Options
All
  • Public
  • Public/Protected
  • All
Menu

Tasks File System

This library is a wrapper of async functions of Node.js fs module using @ts-task instead of Promises.

Use

Install it

npm i @ts-task/fs

Use it

import * as fs from '@ts-task/fs';


fs.readFile('./README.md')
    .fork(
        err => {
            err; // $ExpectType ErrnoException
            if (err.code === 'ENOENT') {
                console.error('Buu, the file does not exists');
            }
        },
        buffer => {
            buffer; // ExpectType Buffer
            console.log(buffer.toString());
        }
    )

You can see the API reference here.

You can see more example usages in the types test file.

Index

Variables

Const access

access: function = liftErrbackOverride<Access>(fs.access)

Type declaration

    • (path: fs.PathLike, mode?: undefined | number): Task<void, ErrnoException>
    • Asynchronously tests a user's permissions for the file specified by path.

      see

      https://nodejs.org/api/fs.html#fs_fs_access_path_mode_callback

      Parameters

      • path: fs.PathLike

        A path to a file or directory. If a URL is provided, it must use the file: protocol. URL support is experimental.

      • Optional mode: undefined | number

      Returns Task<void, ErrnoException>

Const appendFile

appendFile: function = liftErrbackOverride<AppendFile>(fs.appendFile)

Type declaration

    • (file: fs.PathLike | number, data: any, options?: fs.WriteFileOptions): Task<void, ErrnoException>
    • Asynchronously append data to a file, creating the file if it does not exist.

      see

      https://nodejs.org/api/fs.html#fs_fs_appendfile_path_data_options_callback

      Parameters

      • file: fs.PathLike | number

        A path to a file. If a URL is provided, it must use the file: protocol. URL support is experimental. If a file descriptor is provided, the underlying file will not be closed automatically.

      • data: any

        The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.

      • Optional options: fs.WriteFileOptions

        Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag. If encoding is not supplied, the default of 'utf8' is used. If mode is not supplied, the default of 0o666 is used. If mode is a string, it is parsed as an octal integer. If flag is not supplied, the default of 'a' is used.

      Returns Task<void, ErrnoException>

Const chmod

chmod: function = liftErrbackOverride<Chmod>(fs.chmod)

Type declaration

    • (path: fs.PathLike, mode: string | number): Task<void, ErrnoException>
    • Asynchronous chmod(2) - Change permissions of a file.

      see

      https://nodejs.org/api/fs.html#fs_fs_chmod_path_mode_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • mode: string | number

        A file mode. If a string is passed, it is parsed as an octal integer.

      Returns Task<void, ErrnoException>

Const chown

chown: function = liftErrbackOverride<Chown>(fs.chown)

Type declaration

    • (path: fs.PathLike, uid: number, gid: number): Task<void, ErrnoException>

Const close

close: function = liftErrbackOverride<Close>(fs.close)

Type declaration

Const copyFile

copyFile: function = liftErrbackOverride<CopyFile>(fs.copyFile)

Type declaration

    • (src: fs.PathLike, dest: fs.PathLike, flags?: undefined | number): Task<void, ErrnoException>
    • Asynchronously copies src to dest. By default, dest is overwritten if it already exists. No arguments other than a possible exception are given to the callback function. Node.js makes no guarantees about the atomicity of the copy operation. If an error occurs after the destination file has been opened for writing, Node.js will attempt to remove the destination.

      see

      https://nodejs.org/api/fs.html#fs_fs_copyfile_src_dest_flags_callback

      Parameters

      • src: fs.PathLike

        A path to the source file.

      • dest: fs.PathLike

        A path to the destination file.

      • Optional flags: undefined | number

        An integer that specifies the behavior of the copy operation. The only supported flag is fs.constants.COPYFILE_EXCL, which causes the copy operation to fail if dest already exists.

      Returns Task<void, ErrnoException>

Const fchmod

fchmod: function = liftErrbackOverride<Fchmod>(fs.fchmod)

