SimpleFile

SimpleFile

Simple wrapper to represent a file in both Node.js and the browser. This enables downstream code to operate independently of the source of the file.

Constructor

new SimpleFile(x, optionsopt)

Source:
Parameters:
Name Type Attributes Default Description
x Uint8Array | string | File

Contents of a file or a pointer to it. For browsers, this may be a File object; for Node.js, this may be a string containing a file path.

options object <optional>
{}

Optional parameters.

Properties
Name Type Attributes Default Description
name string <optional>
<nullable>
null

Name of the file. If null, it is determined automatically from x where possible (i.e., basename of the file path or extracted from the File object). If x is a Uint8Array, an explicit name is required.

Classes

SimpleFile

Methods

buffer(optionsopt) → {Uint8Array}

Source:
Parameters:
Name Type Attributes Default Description
options object <optional>
{}

Optional parameters.

Properties
Name Type Attributes Default Description
copy boolean <optional>
false

Whether to create a new copy of the buffer. Callers should set this to true for non-read-only applications.

Returns:

Contents of the file as an array.

Type
Uint8Array

content(optionsopt) → {Uint8Array|string}

Source:
Parameters:
Name Type Attributes Default Description
options object <optional>
{}

Optional parameters.

Properties
Name Type Attributes Default Description
copy boolean <optional>
false

Whether to create a new copy of the buffer. Callers should set this to true for non-read-only applications.

Returns:

Contents of the file, as in SimpleFile.buffer. For Node.js, a string may also be returned containing the path to the original file.

Type
Uint8Array | string

name() → {string}

Source:
Returns:

Name of the file, for disambiguation purposes.

Type
string

size() → {number}

Source:
Returns:

Size of the file, in bytes.

Type
number