Created
June 10, 2023 01:39
-
-
Save mattbasta/c7d2a885c32e4674f7cde8cc80594c1f to your computer and use it in GitHub Desktop.
TypeScript typings for idb-file-storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function waitForDOMRequest<T>( | |
req: IDBRequest<T>, | |
onSuccess: () => void, | |
): Promise<T>; | |
type Mode = 'readonly' | 'readwrite' | 'writeonly'; | |
export class IDBPromisedFileHandle { | |
get mode(): Mode; | |
get active(): boolean; | |
close(): Promise<void>; | |
abort(): Promise<void>; | |
getMetadata(): Promise<{size: number; lastModified: Date}>; | |
readAsText(size: number, location?: number): Promise<string>; | |
readAsArrayBuffer(size: number, location?: number): Promise<ArrayBuffer>; | |
truncate(location?: number): Promise<void>; | |
append(data: string | ArrayBuffer): Promise<void>; | |
write(data: string | ArrayBuffer, location: number): Promise<number>; | |
queuedWrite(data: string | ArrayBuffer, location: number): Promise<number>; | |
waitForQueuedWrites(): Promise<number>; | |
} | |
export class IDBPromisedMutableFile { | |
open(mode: 'readonly' | 'readwrite' | 'writeonly'): IDBPromisedFileHandle; | |
getFile(): Promise<File>; | |
persistAsFileSnapshot(snapshotName: string): Promise<File>; | |
persist(): Promise<void>; | |
runFileRequestGenerator( | |
generatorFunction: ( | |
file: IDBPromisedMutableFile, | |
) => Generator<Promise<number>>, | |
mode: Mode, | |
): Promise<void>; | |
} | |
interface ListFilteringOptions { | |
startsWith?: string; | |
endsWith?: string; | |
includes?: string; | |
filterFn?: (fileName: string) => boolean; | |
} | |
export class IDBFileStorage { | |
createMutableFile( | |
fileName: string, | |
fileType?: string, | |
): Promise<IDBPromisedMutableFile>; | |
put( | |
fileName: string, | |
file: Blob | File | IDBPromisedMutableFile, | |
): Promise<void>; | |
remove(fileName: string): Promise<void>; | |
list(options: ListFilteringOptions): Promise<Array<string>>; | |
count(options: ListFilteringOptions): Promise<number>; | |
get(fileName: string): Promise<Blob | File | IDBPromisedFileHandle>; | |
clear(): Promise<void>; | |
} | |
export function getFileStorage(options?: { | |
name?: string; | |
persistent?: boolean; | |
}): IDBFileStorage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment