Skip to main content

FileType

Sandbox filesystem object type.

Enumeration Members

Enumeration MemberValueDescription
DIR"dir"Filesystem object is a directory.
FILE"file"Filesystem object is a file.

Classes

Filesystem

Module for interacting with the sandbox filesystem.

Constructors

Parameters
ParameterType
transportTransport
envdApiEnvdApiClient
connectionConfigConnectionConfig
Returns
Filesystem

Methods

exists()

Check if a file or a directory exists.
Parameters
ParameterTypeDescription
pathstringpath to a file or a directory
opts?FilesystemRequestOptsconnection options.
Returns
Promise<boolean> true if the file or directory exists, false otherwise

getInfo()

Get information about a file or directory.
Parameters
ParameterTypeDescription
pathstringpath to a file or directory.
opts?FilesystemRequestOptsconnection options.
Returns
Promise<EntryInfo> information about the file or directory like name, type, and path.

list()

List entries in a directory.
Parameters
ParameterTypeDescription
pathstringpath to the directory.
opts?FilesystemListOptsconnection options.
Returns
Promise<EntryInfo[]> list of entries in the sandbox filesystem directory.

makeDir()

Create a new directory and all directories along the way if needed on the specified path.
Parameters
ParameterTypeDescription
pathstringpath to a new directory. For example ‘/dirA/dirB’ when creating ‘dirB’.
opts?FilesystemRequestOptsconnection options.
Returns
Promise<boolean> true if the directory was created, false if it already exists.

read()

read(path, opts)
Read file content as a string. You can pass text, bytes, blob, or stream to opts.format to change the return type.
Parameters
ParameterTypeDescription
pathstringpath to the file.
opts?FilesystemRequestOpts & objectconnection options.
Returns
Promise<string> file content as string
read(path, opts)
Read file content as a Uint8Array. You can pass text, bytes, blob, or stream to opts.format to change the return type.
Parameters
ParameterTypeDescription
pathstringpath to the file.
opts?FilesystemRequestOpts & objectconnection options.
Returns
Promise<Uint8Array> file content as Uint8Array
read(path, opts)
Read file content as a Blob. You can pass text, bytes, blob, or stream to opts.format to change the return type.
Parameters
ParameterTypeDescription
pathstringpath to the file.
opts?FilesystemRequestOpts & objectconnection options.
Returns
Promise<Blob> file content as Blob
read(path, opts)
Read file content as a ReadableStream. You can pass text, bytes, blob, or stream to opts.format to change the return type.
Parameters
ParameterTypeDescription
pathstringpath to the file.
opts?FilesystemRequestOpts & objectconnection options.
Returns
Promise<ReadableStream<Uint8Array>> file content as ReadableStream

remove()

Remove a file or directory.
Parameters
ParameterTypeDescription
pathstringpath to a file or directory.
opts?FilesystemRequestOptsconnection options.
Returns
Promise<void>

rename()

Rename a file or directory.
Parameters
ParameterTypeDescription
oldPathstringpath to the file or directory to rename.
newPathstringnew path for the file or directory.
opts?FilesystemRequestOptsconnection options.
Returns
Promise<EntryInfo> information about renamed file or directory.

watchDir()

Start watching a directory for filesystem events.
Parameters
ParameterTypeDescription
pathstringpath to directory to watch.
onEvent(event: FilesystemEvent) => void | Promise<void>callback to call when an event in the directory occurs.
opts?WatchOpts & objectconnection options.
Returns
Promise<WatchHandle> WatchHandle object for stopping watching directory.

write()

write(path, data, opts)
Write content to a file. Writing to a file that doesn’t exist creates the file. Writing to a file that already exists overwrites the file. Writing to a file at path that doesn’t exist creates the necessary directories.
Parameters
ParameterTypeDescription
pathstringpath to file.
datastring | ArrayBuffer | Blob | ReadableStream<any>data to write to the file. Data can be a string, ArrayBuffer, Blob, or ReadableStream.
opts?FilesystemRequestOptsconnection options.
Returns
Promise<WriteInfo> information about the written file
write(files, opts)
Parameters
ParameterType
filesWriteEntry[]
opts?FilesystemRequestOpts
Returns
Promise<WriteInfo[]>

writeFiles()

Write multiple files. Writing to a file that doesn’t exist creates the file. Writing to a file that already exists overwrites the file. Writing to a file at path that doesn’t exist creates the necessary directories.
Parameters
ParameterTypeDescription
filesWriteEntry[]list of files to write as WriteEntry objects, each containing path and data.
opts?FilesystemRequestOptsconnection options.
Returns
Promise<WriteInfo[]> information about the written files

Interfaces

EntryInfo

Sandbox filesystem object information.

Properties

group

Group owner of the filesystem object.

mode

File mode and permission bits.

modifiedTime?

Last modification time of the filesystem object.

name

Name of the filesystem object.

owner

Owner of the filesystem object.

path

Path to the filesystem object.

permissions

String representation of file permissions (e.g. ‘rwxr-xr-x’).

size

Size of the filesystem object in bytes.

symlinkTarget?

If the filesystem object is a symlink, this is the target of the symlink.

type?

Type of the filesystem object.

FilesystemListOpts

Options for the sandbox filesystem operations.

Properties

depth?

Depth of the directory to list.

requestTimeoutMs?

Timeout for requests to the API in milliseconds.
Default

user?

User to use for the operation in the sandbox. This affects the resolution of relative paths and ownership of the created filesystem objects.

FilesystemRequestOpts

Options for the sandbox filesystem operations.

Extended by

  • FilesystemListOpts
  • WatchOpts

Properties

requestTimeoutMs?

Timeout for requests to the API in milliseconds.
Default

user?

User to use for the operation in the sandbox. This affects the resolution of relative paths and ownership of the created filesystem objects.

WatchOpts

Options for watching a directory.

Properties

onExit()?

Callback to call when the watch operation stops.
Parameters
ParameterType
err?Error
Returns
void | Promise<void>

recursive?

Watch the directory recursively

requestTimeoutMs?

Timeout for requests to the API in milliseconds.
Default

timeoutMs?

Timeout for the watch operation in milliseconds. You can pass 0 to disable the timeout.
Default

user?

User to use for the operation in the sandbox. This affects the resolution of relative paths and ownership of the created filesystem objects.

WriteInfo

Sandbox filesystem object information.

Extended by

  • EntryInfo

Properties

name

Name of the filesystem object.

path

Path to the filesystem object.

type?

Type of the filesystem object.

Type Aliases

WriteEntry

Type declaration

NameType
datastring | ArrayBuffer | Blob | ReadableStream
pathstring