Skip to content

Scripting API / core/local-app/LocalFileApi

core/local-app/LocalFileApi

Modules

Module Description
External -

Classes

LocalFileApi

Methods

copy()

copy(sourceFilePath, destinationFilePath): Promise<void>

Copies a file.

Parameters
Parameter Type Description
sourceFilePath string The path of the file to copy.
destinationFilePath string The path where the file will be copied.
Returns

Promise<void>

delete()

delete(filePath): Promise<void>

Deletes a file.

Parameters
Parameter Type Description
filePath string The path of the file to delete.
Returns

Promise<void>

move()

move(sourceFilePath, destinationFilePath): Promise<void>

Moves a file.

Parameters
Parameter Type Description
sourceFilePath string The path of the file to move.
destinationFilePath string The path where the file will be moved.
Returns

Promise<void>

open()
Call Signature

open(filePath, openType): Promise<LocalFileReadHandle>

Opens a file for reading or writing.

Parameters
Parameter Type Description
filePath string The path of the file to open.
openType "read" The way in which the file is opened. 'read' - the file can only be read. 'write' - the file will be created (an existing file with the same name will be erased) and the file can only be written to. 'append' - the file will be created if it does not exist and the file can only be written to. Any text written to the file will be added to the end.
Returns

Promise<LocalFileReadHandle>

LocalFileHandle

Call Signature

open(filePath, openType): Promise<LocalFileWriteHandle>

Opens a file for reading or writing.

Parameters
Parameter Type Description
filePath string The path of the file to open.
openType "write" The way in which the file is opened. 'read' - the file can only be read. 'write' - the file will be created (an existing file with the same name will be erased) and the file can only be written to. 'append' - the file will be created if it does not exist and the file can only be written to. Any text written to the file will be added to the end.
Returns

Promise<LocalFileWriteHandle>

LocalFileHandle

Call Signature

open(filePath, openType): Promise<LocalFileWriteHandle>

Opens a file for reading or writing.

Parameters
Parameter Type Description
filePath string The path of the file to open.
openType "append" The way in which the file is opened. 'read' - the file can only be read. 'write' - the file will be created (an existing file with the same name will be erased) and the file can only be written to. 'append' - the file will be created if it does not exist and the file can only be written to. Any text written to the file will be added to the end.
Returns

Promise<LocalFileWriteHandle>

LocalFileHandle


abstract LocalFileHandle

Extended by

Properties

Property Type Description
info LocalFileInfo Contains information about the file.

Methods

close()

close(): Promise<void>

Closes the file. This makes it available for other programs to use.

Returns

Promise<void>

isOpen()

isOpen(): Promise<boolean>

Checks whether the file is still available.

Returns

Promise<boolean>


LocalFileReadHandle

Extends

Properties

Property Type Description Inherited from
info LocalFileInfo Contains information about the file. LocalFileHandle.info

Methods

close()

close(): Promise<void>

Closes the file. This makes it available for other programs to use.

Returns

Promise<void>

Inherited from

LocalFileHandle.close

isOpen()

isOpen(): Promise<boolean>

Checks whether the file is still available.

Returns

Promise<boolean>

Inherited from

LocalFileHandle.isOpen

readBinary()

readBinary(): Promise<ArrayBuffer>

Reads the entire contents of the file from the beginning to the end regardless of the read position in the file. After reading, the read position is set to the beginning of the file.

Returns

Promise<ArrayBuffer>

An array buffer containing the raw binary data of the file.

readLine()

readLine(): Promise<string | null>

Reads the next line of text from the file. Advances the read position to the end of that line. Use readBinary to read binary data.

Returns

Promise<string | null>

The next line of text from the file, or null if the read position is at the end of the file.

readToEnd()

readToEnd(): Promise<string>

Reads the contents of the file as text from the current read position to the end. This method sets the read position of the file to the beginning. Use readBinary to read binary data.

Returns

Promise<string>

The remainder of the file, or an empty string if the read position is at the end of the file.

reset()

reset(): Promise<void>

Resets the file pointer back to the beginning of the file.

Returns

Promise<void>


LocalFileWriteHandle

Extends

Properties

Property Type Description Inherited from
info LocalFileInfo Contains information about the file. LocalFileHandle.info

Methods

close()

close(): Promise<void>

Closes the file. This makes it available for other programs to use.

Returns

Promise<void>

Inherited from

LocalFileHandle.close

isOpen()

isOpen(): Promise<boolean>

Checks whether the file is still available.

Returns

Promise<boolean>

Inherited from

LocalFileHandle.isOpen

write()

write(contents): Promise<void>

Writes the contents to the file. Changes are saved as soon as they are written.

Parameters
Parameter Type Description
contents string Contents to write to the file.
Returns

Promise<void>

writeBinary()

writeBinary(contents): Promise<void>

Writes the binary contents to the file. Changes are saved as soon as they are written.

Parameters
Parameter Type Description
contents ArrayBuffer Binary contents to write to the file.
Returns

Promise<void>