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

IDBFileStorage

Provides a Promise-based API to store files into an IndexedDB.

Instances of this class are created using the exported getFileStorage function.

Method Summary

Public Methods
public

async clear(): Promise

Remove all the file objects stored in the IDBFileStorage.

public

Count the number of files stored in the IDBFileStorage.

public

async createMutableFile(fileName: string, fileType: string): IDBPromisedMutableFile

Create a new IDBPromisedMutableFile instance (where the IDBMutableFile is supported)

public

Retrieve a file stored in the IDBFileStorage by key.

public

List the names of the files stored in the IDBFileStorage.

public

Put a file object into the IDBFileStorage, it overwrites an existent file saved with the fileName if any.

public

async remove(fileName: string): Promise

Remove a file object from the IDBFileStorage.

Public Methods

public async clear(): Promise source

Remove all the file objects stored in the IDBFileStorage.

Return:

Promise

A promise resolved once the IDBFileStorage has been cleared.

public async count(options: IDBFileStorage.ListFilteringOptions): Promise<number> source

Count the number of files stored in the IDBFileStorage.

(If any filtering options has been specified, only the file names that match all the filters are included in the final count).

Params:

NameTypeAttributeDescription
options IDBFileStorage.ListFilteringOptions

The optional filters to apply while listing the stored file names.

Return:

Promise<number>

A promise resolved to the number of files that has been found.

public async createMutableFile(fileName: string, fileType: string): IDBPromisedMutableFile source

Create a new IDBPromisedMutableFile instance (where the IDBMutableFile is supported)

Params:

NameTypeAttributeDescription
fileName string

The fileName associated to the new IDBPromisedMutableFile instance.

fileType string
  • optional
  • default: "text"

The mime type associated to the file.

Return:

IDBPromisedMutableFile

The newly created IDBPromisedMutableFile instance.

public async get(fileName: string): Promise<Blob|File|IDBPromisedMutableFile> source

Retrieve a file stored in the IDBFileStorage by key.

Params:

NameTypeAttributeDescription
fileName string

The key to use to retrieve the file from the IDBFileStorage.

Return:

Promise<Blob|File|IDBPromisedMutableFile>

A promise resolved once the file stored in the IDBFileStorage has been retrieved.

public async list(options: IDBFileStorage.ListFilteringOptions): Promise<string[]> source

List the names of the files stored in the IDBFileStorage.

(If any filtering options has been specified, only the file names that match all the filters are included in the result).

Params:

NameTypeAttributeDescription
options IDBFileStorage.ListFilteringOptions

The optional filters to apply while listing the stored file names.

Return:

Promise<string[]>

A promise resolved to the array of the filenames that has been found.

public async put(fileName: string, file: Blob | File | IDBPromisedMutableFile | IDBMutableFile): Promise source

Put a file object into the IDBFileStorage, it overwrites an existent file saved with the fileName if any.

Params:

NameTypeAttributeDescription
fileName string

The key associated to the file in the IDBFileStorage.

file Blob | File | IDBPromisedMutableFile | IDBMutableFile

The file to be persisted.

Return:

Promise

A promise resolved when the request has been completed.

public async remove(fileName: string): Promise source

Remove a file object from the IDBFileStorage.

Params:

NameTypeAttributeDescription
fileName string

The fileName (the associated IndexedDB key) to remove from the IDBFileStorage.

Return:

Promise

A promise resolved when the request has been completed.