import {IDBPromisedFileHandle} from 'idb-file-storage/src/idb-file-storage.js'
IDBPromisedFileHandle
Wraps an IDBMutableFile's FileHandle with a nicer Promise-based API.
Instances of this class are created from the IDBPromisedMutableFile.open method.
Member Summary
Public Members | ||
public get |
A boolean property that is true if the lock is still active. |
|
public get |
mode: "readonly" | "readwrite" | "writeonly" Provide access to the mode that has been used to open the IDBPromisedMutableFile. |
Method Summary
Public Methods | ||
public |
Abort any pending data request and set the instance as aborted. |
|
public |
async append(data: string | ArrayBuffer): Promise Append the passed data to the end of the file. |
|
public |
Close the locked file (and wait for any written data to be flushed if needed). |
|
public |
async getMetadata(): Promise<{size: number, lastModified: Date}>{size:> Get the file metadata (take a look to IDBPromisedFileHandle.Metadata for more info). |
|
public |
queuedWrite(data: string | ArrayBuffer, location: number): Promise<number> Queue data to be written into the file (optionally starting from a defined location in the file). |
|
public |
async readAsArrayBuffer(size: number, location: number): Promise<ArrayBuffer> Read a given amount of data from the file as an ArrayBufer (optionally starting from the specified location). |
|
public |
async readAsText(size: number, location: number): Promise<string> Read a given amount of data from the file as Text (optionally starting from the specified location). |
|
public |
async truncate(location: number): Promise<ArrayBuffer> Truncate the file (optionally at a specified location). |
|
public |
async waitForQueuedWrites(): Promise<number> Wait that any queued data has been written. |
|
public |
Write data into the file (optionally starting from a defined location in the file). |
Public Members
public get mode: "readonly" | "readwrite" | "writeonly" source
Provide access to the mode that has been used to open the IDBPromisedMutableFile.
Public Methods
public async abort(): Promise source
Abort any pending data request and set the instance as aborted.
public async append(data: string | ArrayBuffer): Promise source
Append the passed data to the end of the file.
Params:
Name | Type | Attribute | Description |
data | string | ArrayBuffer | The data to append to the end of the file. |
public async close(): Promise source
Close the locked file (and wait for any written data to be flushed if needed).
public async getMetadata(): Promise<{size: number, lastModified: Date}>{size:> source
Get the file metadata (take a look to IDBPromisedFileHandle.Metadata for more info).
public queuedWrite(data: string | ArrayBuffer, location: number): Promise<number> source
Queue data to be written into the file (optionally starting from a defined location in the file).
Params:
Name | Type | Attribute | Description |
data | string | ArrayBuffer | The data to write into the file. |
|
location | number | The location where the data should be written (when not specified the end of the previous queued write is used). |
public async readAsArrayBuffer(size: number, location: number): Promise<ArrayBuffer> source
Read a given amount of data from the file as an ArrayBufer (optionally starting from the specified location).
Return:
Promise<ArrayBuffer> | A promise which resolves to the data read, when the request has been completed. |
public async readAsText(size: number, location: number): Promise<string> source
Read a given amount of data from the file as Text (optionally starting from the specified location).
public async truncate(location: number): Promise<ArrayBuffer> source
Truncate the file (optionally at a specified location).
Params:
Name | Type | Attribute | Description |
location | number |
|
The location where the file should be truncated. |
public async waitForQueuedWrites(): Promise<number> source
Wait that any queued data has been written.
public async write(data: string | ArrayBuffer, location: number): Promise<number> source
Write data into the file (optionally starting from a defined location in the file).
Params:
Name | Type | Attribute | Description |
data | string | ArrayBuffer | The data to write into the file. |
|
location | number | The location where the data should be written. |