fs

HTML5 Filesystem API

Source:

Methods

(static) appendFile(path, data) → {Promise}

Source:

Appends data to file. If file does not exist - it will be created.

Parameters:
Name Type Description
path String | FileSystemFileEntry
data String | Blob | File | ArrayBuffer
Returns:
Type
Promise

(static) clear() → {Promise}

Source:

Clears whole filesystem

Returns:
Type
Promise

(static) copy(oldPath, newPath, optionsopt) → {Promise.<FileSystemEntry>}

Source:

Copies file or entire directory. If file or directory does not exist - error thrown.

Parameters:
Name Type Attributes Description
oldPath String | FileSystemEntry
newPath String
options Object <optional>
Properties
Name Type Attributes Default Description
create Boolean <optional>
false

create missing directories

Returns:
Type
Promise.<FileSystemEntry>

(static) createReadStream(path) → {ReadableStream}

Source:

Create a ReadableStream for reading

Parameters:
Name Type Description
path String | FileSystemFileEntry
Returns:
Type
ReadableStream

(static) createWriteStream(path) → {WritableStream}

Source:

Create a WritableStream for writing

Parameters:
Name Type Description
path String | FileSystemFileEntry
Returns:
Type
WritableStream

(static) exists(path) → {Promise.<Boolean>}

Source:

Checks that file or directory exists by provided path.

Parameters:
Name Type Description
path String
Returns:
Type
Promise.<Boolean>

(static) getEntry(path) → {Promise.<FileSystemEntry>}

Source:

Gets file or directory

Parameters:
Name Type Description
path String | FileSystemEntry
Returns:
Type
Promise.<FileSystemEntry>

(static) getRoot() → {FileSystemDirectoryEntry}

Source:

Returns root directory

Returns:
Type
FileSystemDirectoryEntry

(static) getUrl(path) → {String}

Source:

Gets URL for path

Parameters:
Name Type Description
path String | FileSystemEntry
Returns:
Type
String

(static) init(optionsopt) → {Promise}

Source:

Init filesystem

Parameters:
Name Type Attributes Description
options Object <optional>
Properties
Name Type Attributes Default Description
type Number <optional>
window.PERSISTENT

window.PERSISTENT | window.TEMPORARY

bytes Number <optional>
1Mb
requestQuota Boolean <optional>
true

show request quota popup for PERSISTENT type. (for Chrome extensions with unlimitedStorage permission it is useful to pass options.requestQuota = false)

Returns:
Type
Promise

(static) isSupported() → {Boolean}

Source:

Is filesystem API supported by current browser

Returns:
Type
Boolean

(static) mkdir(path) → {Promise.<FileSystemDirectoryEntry>}

Source:

Recursively creates required directories in provided path.

Parameters:
Name Type Description
path String
Returns:
Type
Promise.<FileSystemDirectoryEntry>

(static) readdir(path, optionsopt) → {Promise.<Array.<FileSystemEntry>>}

Source:

Reads directory content

Parameters:
Name Type Attributes Description
path String | FileSystemDirectoryEntry
options Object <optional>
Properties
Name Type Attributes Default Description
deep Boolean <optional>
false

read recursively and attach data as children property

Returns:
Type
Promise.<Array.<FileSystemEntry>>

(static) readFile(path, optionsopt) → {Promise.<String>}

Source:

Reads file content.

  • options.type='Blob' returns a immutable snapshot of the file. Slower but safer.
  • options.type='File' returns a mutable instance of File. Faster but may have a data race.

If file does not exist - error thrown.

Parameters:
Name Type Attributes Description
path String | FileSystemFileEntry
options Object <optional>
Properties
Name Type Attributes Default Description
type String <optional>
'Text'

how content should be read: Text|ArrayBuffer|BinaryString|DataURL|Blob|File

Returns:
Type
Promise.<String>

(static) rename(oldPath, newPath, optionsopt) → {Promise.<FileSystemEntry>}

Source:

Renames file or directory. If source file or directory does not exist - error thrown. If target already exists - it will be overwritten.

Parameters:
Name Type Attributes Description
oldPath String | FileSystemEntry
newPath String
options Object <optional>
Properties
Name Type Attributes Default Description
create Boolean <optional>
false

create missing directories

Returns:
Type
Promise.<FileSystemEntry>

(static) rmdir(path) → {Promise}

Source:

Removes directory recursively. If directory does not exist - method does nothing without error.

Parameters:
Name Type Description
path String | FileSystemDirectoryEntry
Returns:
Type
Promise

(static) stat(path) → {Promise.<StatObject>}

Source:

Gets info about file or directory. If it does not exist - error thrown.

Parameters:
Name Type Description
path String | FileSystemEntry
Returns:
Type
Promise.<StatObject>
Source:

Removes file. If file does not exist - no error thrown.

Parameters:
Name Type Description
path String | FileSystemFileEntry
Returns:
Type
Promise

(static) usage() → {Promise.<{usedBytes, grantedBytes}>}

Source:

Gets used and granted bytes

Returns:
Type
Promise.<{usedBytes, grantedBytes}>

(static) writeFile(path, data) → {Promise}

Source:

Writes data to file. If file does not exist - it will be created. If file already exists - it will be overwritten.

Parameters:
Name Type Description
path String
data String | Blob | File | ArrayBuffer
Returns:
Type
Promise