Type declaration

    • (fd: number, mode: string | number): Task<void, ErrnoException>

Const fchown

fchown: function = liftErrbackOverride<Fchown>(fs.fchown)

Type declaration

Const fdatasync

fdatasync: function = liftErrbackOverride<Fdatasync>(fs.fdatasync)

Type declaration

Const fstat

fstat: function = liftErrbackOverride<Fstat>(fs.fstat)

Type declaration

Const fsync

fsync: function = liftErrbackOverride<Fsync>(fs.fsync)

Type declaration

    • (fd: number): Task<void, ErrnoException>

Const ftruncate

ftruncate: function = liftErrbackOverride<Ftruncate>(fs.ftruncate)

Type declaration

Const futimes

futimes: function = liftErrbackOverride<Futimes>(fs.futimes)

Type declaration

    • (fd: number, atime: string | number | Date, mtime: string | number | Date): Task<void, ErrnoException>
    • Asynchronously change file timestamps of the file referenced by the supplied file descriptor.

      see

      https://nodejs.org/docs/latest-v10.x/api/fs.html#fs_fs_futimes_fd_atime_mtime_callback

      Parameters

      • fd: number

        A file descriptor.

      • atime: string | number | Date

        The last access time. If a string is provided, it will be coerced to number.

      • mtime: string | number | Date

        The last modified time. If a string is provided, it will be coerced to number.

      Returns Task<void, ErrnoException>

Const lchmod

lchmod: function = liftErrbackOverride<Lchmod>(fs.lchmod)

Type declaration

    • (path: fs.PathLike, mode: string | number): Task<void, ErrnoException>
    • Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.

      see

      https://nodejs.org/docs/latest-v10.x/api/fs.html#fs_fs_lchmod_path_mode_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • mode: string | number

        A file mode. If a string is passed, it is parsed as an octal integer.

      Returns Task<void, ErrnoException>

Const lchown

lchown: function = liftErrbackOverride<Lchown>(fs.lchown)

Type declaration

Const link

link: function = liftErrbackOverride<Link>(fs.link)

Type declaration

    • (existingPath: fs.PathLike, newPath: fs.PathLike): Task<void, ErrnoException>

Const lstat

lstat: function = liftErrbackOverride<Lstat>(fs.lstat)

Type declaration

Const mkdir

mkdir: function = liftErrbackOverride<Mkdir>(fs.mkdir)

Type declaration

    • (path: fs.PathLike, options?: number | string | MakeDirectoryOptions | null): Task<void, ErrnoException>
    • Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • Optional options: number | string | MakeDirectoryOptions | null

        Either the file mode, or an object optionally specifying the file mode and whether parent folders should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to 0o777.

      Returns Task<void, ErrnoException>

Const mkdtemp

mkdtemp: function = liftErrbackOverride<Mkdtemp>(fs.mkdtemp)

Type declaration

    • (prefix: string, options?: object | BufferEncoding | null): Task<string, ErrnoException>
    • (prefix: string, options: "buffer" | object): Task<Buffer, ErrnoException>
    • (prefix: string, options: object | string | undefined | null): Task<string | Buffer, ErrnoException>
    • Asynchronously creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory.

      see

      https://nodejs.org/docs/latest-v10.x/api/fs.html#fs_fs_mkdtemp_prefix_options_callback

      Parameters

      • prefix: string
      • Optional options: object | BufferEncoding | null

        The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, 'utf8' is used.

      Returns Task<string, ErrnoException>

    • Asynchronously creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory.

      see

      https://nodejs.org/docs/latest-v10.x/api/fs.html#fs_fs_mkdtemp_prefix_options_callback

      Parameters

      • prefix: string
      • options: "buffer" | object

        The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, 'utf8' is used.

      Returns Task<Buffer, ErrnoException>

    • Asynchronously creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory.

      see

      https://nodejs.org/docs/latest-v10.x/api/fs.html#fs_fs_mkdtemp_prefix_options_callback

      Parameters

      • prefix: string
      • options: object | string | undefined | null

        The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, 'utf8' is used.

      Returns Task<string | Buffer, ErrnoException>

