Fs
Edit on GitHubUtilities for high-level file system interactions. Utilizes WASI Preview 1 for underlying API
Added in 0.7.0
No other changes yet.
Types
Type declarations included in the Fs module.
Fs.FileError
Potential errors that can be raised from system interactions.
Fs.SpecialFileType
Represents non-standard system file types.
Fs.FileType
Represents different system file types.
Fs.Stats
1 | record Stats { |
Represents metadata about a file.
Fields:
name | type | description |
---|---|---|
fileType |
FileType |
|
size |
Number |
File size in bytes |
accessedTimestamp |
Number |
Last accessed timestamp in nanoseconds |
modifiedTimestamp |
Number |
Last modified timestamp in nanoseconds |
changedTimestamp |
Number |
Last file status change timestamp in nanoseconds |
Fs.DirectoryEntry
Represents information about an item in a directory.
Fs.RemoveMode
The type of removal operation to perform when calling remove
.
Fs.CopyMode
The type of copy operation to perform when calling copy
.
Fs.WriteMode
The type of write operation to perform when calling writeFile
.
Values
Functions and constants included in the Fs module.
Fs.remove
Added in 0.7.0
No other changes yet.
1 | remove: |
Removes a file or directory.
Parameters:
param | type | description |
---|---|---|
?removeMode |
RemoveMode |
The type of removal to perform; RemoveFile by default |
?baseDirPath |
Option<Path.Path> |
The path to the directory in which path resolution starts |
path |
Path.Path |
The path of the file or directory to remove |
Returns:
type | description |
---|---|
Result<Void, FileError> |
Ok(void) if the operation succeeds, Err(err) if a file system error is encountered |
Examples:
1 | Fs.remove(removeMode=Fs.RemoveEmptyDirectory, Path.fromString("dir")) // removes an empty directory |
1 | Fs.remove(removeMode=Fs.RemoveRecursive, Path.fromString("dir")) // removes the directory and its contents |
Fs.readDir
Added in 0.7.0
No other changes yet.
1 | readDir: |
Reads the contents of a directory.
Parameters:
param | type | description |
---|---|---|
?baseDirPath |
Option<Path.Path> |
The path to the directory in which resolution should begin |
path |
Path.Path |
The path to the directory to read |
Returns:
type | description |
---|---|
Result<List<DirectoryEntry>, FileError> |
Ok(contents) containing the directory contents or Err(err) if a file system error is encountered |
Fs.createDir
Added in 0.7.0
No other changes yet.
Creates a new empty directory at the given path.
Parameters:
param | type | description |
---|---|---|
?baseDirPath |
Option<Path.Path> |
The path to the directory in which resolution should begin |
path |
Path.Path |
The path to create the new directory, relative to the base directory |
Returns:
type | description |
---|---|
Result<Void, FileError> |
Ok(void) if the operation succeeds, Err(err) if a file system error is encountered |
Fs.createSymlink
Added in 0.7.0
No other changes yet.
1 | createSymlink: |
Creates a new symbolic link with the given contents.
Parameters:
param | type | description |
---|---|---|
linkContents |
Path.Path |
The path to store into the link |
?targetBaseDirPath |
Option<Path.Path> |
The path to the directory in which the target path resolution starts |
targetPath |
Path.Path |
The path to the target of the link |
Returns:
type | description |
---|---|
Result<Void, FileError> |
Ok(void) if the operation succeeds, Err(err) if a file system error or relativization error is encountered |
Fs.stats
Added in 0.7.0
No other changes yet.
1 | stats: |
Queries information about a file.
Parameters:
param | type | description |
---|---|---|
?followSymlink |
Bool |
Whether to follow symlinks or not; if true then the stats of a valid symlink’s underlying file will be returned. true by default |
?baseDirPath |
Option<Path.Path> |
The path to the directory in which the path resolution starts |
path |
Path.Path |
The path of the file to query |
Returns:
type | description |
---|---|
Result<Stats, FileError> |
Ok(stats) containing metadata or Err(err) if a file system error is encountered |
Fs.exists
Added in 0.7.0
No other changes yet.
Polls whether or not a file or directory exists at the given path.
Parameters:
param | type | description |
---|---|---|
?baseDirPath |
Option<Path.Path> |
The path to the directory in which the path resolution starts |
path |
Path.Path |
The path of the file to query |
Returns:
type | description |
---|---|
Bool |
true if a file or directory exists at the path or false otherwise |
Fs.readLink
Added in 0.7.0
No other changes yet.
Reads the contents of a symbolic link.
Parameters:
param | type | description |
---|---|---|
?baseDirPath |
Option<Path.Path> |
The path to the directory to begin path resolution |
path |
Path.Path |
The path to the link to read |
Returns:
type | description |
---|---|
Result<Path.Path, FileError> |
Ok(path) containing the link contents or Err(err) if a file system error is encountered |
Fs.copy
Copies a file or directory.
Parameters:
param | type | description |
---|---|---|
?copyMode |
CopyMode |
The type of copy to perform; CopyFile by default |
?followSymlink |
Bool |
Whether to follow symlinks or not; if true then the stats of a valid symlink’s underlying file will be returned. true by default |
?sourceBaseDirPath |
Option<Path.Path> |
The path to the directory in which the source path resolution starts |
sourcePath |
Path.Path |
The path of the file or directory to copy |
?targetBaseDirPath |
Option<Path.Path> |
The path to the directory in which the target path resolution starts |
targetPath |
Path.Path |
The path to copy the file or directory to |
Returns:
type | description |
---|---|
Result<Void, FileError> |
Ok(void) if the operation succeeds, Err(err) if a file system error is encountered |
Fs.rename
Added in 0.7.0
No other changes yet.
1 | rename: |
Renames a file or directory.
Parameters:
param | type | description |
---|---|---|
?sourceBaseDirPath |
Option<Path.Path> |
The path to the directory in which the source path resolution starts |
sourcePath |
Path.Path |
The path of the file to rename |
?targetBaseDirPath |
Option<Path.Path> |
The path to the directory in which the target path resolution starts |
targetPath |
Path.Path |
The new path of the file |
Returns:
type | description |
---|---|
Result<Void, FileError> |
Ok(void) if the operation succeeds, Err(err) if a file system error is encountered |
Fs.Binary
Functionality for reading and writing Bytes
to files.
Added in 0.7.0
No other changes yet.
Values
Functions and constants included in the Fs.Binary module.
Fs.Binary.readFile
Added in 0.7.0
No other changes yet.
1 | readFile: |
Read the contents of a file as Bytes
.
Parameters:
param | type | description |
---|---|---|
?sync |
Bool |
Whether to synchronously read; true by default |
?baseDirPath |
Option<Path.Path> |
The path to the directory to begin path resolution |
path |
Path.Path |
The file path to read from |
Returns:
type | description |
---|---|
Result<Bytes, FileError> |
Ok(contents) containing the bytes read if successful or Err(err) if a file system error is encountered |
Fs.Binary.writeFile
Added in 0.7.0
No other changes yet.
1 | writeFile: |
Write Bytes
to a file.
Parameters:
param | type | description |
---|---|---|
?writeMode |
WriteMode |
The type of write operation to perform; Truncate by default |
?sync |
Bool |
Whether to synchronously write; true by default |
?baseDirPath |
Option<Path.Path> |
The path to the directory to begin path resolution |
path |
Path.Path |
The file path to write to |
data |
Bytes |
The bytes to write to the file |
Returns:
type | description |
---|---|
Result<Void, FileError> |
Ok(void) if the operation is successful or Err(err) if a file system error is encountered |
Fs.Utf8
Functionality for reading and writing String
s to files.
Added in 0.7.0
No other changes yet.
Values
Functions and constants included in the Fs.Utf8 module.
Fs.Utf8.readFile
Added in 0.7.0
No other changes yet.
1 | readFile: |
Read the contents of a file as a String
.
Parameters:
param | type | description |
---|---|---|
?sync |
Bool |
Whether to synchronously read; true by default |
?baseDirPath |
Option<Path.Path> |
The path to the directory to begin path resolution |
path |
Path.Path |
The file path to read from |
Returns:
type | description |
---|---|
Result<String, FileError> |
Ok(contents) containing the string read if successful or Err(err) if a file system error is encountered |
Fs.Utf8.writeFile
Added in 0.7.0
No other changes yet.
1 | writeFile: |
Write a String
to a file.
Parameters:
param | type | description |
---|---|---|
?writeMode |
WriteMode |
The type of write operation to perform; Truncate by default |
?sync |
Bool |
Whether to synchronously write; true by default |
?baseDirPath |
Option<Path.Path> |
The path to the directory to begin path resolution |
path |
Path.Path |
The file path to write to |
data |
String |
The string to write to the file |
Returns:
type | description |
---|---|
Result<Void, FileError> |
Ok(void) if the operation is successful or Err(err) if a file system error is encountered |