forked from Shiloh/remnantchat
refactor: type abstract-chunk-store and idb-chunk-store
This commit is contained in:
parent
8d27c2239a
commit
a9f7919460
61
src/react-app-env.d.ts
vendored
61
src/react-app-env.d.ts
vendored
@ -145,3 +145,64 @@ consumes the data in `encryptedStream` and returns a plaintext version.
|
|||||||
*/
|
*/
|
||||||
export function encryptedSize(plaintextSize: number): number
|
export function encryptedSize(plaintextSize: number): number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module 'abstract-chunk-store' {
|
||||||
|
type GetCallback = (err: Error | null, buffer: Buffer) => void
|
||||||
|
|
||||||
|
export interface ChunkStore {
|
||||||
|
/**
|
||||||
|
* Create a new chunk store. Chunks must have a length of `chunkLength`.
|
||||||
|
*/
|
||||||
|
constructor(chunkLength: number)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new chunk to the storage. `index` should be an integer.
|
||||||
|
*/
|
||||||
|
put(
|
||||||
|
index: number,
|
||||||
|
chunkBuffer: Buffer,
|
||||||
|
cb: (err: Error | null) => void
|
||||||
|
): void
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a chunk stored. `index` should be an integer.
|
||||||
|
*/
|
||||||
|
get(index: number, cb: GetCallback): void
|
||||||
|
get(
|
||||||
|
index: number,
|
||||||
|
options: { offset?: number; length?: number },
|
||||||
|
cb: GetCallback
|
||||||
|
): void
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the underlying resource, e.g. if the store is backed by a file, this would close the file descriptor.
|
||||||
|
*/
|
||||||
|
close(cb: (err: Error | null) => void)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the file data, e.g. if the store is backed by a file, this would delete the file from the filesystem.
|
||||||
|
*/
|
||||||
|
destroy(cb: (err: Error | null) => void)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expose the chunk length from the constructor so that code that receives a chunk store can know what size of chunks to write.
|
||||||
|
*/
|
||||||
|
chunkLength: number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module 'idb-chunk-store' {
|
||||||
|
import { TorrentOptions } from 'webtorrent'
|
||||||
|
import { ChunkStore } from 'abstract-chunk-store'
|
||||||
|
|
||||||
|
export default function idbChunkStore(
|
||||||
|
chunkLength: number,
|
||||||
|
opts?: Partial<{
|
||||||
|
/**
|
||||||
|
* A name to separate the contents of different stores
|
||||||
|
*/
|
||||||
|
name: string
|
||||||
|
}> &
|
||||||
|
TorrentOptions.store
|
||||||
|
): ChunkStore
|
||||||
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import WebTorrent, { Torrent, TorrentFile } from 'webtorrent'
|
import WebTorrent, { Torrent, TorrentFile } from 'webtorrent'
|
||||||
import streamSaver from 'streamsaver'
|
import streamSaver from 'streamsaver'
|
||||||
import { Keychain, plaintextSize, encryptedSize } from 'wormhole-crypto'
|
import { Keychain, plaintextSize, encryptedSize } from 'wormhole-crypto'
|
||||||
// @ts-ignore
|
|
||||||
import idbChunkStore from 'idb-chunk-store'
|
import idbChunkStore from 'idb-chunk-store'
|
||||||
import { detectIncognito } from 'detectincognitojs'
|
import { detectIncognito } from 'detectincognitojs'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user