Const open

open: function = liftErrbackOverride<Open>(fs.open)

Type declaration

    • (path: fs.PathLike, flags: string | number, mode?: string | number | null): Task<number, ErrnoException>
    • Asynchronous open(2) - open and possibly create a file.

      see

      https://nodejs.org/docs/latest-v10.x/api/fs.html#fs_fs_open_path_flags_mode_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • flags: string | number
      • Optional mode: string | number | null

        A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to 0o666.

      Returns Task<number, ErrnoException>

Const readFile

readFile: function = liftErrbackOverride<ReadFile>(fs.readFile)

Type declaration

    • (path: fs.PathLike | number): Task<Buffer, ErrnoException>
    • (path: fs.PathLike | number, options: object | string): Task<string, ErrnoException>
    • (path: fs.PathLike | number, options: object | string | undefined | null): Task<Buffer | string, ErrnoException>
    • Asynchronously reads the entire contents of a file.

      see

      https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback

      Parameters

      • path: fs.PathLike | number

        A path to a file. If a URL is provided, it must use the file: protocol. If a file descriptor is provided, the underlying file will not be closed automatically.

      Returns Task<Buffer, ErrnoException>

    • Asynchronously reads the entire contents of a file.

      see

      https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback

      Parameters

      • path: fs.PathLike | number

        A path to a file. If a URL is provided, it must use the file: protocol. URL support is experimental. If a file descriptor is provided, the underlying file will not be closed automatically.

      • options: object | string

        Either the encoding for the result, or an object that contains the encoding and an optional flag. If a flag is not provided, it defaults to 'r'.

      Returns Task<string, ErrnoException>

    • Asynchronously reads the entire contents of a file.

      see

      https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback

      Parameters

      • path: fs.PathLike | number

        A path to a file. If a URL is provided, it must use the file: protocol. URL support is experimental. If a file descriptor is provided, the underlying file will not be closed automatically.

      • options: object | string | undefined | null

        Either the encoding for the result, or an object that contains the encoding and an optional flag. If a flag is not provided, it defaults to 'r'.

      Returns Task<Buffer | string, ErrnoException>

Const readdir

readdir: function = liftErrbackOverride<Readdir>(fs.readdir)

Type declaration

    • (path: fs.PathLike, options?: object | BufferEncoding | null): Task<string[], ErrnoException>
    • (path: fs.PathLike, options: object | "buffer"): Task<Buffer[], ErrnoException>
    • (path: fs.PathLike, options: object | string | undefined | null): Task<string[] | Buffer[], ErrnoException>
    • (path: fs.PathLike, options: object): Task<Dirent[], ErrnoException>
    • Asynchronous readdir(3) - read a directory.

      see

      https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • Optional options: object | BufferEncoding | null

        The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, 'utf8' is used.

      Returns Task<string[], ErrnoException>

    • Asynchronous readdir(3) - read a directory.

      see

      https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • options: object | "buffer"

        The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, 'utf8' is used.

      Returns Task<Buffer[], ErrnoException>

    • Asynchronous readdir(3) - read a directory.

      see

      https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • options: object | string | undefined | null

        The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, 'utf8' is used.

      Returns Task<string[] | Buffer[], ErrnoException>

    • Asynchronous readdir(3) - read a directory.

      see

      https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • options: object

        If called with withFileTypes: true the result data will be an array of Dirent.

        • withFileTypes: true

      Returns Task<Dirent[], ErrnoException>

Const readlink

readlink: function = liftErrbackOverride<Readlink>(fs.readlink)

