8.7 released—WinterCG Compliance Part 1
Learn more
Represents a File entity on the file system.

Summary

Constructors

constructor

new File(): File
inherited from constructor
Returns File

Properties

extension

extension: string
Gets the extension of the file.

isLocked

isLocked: boolean
Gets a value indicating whether the file is currently locked, meaning a background operation associated with this file is running.

size

size: number
Gets the size in bytes of the file.

android

StaticReadonly

ios

StaticReadonly

Methods

append

append(content: any): Promise<void>
Appends the provided binary content to the file.
Parameter Default Description
content
any

The binary content to be saved to the file.

Returns Promise<void>

appendSync

appendSync(content: any, onError?: (error: any) => any): void
Appends the provided binary content to the file synchronously.
Parameter Default Description
content
any

The binary content to be saved to the file.

onError
(error: any) => any

An optional function to be called if some IO-error occurs.

Returns void

appendText

appendText(content: string, encoding?: string): Promise&lt;any&gt;
Appends the provided string to the file, using the specified encoding (defaults to UTF-8).
Parameter Default Description
content
string

The content to be saved to the file.

encoding
string

An optional value specifying the preferred encoding (defaults to UTF-8).

Returns Promise<any>

appendTextSync

appendTextSync(
  content: string,
  onError?: (error: any) => any,
  encoding?: string
): void
Appends the provided string to the file synchronously, using the specified encoding (defaults to UTF-8).
Parameter Default Description
content
string

The content to be saved to the file.

onError
(error: any) => any

An optional function to be called if some IO-error occurs.

encoding
string

An optional value specifying the preferred encoding (defaults to UTF-8).

Returns void

copy

copy(dest: string): Promise&lt;boolean&gt;
Copies a file to a given path.
Parameter Default Description
dest
string

The path to the destination file. Returns a Promise with a boolean.

Returns Promise<boolean>

copySync

copySync(dest: string, onError?: (error: any) => any): any
Copies a file to a given path.
Parameter Default Description
dest
string

The path to the destination file.

onError
(error: any) => any

(optional) A callback function to use if any error occurs. Returns a Promise with a boolean.

Returns any

read

read(): Promise&lt;any&gt;
Reads the binary content of the file asynchronously.
Returns Promise<any>

readSync

readSync(onError?: (error: any) => any): any
Reads the binary content of the file synchronously.
Parameter Default Description
onError
(error: any) => any

An optional function to be called if some IO-error occurs.

Returns any

readText

readText(encoding?: string): Promise&lt;string&gt;
Reads the content of the file as a string using the specified encoding (defaults to UTF-8).
Parameter Default Description
encoding
string

An optional value specifying the preferred encoding (defaults to UTF-8).

Returns Promise<string>

readTextSync

readTextSync(onError?: (error: any) => any, encoding?: string): string
Reads the content of the file as a string synchronously, using the specified encoding (defaults to UTF-8).
Parameter Default Description
onError
(error: any) => any

An optional function to be called if some IO-error occurs.

encoding
string

An optional value specifying the preferred encoding (defaults to UTF-8).

Returns string

write

write(content: any): Promise&lt;void&gt;
Writes the provided binary content to the file.
Parameter Default Description
content
any

The binary content to be saved to the file.

Returns Promise<void>

writeSync

writeSync(content: any, onError?: (error: any) => any): void
Writes the provided binary content to the file synchronously.
Parameter Default Description
content
any

The binary content to be saved to the file.

onError
(error: any) => any

An optional function to be called if some IO-error occurs.

Returns void

writeText

writeText(content: string, encoding?: string): Promise&lt;any&gt;
Writes the provided string to the file, using the specified encoding (defaults to UTF-8).
Parameter Default Description
content
string

The content to be saved to the file.

encoding
string

An optional value specifying the preferred encoding (defaults to UTF-8).

Returns Promise<any>

writeTextSync

writeTextSync(
  content: string,
  onError?: (error: any) => any,
  encoding?: string
): void
Writes the provided string to the file synchronously, using the specified encoding (defaults to UTF-8).
Parameter Default Description
content
string

The content to be saved to the file.

onError
(error: any) => any

An optional function to be called if some IO-error occurs.

encoding
string

An optional value specifying the preferred encoding (defaults to UTF-8).

Returns void

exists

Static
exists(path: string): boolean
Checks whether a File with the specified path already exists.
Parameter Default Description
path
string

The path to check for.

Returns boolean

fromPath

Static
fromPath(path: string, copy?: boolean): File
Gets or creates a File entity at the specified path.
Parameter Default Description
path
string

The path to get/create the file at.

copy
boolean

An optional value when set, copies the content-uri to a temp file enabling the legacy behaviour

Returns File