Edit in GitHubLog an issue

require('uxp').storage.File

Represents a file on a file system. Provides methods for reading from and writing to the file. You'll never instantiate a File directly; instead you'll get access via a storage.FileSystemProvider.

isFile#

Indicates that this instance is a file.

Example

Copied to your clipboard
1if (anEntry.isFile) {
2 await anEntry.read();
3}

mode : Symbol#

Indicates whether this file is read-only or read-write. See readOnly and readWrite.

Example

Copied to your clipboard
1if (aFile.mode === modes.readOnly) {
2 throw new Error("Can't write to a file opened as read-only.");
3}

read(options)#

Reads data from the file and returns it. The file format can be specified with the format option. If a format is not supplied, the file is assumed to be a text file using UTF8 encoding.

Returns: Promise.<(string\|ArrayBuffer)> - the contents of the file

ParamTypeDefaultDescription
optionsany
[options.format]Symbolformats.utf8The format of the file; see utf8 and binary.

Example

Copied to your clipboard
const text = await myNovel.read();

Example

Copied to your clipboard
const data = await myNovel.read({format: formats.binary});

write(data, options)#

Writes data to a file, appending if desired. The format of the file is controlled via the format option, and defaults to UTF8.

Throws:

  • FileIsReadOnly if writing to a read-only file
  • OutOfSpace If writing to the file causes the file system to exceed the available space (or quota)
ParamTypeDefaultDescription
datastring | ArrayBufferthe data to write to the file
optionsany
[options.format]Symbolformats.utf8the format of the file; see utf8 and binary
[options.append]booleanfalseif true, the data is written to the end of the file

Example

Copied to your clipboard
1await myNovel.write("It was a dark and stormy night.\n");
2await myNovel.write("Cliches and tropes aside, it really was.", {append: true});

Example

Copied to your clipboard
1const data = new ArrayBuffer();
2await aDataFile.write(data, {format: formats.binary});

isFile(entry)#

Determines if the entry is a file or not. This is safe to use even if the entry is null or undefined.

Returns: boolean - if true, the entry is a file.

ParamTypeDescription
entryanythe entry to check
Copyright © 2021 Adobe. All rights reserved.