Type declaration

    • (path: fs.PathLike, options?: object | BufferEncoding | null): Task<string, ErrnoException>
    • (path: fs.PathLike, options: object | "buffer"): Task<Buffer, ErrnoException>
    • (path: fs.PathLike, options: object | string | undefined | null): Task<string | Buffer, ErrnoException>
    • Asynchronous readlink(2) - read value of a symbolic link.

      see

      https://nodejs.org/api/fs.html#fs_fs_readlink_path_options_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • Optional options: object | BufferEncoding | null

        The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, 'utf8' is used.

      Returns Task<string, ErrnoException>

    • Asynchronous readlink(2) - read value of a symbolic link.

      see

      https://nodejs.org/api/fs.html#fs_fs_readlink_path_options_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • options: object | "buffer"

        The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, 'utf8' is used.

      Returns Task<Buffer, ErrnoException>

    • Asynchronous readlink(2) - read value of a symbolic link.

      see

      https://nodejs.org/api/fs.html#fs_fs_readlink_path_options_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • options: object | string | undefined | null

        The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, 'utf8' is used.

      Returns Task<string | Buffer, ErrnoException>

Const realpath

realpath: function = liftErrbackOverride<Realpath>(fs.realpath)

Type declaration

    • (path: fs.PathLike, options?: object | BufferEncoding | null): Task<string, ErrnoException>
    • (path: fs.PathLike, options: object | "buffer"): Task<Buffer, ErrnoException>
    • (path: fs.PathLike, options: object | string | undefined | null): Task<string | Buffer, ErrnoException>
    • Asynchronous realpath(3) - return the canonicalized absolute pathname.

      see

      https://nodejs.org/api/fs.html#fs_fs_realpath_path_options_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • Optional options: object | BufferEncoding | null

        The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, 'utf8' is used.

      Returns Task<string, ErrnoException>

    • Asynchronous realpath(3) - return the canonicalized absolute pathname.

      see

      https://nodejs.org/api/fs.html#fs_fs_realpath_path_options_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • options: object | "buffer"

        The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, 'utf8' is used.

      Returns Task<Buffer, ErrnoException>

    • Asynchronous realpath(3) - return the canonicalized absolute pathname.

      see

      https://nodejs.org/api/fs.html#fs_fs_realpath_path_options_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • options: object | string | undefined | null

        The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, 'utf8' is used.

      Returns Task<string | Buffer, ErrnoException>

Const rename

rename: function = liftErrbackOverride<Rename>(fs.rename)

Type declaration

    • (oldPath: fs.PathLike, newPath: fs.PathLike): Task<void, ErrnoException>
    • Asynchronous rename(2) - Change the name or location of a file or directory.

      see

      https://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback

      Parameters

      • oldPath: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol. URL support is experimental.

      • newPath: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol. URL support is experimental.

      Returns Task<void, ErrnoException>

Const rmdir

rmdir: function = liftErrbackOverride<Rmdir>(fs.rmdir)

Type declaration

    • (path: fs.PathLike): Task<void, ErrnoException>

Const stat

stat: function = liftErrbackOverride<Stat>(fs.stat)

Type declaration

Const symlink

symlink: function = liftErrbackOverride<Symlink>(fs.symlink)

Type declaration

    • (target: fs.PathLike, path: fs.PathLike, type?: fs.symlink.Type | null): Task<void, ErrnoException>
    • Asynchronous symlink(2) - Create a new symbolic link to an existing file.

      see

      https://nodejs.org/api/fs.html#fs_fs_symlink_target_path_type_callback

      Parameters

      • target: fs.PathLike

        A path to an existing file. If a URL is provided, it must use the file: protocol.

      • path: fs.PathLike

        A path to the new symlink. If a URL is provided, it must use the file: protocol.

      • Optional type: fs.symlink.Type | null

        May be set to 'dir', 'file', or 'junction' (default is 'file') and is only available on Windows (ignored on other platforms). When using 'junction', the target argument will automatically be normalized to an absolute path.

      Returns Task<void, ErrnoException>

Const truncate

truncate: function = liftErrbackOverride<Truncate>(fs.truncate)

