Home Reference Source
import {IDBPromisedFileHandle} from 'idb-file-storage/src/idb-file-storage.js'
public class | source

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

async abort(): Promise

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

async close(): Promise

Close the locked file (and wait for any written data to be flushed if needed).

public

async getMetadata(): Promise<{size: number, lastModified: Date}>

Get the file metadata (take a look to IDBPromisedFileHandle.Metadata for more info).

public

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

Wait that any queued data has been written.

public

async write(data: string | ArrayBuffer, location: number): Promise<number>

Write data into the file (optionally starting from a defined location in the file).

Public Members

public get active: boolean source

A boolean property that is true if the lock is still active.

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.

Return:

Promise

A promise which is resolved when the abort request has been completed

public async append(data: string | ArrayBuffer): Promise source

Append the passed data to the end of the file.

Params:

NameTypeAttributeDescription
data string | ArrayBuffer

The data to append to the end of the file.

Return:

Promise

A promise which is resolved once the request has been completed.

public async close(): Promise source

Close the locked file (and wait for any written data to be flushed if needed).

Return:

Promise

A promise which is resolved when the close request has been completed

public async getMetadata(): Promise<{size: number, lastModified: Date}> source

Get the file metadata (take a look to IDBPromisedFileHandle.Metadata for more info).

Return:

Promise<{size: number, lastModified: Date}>

A promise which is resolved when the request has been completed

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:

NameTypeAttributeDescription
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).

Return:

Promise<number>

A promise which is resolved once the request has been completed with the location where the file was after the data has been writted.

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).

Params:

NameTypeAttributeDescription
size number

The amount of data to read.

location number
  • optional

The location where the request should start to read the data.

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).

Params:

NameTypeAttributeDescription
size number

The amount of data to read.

location number
  • optional

The location where the request should start to read the data.

Return:

Promise<string>

A promise which resolves to the data read, when the request has been completed.

public async truncate(location: number): Promise<ArrayBuffer> source

Truncate the file (optionally at a specified location).

Params:

NameTypeAttributeDescription
location number
  • optional
  • default: 0

The location where the file should be truncated.

Return:

Promise<ArrayBuffer>

A promise which is resolved once the request has been completed.

public async waitForQueuedWrites(): Promise<number> source

Wait that any queued data has been written.

Return:

Promise<number>

A promise which is resolved once the request has been completed with the location where the file was after the data has been writted.

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:

NameTypeAttributeDescription
data string | ArrayBuffer

The data to write into the file.

location number

The location where the data should be written.

Return:

Promise<number>

A promise which is resolved to the location where the written data ends.