Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FileSystem

Contains a broad set of operations for manipulating files on the file system.

A (potential) blocking and non blocking version of each operation is provided.

The non blocking versions take a handler which is called when the operation completes or an error occurs.

The blocking versions are named xxxBlocking and return the results, or throw exceptions directly. In many cases, depending on the operating system and file system some of the potentially blocking operations can return quickly, which is why we provide them, but it's highly recommended that you test how long they take to return in your particular application before using them on an event loop.

Please consult the documentation for more information on file system support.

Hierarchy

  • FileSystem

Index

Methods

chmod

  • Change the permissions on the file represented by path to perms, asynchronously.

    The permission String takes the form rwxr-x--- as specified here.

    Parameters

    • path: string
    • perms: string

    Returns PromiseLike<void>

  • Change the permissions on the file represented by path to perms, asynchronously.

    The permission String takes the form rwxr-x--- as specified here.

    Parameters

    Returns FileSystem

chmodBlocking

  • chmodBlocking(path: string, perms: string): FileSystem
  • Blocking version of [#chmod(String, String, Handler)] FileSystem

    Parameters

    • path: string
    • perms: string

    Returns FileSystem

chmodRecursive

  • chmodRecursive(path: string, perms: string, dirPerms: string): PromiseLike<void>
  • chmodRecursive(path: string, perms: string, dirPerms: string, handler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>): FileSystem
  • Change the permissions on the file represented by path to perms, asynchronously.

    The permission String takes the form rwxr-x--- as specified in {here}.

    If the file is directory then all contents will also have their permissions changed recursively. Any directory permissions will be set to dirPerms, whilst any normal file permissions will be set to perms.

    Parameters

    • path: string
    • perms: string
    • dirPerms: string

    Returns PromiseLike<void>

  • Change the permissions on the file represented by path to perms, asynchronously.

    The permission String takes the form rwxr-x--- as specified in {here}.

    If the file is directory then all contents will also have their permissions changed recursively. Any directory permissions will be set to dirPerms, whilst any normal file permissions will be set to perms.

    Parameters

    Returns FileSystem

chmodRecursiveBlocking

  • chmodRecursiveBlocking(path: string, perms: string, dirPerms: string): FileSystem
  • Blocking version of {@link FileSystem#chmodRecursive}

    Parameters

    • path: string
    • perms: string
    • dirPerms: string

    Returns FileSystem

chown

  • chown(path: string, user: string | null | undefined, group: string | null | undefined): PromiseLike<void>
  • chown(path: string, user: string | null | undefined, group: string | null | undefined, handler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>): FileSystem
  • Change the ownership on the file represented by path to user and {code group}, asynchronously.

    Parameters

    • path: string
    • user: string | null | undefined
    • group: string | null | undefined

    Returns PromiseLike<void>

  • Change the ownership on the file represented by path to user and {code group}, asynchronously.

    Parameters

    • path: string
    • user: string | null | undefined
    • group: string | null | undefined
    • handler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>

    Returns FileSystem

chownBlocking

  • chownBlocking(path: string, user: string | null | undefined, group: string | null | undefined): FileSystem
  • Blocking version of {@link FileSystem#chown}

    Parameters

    • path: string
    • user: string | null | undefined
    • group: string | null | undefined

    Returns FileSystem

copy

  • Copy a file from the path from to path to, asynchronously.

    The copy will fail if the destination already exists.

    Parameters

    • from: string
    • to: string

    Returns PromiseLike<void>

  • Copy a file from the path from to path to, asynchronously.

    The copy will fail if the destination already exists.

    Parameters

    Returns FileSystem

  • Copy a file from the path from to path to, asynchronously.

    Parameters

    Returns PromiseLike<void>

  • Copy a file from the path from to path to, asynchronously.

    Parameters

    Returns FileSystem

copyBlocking

  • copyBlocking(from: string, to: string): FileSystem
  • Blocking version of {@link FileSystem#copy}

    Parameters

    • from: string
    • to: string

    Returns FileSystem

copyRecursive

  • copyRecursive(from: string, to: string, recursive: boolean): PromiseLike<void>
  • copyRecursive(from: string, to: string, recursive: boolean, handler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>): FileSystem
  • Copy a file from the path from to path to, asynchronously.

    If recursive is true and from represents a directory, then the directory and its contents will be copied recursively to the destination to.

    The copy will fail if the destination if the destination already exists.

    Parameters

    • from: string
    • to: string
    • recursive: boolean

    Returns PromiseLike<void>

  • Copy a file from the path from to path to, asynchronously.

    If recursive is true and from represents a directory, then the directory and its contents will be copied recursively to the destination to.

    The copy will fail if the destination if the destination already exists.

    Parameters

    Returns FileSystem

copyRecursiveBlocking

  • copyRecursiveBlocking(from: string, to: string, recursive: boolean): FileSystem
  • Blocking version of {@link FileSystem#copyRecursive}

    Parameters

    • from: string
    • to: string
    • recursive: boolean

    Returns FileSystem

createFile

  • Creates an empty file with the specified path, asynchronously.

    Parameters

    • path: string

    Returns PromiseLike<void>

  • Creates an empty file with the specified path, asynchronously.

    Parameters

    Returns FileSystem

  • Creates an empty file with the specified path and permissions perms, asynchronously.

    Parameters

    • path: string
    • perms: string

    Returns PromiseLike<void>

  • Creates an empty file with the specified path and permissions perms, asynchronously.

    Parameters

    Returns FileSystem

createFileBlocking

  • createFileBlocking(path: string): FileSystem
  • createFileBlocking(path: string, perms: string): FileSystem
  • Blocking version of {@link FileSystem#createFile}

    Parameters

    • path: string

    Returns FileSystem

  • Blocking version of {@link FileSystem#createFile}

    Parameters

    • path: string
    • perms: string

    Returns FileSystem

createTempDirectory

  • createTempDirectory(prefix: string): PromiseLike<string>
  • createTempDirectory(prefix: string, handler: ((res: AsyncResult<string>) => void) | Handler<AsyncResult<string>>): FileSystem
  • createTempDirectory(prefix: string, perms: string): PromiseLike<string>
  • createTempDirectory(prefix: string, perms: string, handler: ((res: AsyncResult<string>) => void) | Handler<AsyncResult<string>>): FileSystem
  • createTempDirectory(dir: string, prefix: string, perms: string): PromiseLike<string>
  • createTempDirectory(dir: string, prefix: string, perms: string, handler: ((res: AsyncResult<string>) => void) | Handler<AsyncResult<string>>): FileSystem
  • Creates a new directory in the default temporary-file directory, using the given prefix to generate its name, asynchronously.

    As with the File.createTempFile methods, this method is only part of a temporary-file facility.A #addShutdownHook shutdown-hook, or the deleteOnExit mechanism may be used to delete the directory automatically.

    Parameters

    • prefix: string

    Returns PromiseLike<string>

  • Creates a new directory in the default temporary-file directory, using the given prefix to generate its name, asynchronously.

    As with the File.createTempFile methods, this method is only part of a temporary-file facility.A #addShutdownHook shutdown-hook, or the deleteOnExit mechanism may be used to delete the directory automatically.

    Parameters

    Returns FileSystem

  • Creates a new directory in the default temporary-file directory, using the given prefix to generate its name, asynchronously.

    The new directory will be created with permissions as specified by perms.

    The permission String takes the form rwxr-x--- as specified in here.

    As with the File.createTempFile methods, this method is only part of a temporary-file facility.A #addShutdownHook shutdown-hook, or the deleteOnExit mechanism may be used to delete the directory automatically.

    Parameters

    • prefix: string
    • perms: string

    Returns PromiseLike<string>

  • Creates a new directory in the default temporary-file directory, using the given prefix to generate its name, asynchronously.

    The new directory will be created with permissions as specified by perms.

    The permission String takes the form rwxr-x--- as specified in here.

    As with the File.createTempFile methods, this method is only part of a temporary-file facility.A #addShutdownHook shutdown-hook, or the deleteOnExit mechanism may be used to delete the directory automatically.

    Parameters

    Returns FileSystem

  • Creates a new directory in the directory provided by the path path, using the given prefix to generate its name, asynchronously.

    The new directory will be created with permissions as specified by perms.

    The permission String takes the form rwxr-x--- as specified in here.

    As with the File.createTempFile methods, this method is only part of a temporary-file facility.A #addShutdownHook shutdown-hook, or the deleteOnExit mechanism may be used to delete the directory automatically.

    Parameters

    • dir: string
    • prefix: string
    • perms: string

    Returns PromiseLike<string>

  • Creates a new directory in the directory provided by the path path, using the given prefix to generate its name, asynchronously.

    The new directory will be created with permissions as specified by perms.

    The permission String takes the form rwxr-x--- as specified in here.

    As with the File.createTempFile methods, this method is only part of a temporary-file facility.A #addShutdownHook shutdown-hook, or the deleteOnExit mechanism may be used to delete the directory automatically.

    Parameters

    Returns FileSystem

createTempDirectoryBlocking

  • createTempDirectoryBlocking(prefix: string): string
  • createTempDirectoryBlocking(prefix: string, perms: string): string
  • createTempDirectoryBlocking(dir: string, prefix: string, perms: string): string
  • Blocking version of {@link FileSystem#createTempDirectory}

    Parameters

    • prefix: string

    Returns string

  • Blocking version of {@link FileSystem#createTempDirectory}

    Parameters

    • prefix: string
    • perms: string

    Returns string

  • Blocking version of {@link FileSystem#createTempDirectory}

    Parameters

    • dir: string
    • prefix: string
    • perms: string

    Returns string

createTempFile

  • createTempFile(prefix: string, suffix: string): PromiseLike<string>
  • createTempFile(prefix: string, suffix: string, handler: ((res: AsyncResult<string>) => void) | Handler<AsyncResult<string>>): FileSystem
  • createTempFile(prefix: string, suffix: string, perms: string): PromiseLike<string>
  • createTempFile(prefix: string, suffix: string, perms: string, handler: ((res: AsyncResult<string>) => void) | Handler<AsyncResult<string>>): FileSystem
  • createTempFile(dir: string, prefix: string, suffix: string, perms: string): PromiseLike<string>
  • createTempFile(dir: string, prefix: string, suffix: string, perms: string, handler: ((res: AsyncResult<string>) => void) | Handler<AsyncResult<string>>): FileSystem
  • Creates a new file in the default temporary-file directory, using the given prefix and suffix to generate its name, asynchronously.

    As with the File.createTempFile methods, this method is only part of a temporary-file facility.A #addShutdownHook shutdown-hook, or the deleteOnExit mechanism may be used to delete the directory automatically.

    Parameters

    • prefix: string
    • suffix: string

    Returns PromiseLike<string>

  • Creates a new file in the default temporary-file directory, using the given prefix and suffix to generate its name, asynchronously.

    As with the File.createTempFile methods, this method is only part of a temporary-file facility.A #addShutdownHook shutdown-hook, or the deleteOnExit mechanism may be used to delete the directory automatically.

    Parameters

    Returns FileSystem

  • Creates a new file in the directory provided by the path dir, using the given prefix and suffix to generate its name, asynchronously.

    As with the File.createTempFile methods, this method is only part of a temporary-file facility.A #addShutdownHook shutdown-hook, or the deleteOnExit mechanism may be used to delete the directory automatically.

    Parameters

    • prefix: string
    • suffix: string
    • perms: string

    Returns PromiseLike<string>

  • Creates a new file in the directory provided by the path dir, using the given prefix and suffix to generate its name, asynchronously.

    As with the File.createTempFile methods, this method is only part of a temporary-file facility.A #addShutdownHook shutdown-hook, or the deleteOnExit mechanism may be used to delete the directory automatically.

    Parameters

    Returns FileSystem

  • Creates a new file in the directory provided by the path dir, using the given prefix and suffix to generate its name, asynchronously.

    The new directory will be created with permissions as specified by perms.

    The permission String takes the form rwxr-x--- as specified in here.

    As with the File.createTempFile methods, this method is only part of a temporary-file facility.A #addShutdownHook shutdown-hook, or the deleteOnExit mechanism may be used to delete the directory automatically.

    Parameters

    • dir: string
    • prefix: string
    • suffix: string
    • perms: string

    Returns PromiseLike<string>

  • Creates a new file in the directory provided by the path dir, using the given prefix and suffix to generate its name, asynchronously.

    The new directory will be created with permissions as specified by perms.

    The permission String takes the form rwxr-x--- as specified in here.

    As with the File.createTempFile methods, this method is only part of a temporary-file facility.A #addShutdownHook shutdown-hook, or the deleteOnExit mechanism may be used to delete the directory automatically.

    Parameters

    Returns FileSystem

createTempFileBlocking

  • createTempFileBlocking(prefix: string, suffix: string): string
  • createTempFileBlocking(prefix: string, suffix: string, perms: string): string
  • createTempFileBlocking(dir: string, prefix: string, suffix: string, perms: string): string
  • Blocking version of {@link FileSystem#createTempFile}

    Parameters

    • prefix: string
    • suffix: string

    Returns string

  • Blocking version of {@link FileSystem#createTempFile}

    Parameters

    • prefix: string
    • suffix: string
    • perms: string

    Returns string

  • Blocking version of {@link FileSystem#createTempFile}

    Parameters

    • dir: string
    • prefix: string
    • suffix: string
    • perms: string

    Returns string

delete

  • Deletes the file represented by the specified path, asynchronously.

    Parameters

    • path: string

    Returns PromiseLike<void>

  • Deletes the file represented by the specified path, asynchronously.

    Parameters

    Returns FileSystem

deleteBlocking

  • Blocking version of {@link FileSystem#delete}

    Parameters

    • path: string

    Returns FileSystem

deleteRecursive

  • deleteRecursive(path: string, recursive: boolean): PromiseLike<void>
  • deleteRecursive(path: string, recursive: boolean, handler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>): FileSystem
  • Deletes the file represented by the specified path, asynchronously.

    If the path represents a directory and recursive = true then the directory and its contents will be deleted recursively.

    Parameters

    • path: string
    • recursive: boolean

    Returns PromiseLike<void>

  • Deletes the file represented by the specified path, asynchronously.

    If the path represents a directory and recursive = true then the directory and its contents will be deleted recursively.

    Parameters

    Returns FileSystem

deleteRecursiveBlocking

  • deleteRecursiveBlocking(path: string, recursive: boolean): FileSystem
  • Blocking version of {@link FileSystem#deleteRecursive}

    Parameters

    • path: string
    • recursive: boolean

    Returns FileSystem

exists

  • Determines whether the file as specified by the path path exists, asynchronously.

    Parameters

    • path: string

    Returns PromiseLike<boolean>

  • Determines whether the file as specified by the path path exists, asynchronously.

    Parameters

    Returns FileSystem

existsBlocking

  • existsBlocking(path: string): boolean
  • Blocking version of {@link FileSystem#exists}

    Parameters

    • path: string

    Returns boolean

fsProps

  • Returns properties of the file-system being used by the specified path, asynchronously.

    Parameters

    • path: string

    Returns PromiseLike<FileSystemProps>

  • Returns properties of the file-system being used by the specified path, asynchronously.

    Parameters

    Returns FileSystem

fsPropsBlocking

  • Blocking version of {@link FileSystem#fsProps}

    Parameters

    • path: string

    Returns FileSystemProps

link

  • Create a hard link on the file system from link to existing, asynchronously.

    Parameters

    • link: string
    • existing: string

    Returns PromiseLike<void>

  • Create a hard link on the file system from link to existing, asynchronously.

    Parameters

    Returns FileSystem

linkBlocking

  • linkBlocking(link: string, existing: string): FileSystem
  • Blocking version of {@link FileSystem#link}

    Parameters

    • link: string
    • existing: string

    Returns FileSystem

lprops

  • Obtain properties for the link represented by path, asynchronously.

    The link will not be followed.

    Parameters

    • path: string

    Returns PromiseLike<FileProps>

  • Obtain properties for the link represented by path, asynchronously.

    The link will not be followed.

    Parameters

    Returns FileSystem

lpropsBlocking

  • Blocking version of {@link FileSystem#lprops}

    Parameters

    • path: string

    Returns FileProps

mkdir

  • Create the directory represented by path, asynchronously.

    The operation will fail if the directory already exists.

    Parameters

    • path: string

    Returns PromiseLike<void>

  • Create the directory represented by path, asynchronously.

    The operation will fail if the directory already exists.

    Parameters

    Returns FileSystem

  • Create the directory represented by path, asynchronously.

    The new directory will be created with permissions as specified by perms.

    The permission String takes the form rwxr-x--- as specified in here.

    The operation will fail if the directory already exists.

    Parameters

    • path: string
    • perms: string

    Returns PromiseLike<void>

  • Create the directory represented by path, asynchronously.

    The new directory will be created with permissions as specified by perms.

    The permission String takes the form rwxr-x--- as specified in here.

    The operation will fail if the directory already exists.

    Parameters

    Returns FileSystem

mkdirBlocking

  • Blocking version of {@link FileSystem#mkdir}

    Parameters

    • path: string

    Returns FileSystem

  • Blocking version of {@link FileSystem#mkdir}

    Parameters

    • path: string
    • perms: string

    Returns FileSystem

mkdirs

  • Create the directory represented by path and any non existent parents, asynchronously.

    The operation will fail if the path already exists but is not a directory.

    Parameters

    • path: string

    Returns PromiseLike<void>

  • Create the directory represented by path and any non existent parents, asynchronously.

    The operation will fail if the path already exists but is not a directory.

    Parameters

    Returns FileSystem

  • Create the directory represented by path and any non existent parents, asynchronously.

    The new directory will be created with permissions as specified by perms.

    The permission String takes the form rwxr-x--- as specified in here.

    The operation will fail if the path already exists but is not a directory.

    Parameters

    • path: string
    • perms: string

    Returns PromiseLike<void>

  • Create the directory represented by path and any non existent parents, asynchronously.

    The new directory will be created with permissions as specified by perms.

    The permission String takes the form rwxr-x--- as specified in here.

    The operation will fail if the path already exists but is not a directory.

    Parameters

    Returns FileSystem

mkdirsBlocking

  • Blocking version of {@link FileSystem#mkdirs}

    Parameters

    • path: string

    Returns FileSystem

  • Blocking version of {@link FileSystem#mkdirs}

    Parameters

    • path: string
    • perms: string

    Returns FileSystem

move

  • Move a file from the path from to path to, asynchronously.

    The move will fail if the destination already exists.

    Parameters

    • from: string
    • to: string

    Returns PromiseLike<void>

  • Move a file from the path from to path to, asynchronously.

    The move will fail if the destination already exists.

    Parameters

    Returns FileSystem

  • Move a file from the path from to path to, asynchronously.

    Parameters

    Returns PromiseLike<void>

  • Move a file from the path from to path to, asynchronously.

    Parameters

    Returns FileSystem

moveBlocking

  • moveBlocking(from: string, to: string): FileSystem
  • Blocking version of {@link FileSystem#move}

    Parameters

    • from: string
    • to: string

    Returns FileSystem

open

  • Open the file represented by path, asynchronously.

    The file is opened for both reading and writing. If the file does not already exist it will be created.

    Parameters

    Returns PromiseLike<AsyncFile>

  • Open the file represented by path, asynchronously.

    The file is opened for both reading and writing. If the file does not already exist it will be created.

    Parameters

    Returns FileSystem

openBlocking

  • Blocking version of {@link FileSystem#open}

    Parameters

    Returns AsyncFile

props

  • Obtain properties for the file represented by path, asynchronously.

    If the file is a link, the link will be followed.

    Parameters

    • path: string

    Returns PromiseLike<FileProps>

  • Obtain properties for the file represented by path, asynchronously.

    If the file is a link, the link will be followed.

    Parameters

    Returns FileSystem

propsBlocking

  • Blocking version of {@link FileSystem#props}

    Parameters

    • path: string

    Returns FileProps

readDir

  • Read the contents of the directory specified by path, asynchronously.

    The result is an array of String representing the paths of the files inside the directory.

    Parameters

    • path: string

    Returns PromiseLike<string>

  • Read the contents of the directory specified by path, asynchronously.

    The result is an array of String representing the paths of the files inside the directory.

    Parameters

    Returns FileSystem

  • Read the contents of the directory specified by path, asynchronously.

    The parameter filter is a regular expression. If filter is specified then only the paths that match @{filter}will be returned.

    The result is an array of String representing the paths of the files inside the directory.

    Parameters

    • path: string
    • filter: string

    Returns PromiseLike<string>

  • Read the contents of the directory specified by path, asynchronously.

    The parameter filter is a regular expression. If filter is specified then only the paths that match @{filter}will be returned.

    The result is an array of String representing the paths of the files inside the directory.

    Parameters

    Returns FileSystem

readDirBlocking

  • readDirBlocking(path: string): string
  • readDirBlocking(path: string, filter: string): string
  • Blocking version of {@link FileSystem#readDir}

    Parameters

    • path: string

    Returns string

  • Blocking version of {@link FileSystem#readDir}

    Parameters

    • path: string
    • filter: string

    Returns string

readFile

  • Reads the entire file as represented by the path path as a , asynchronously.

    Do not use this method to read very large files or you risk running out of available RAM.

    Parameters

    • path: string

    Returns PromiseLike<Buffer>

  • Reads the entire file as represented by the path path as a , asynchronously.

    Do not use this method to read very large files or you risk running out of available RAM.

    Parameters

    Returns FileSystem

readFileBlocking

  • readFileBlocking(path: string): Buffer
  • Blocking version of {@link FileSystem#readFile}

    Parameters

    • path: string

    Returns Buffer

readSymlink

  • Returns the path representing the file that the symbolic link specified by link points to, asynchronously.

    Parameters

    • link: string

    Returns PromiseLike<string>

  • Returns the path representing the file that the symbolic link specified by link points to, asynchronously.

    Parameters

    Returns FileSystem

readSymlinkBlocking

  • readSymlinkBlocking(link: string): string
  • Blocking version of {@link FileSystem#readSymlink}

    Parameters

    • link: string

    Returns string

symlink

  • Create a symbolic link on the file system from link to existing, asynchronously.

    Parameters

    • link: string
    • existing: string

    Returns PromiseLike<void>

  • Create a symbolic link on the file system from link to existing, asynchronously.

    Parameters

    Returns FileSystem

symlinkBlocking

  • symlinkBlocking(link: string, existing: string): FileSystem
  • Blocking version of {@link FileSystem#link}

    Parameters

    • link: string
    • existing: string

    Returns FileSystem

truncate

  • Truncate the file represented by path to length len in bytes, asynchronously.

    The operation will fail if the file does not exist or len is less than zero.

    Parameters

    • path: string
    • len: number

    Returns PromiseLike<void>

  • Truncate the file represented by path to length len in bytes, asynchronously.

    The operation will fail if the file does not exist or len is less than zero.

    Parameters

    Returns FileSystem

truncateBlocking

  • truncateBlocking(path: string, len: number): FileSystem
  • Blocking version of {@link FileSystem#truncate}

    Parameters

    • path: string
    • len: number

    Returns FileSystem

unlink

  • Unlinks the link on the file system represented by the path link, asynchronously.

    Parameters

    • link: string

    Returns PromiseLike<void>

  • Unlinks the link on the file system represented by the path link, asynchronously.

    Parameters

    Returns FileSystem

unlinkBlocking

  • Blocking version of {@link FileSystem#unlink}

    Parameters

    • link: string

    Returns FileSystem

writeFile

  • Creates the file, and writes the specified Buffer data to the file represented by the path path, asynchronously.

    Parameters

    Returns PromiseLike<void>

  • Creates the file, and writes the specified Buffer data to the file represented by the path path, asynchronously.

    Parameters

    Returns FileSystem

writeFileBlocking

  • Blocking version of {@link FileSystem#writeFile}

    Parameters

    Returns FileSystem

Generated using TypeDoc