Type declaration

    • (path: fs.PathLike, len?: number | null): Task<void, ErrnoException>
    • Asynchronous truncate(2) - Truncate a file to a specified length.

      see

      https://nodejs.org/api/fs.html#fs_fs_truncate_path_len_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • Optional len: number | null

        If not specified, defaults to 0.

      Returns Task<void, ErrnoException>

Const unlink

unlink: function = liftErrbackOverride<Unlink>(fs.unlink)

Type declaration

    • (path: fs.PathLike): Task<void, ErrnoException>

Const utimes

utimes: function = liftErrbackOverride<Utimes>(fs.utimes)

Type declaration

    • (path: fs.PathLike, atime: string | number | Date, mtime: string | number | Date): Task<void, ErrnoException>
    • Asynchronously change file timestamps of the file referenced by the supplied path.

      see

      https://nodejs.org/api/fs.html#fs_fs_utimes_path_atime_mtime_callback

      Parameters

      • path: fs.PathLike

        A path to a file. If a URL is provided, it must use the file: protocol.

      • atime: string | number | Date

        The last access time. If a string is provided, it will be coerced to number.

      • mtime: string | number | Date

        The last modified time. If a string is provided, it will be coerced to number.

      Returns Task<void, ErrnoException>

Const writeFile

writeFile: function = liftErrbackOverride<WriteFile>(fs.writeFile)

Type declaration

    • (path: fs.PathLike | number, data: any, options?: fs.WriteFileOptions): Task<void, ErrnoException>
    • Asynchronously writes data to a file, replacing the file if it already exists.

      see

      https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback

      Parameters

      • path: fs.PathLike | number

        A path to a file. If a URL is provided, it must use the file: protocol. URL support is experimental. If a file descriptor is provided, the underlying file will not be closed automatically.

      • data: any

        The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.

      • Optional options: fs.WriteFileOptions

        Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag. If encoding is not supplied, the default of 'utf8' is used. If mode is not supplied, the default of 0o666 is used. If mode is a string, it is parsed as an octal integer. If flag is not supplied, the default of 'w' is used.

      Returns Task<void, ErrnoException>

Functions

read

  • read<TBuffer>(fd: number, buffer: TBuffer, offset: number, length: number, position: number | null): Task<object, ErrnoException>
  • Asynchronously reads data from the file referenced by the supplied file descriptor.

    see

    https://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback

    Type parameters

    • TBuffer: fs.BinaryData

    Parameters

    • fd: number

      A file descriptor.

    • buffer: TBuffer

      The buffer that the data will be written to.

    • offset: number

      The offset in the buffer at which to start writing.

    • length: number

      The number of bytes to read.

    • position: number | null

      The offset from the beginning of the file from which data should be read. If null, data will be read from the current position.

    Returns Task<object, ErrnoException>

write

  • write<TBuffer>(fd: number, buffer: TBuffer, offset?: number | null, length?: number | null, position?: number | null): Task<object, ErrnoException>
  • write(fd: number, str: any, position?: number | null, encoding?: string | null): Task<object, ErrnoException>
  • Asynchronously writes buffer to the file referenced by the supplied file descriptor.

    see

    https://nodejs.org/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback

    Type parameters

    • TBuffer: fs.BinaryData

    Parameters

    • fd: number

      A file descriptor.

    • buffer: TBuffer
    • Optional offset: number | null

      The part of the buffer to be written. If not supplied, defaults to 0.

    • Optional length: number | null

      The number of bytes to write. If not supplied, defaults to buffer.length - offset.

    • Optional position: number | null

      The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.

    Returns Task<object, ErrnoException>

  • Asynchronously writes string to the file referenced by the supplied file descriptor.

    see

    https://nodejs.org/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback

    Parameters

    • fd: number

      A file descriptor.

    • str: any
    • Optional position: number | null

      The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.

    • Optional encoding: string | null

      The expected string encoding.

    Returns Task<object, ErrnoException>

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc