Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface FSModule

Hierarchy

  • FS
    • FSModule

Index

Properties

FS

FS: FS

The FS constructor.

F_OK

F_OK: number = 0

R_OK

R_OK: number = 4

W_OK

W_OK: number = 2

X_OK

X_OK: number = 1

Static Stats

Stats: Stats = Stats

Methods

_toUnixTimestamp

  • _toUnixTimestamp(time: Date | number): number
  • converts Date or number to a fractional UNIX timestamp Grabbed from NodeJS sources (lib/fs.js)

    Parameters

    • time: Date | number

    Returns number

access

  • access(path: string, callback: function): void
  • access(path: string, mode: number, callback: function): void
  • Parameters

    • path: string
    • callback: function

    Returns void

  • Parameters

    • path: string
    • mode: number
    • callback: function

    Returns void

accessSync

  • accessSync(path: string, mode?: number): void
  • Parameters

    • path: string
    • Optional mode: number

    Returns void

appendFile

  • Asynchronously append data to a file, creating the file if it not yet exists.

    example

    Usage example fs.appendFile('message.txt', 'data to append', function (err) { if (err) throw err; console.log('The "data to append" was appended to file!'); });

    option

    options [String] encoding Defaults to 'utf8'.

    option

    options [Number] mode Defaults to 0644.

    option

    options [String] flag Defaults to 'a'.

    Parameters

    Returns void

  • Parameters

    • filename: string
    • data: any
    • Optional options: object
      • Optional encoding?: string
      • Optional flag?: string
      • Optional mode?: number | string
    • Optional cb: BFSOneArgCallback

    Returns void

  • Parameters

    • filename: string
    • data: any
    • Optional encoding: string
    • Optional cb: BFSOneArgCallback

    Returns void

appendFileSync

  • appendFileSync(filename: string, data: any, options?: object): void
  • appendFileSync(filename: string, data: any, encoding?: string): void
  • Asynchronously append data to a file, creating the file if it not yet exists.

    example

    Usage example fs.appendFile('message.txt', 'data to append', function (err) { if (err) throw err; console.log('The "data to append" was appended to file!'); });

    option

    options [String] encoding Defaults to 'utf8'.

    option

    options [Number] mode Defaults to 0644.

    option

    options [String] flag Defaults to 'a'.

    Parameters

    • filename: string
    • data: any
    • Optional options: object
      • Optional encoding?: string
      • Optional flag?: string
      • Optional mode?: number | string

    Returns void

  • Parameters

    • filename: string
    • data: any
    • Optional encoding: string

    Returns void

changeFSModule

  • changeFSModule(newFs: FS): void
  • Set the FS object backing the fs module.

    Parameters

    • newFs: FS

    Returns void

chmod

  • Asynchronous chmod.

    Parameters

    Returns void

chmodSync

  • chmodSync(path: string, mode: string | number): void
  • Synchronous chmod.

    Parameters

    • path: string
    • mode: string | number

    Returns void

chown

  • Asynchronous chown.

    Parameters

    Returns void

chownSync

  • chownSync(path: string, uid: number, gid: number): void
  • Synchronous chown.

    Parameters

    • path: string
    • uid: number
    • gid: number

    Returns void

close

  • Asynchronous close.

    Parameters

    Returns void

closeSync

  • closeSync(fd: number): void
  • Synchronous close.

    Parameters

    • fd: number

    Returns void

createReadStream

  • createReadStream(path: string, options?: object): ReadStream
  • Parameters

    • path: string
    • Optional options: object
      • Optional autoClose?: boolean
      • Optional encoding?: string
      • Optional fd?: number
      • Optional flags?: string
      • Optional mode?: number

    Returns ReadStream

createWriteStream

  • createWriteStream(path: string, options?: object): WriteStream
  • Parameters

    • path: string
    • Optional options: object
      • Optional encoding?: string
      • Optional fd?: number
      • Optional flags?: string
      • Optional mode?: number

    Returns WriteStream

exists

  • exists(path: string, cb?: function): void
  • Test whether or not the given path exists by checking with the file system. Then call the callback argument with either true or false.

    example

    Sample invocation fs.exists('/etc/passwd', function (exists) { util.debug(exists ? "it's there" : "no passwd!"); });

    Parameters

    • path: string
    • Default value cb: function = nopCb
        • (exists: boolean): any
        • Parameters

          • exists: boolean

          Returns any

    Returns void

existsSync

  • existsSync(path: string): boolean
  • Test whether or not the given path exists by checking with the file system.

    Parameters

    • path: string

    Returns boolean

fchmod

  • Asynchronous fchmod.

    Parameters

    Returns void

fchmodSync

  • fchmodSync(fd: number, mode: number | string): void
  • Synchronous fchmod.

    Parameters

    • fd: number
    • mode: number | string

    Returns void

fchown

  • Asynchronous fchown.

    Parameters

    • fd: number
    • uid: number
    • gid: number
    • Default value callback: BFSOneArgCallback = nopCb

    Returns void

fchownSync

  • fchownSync(fd: number, uid: number, gid: number): void
  • Synchronous fchown.

    Parameters

    • fd: number
    • uid: number
    • gid: number

    Returns void

fdatasync

  • Asynchronous fdatasync.

    Parameters

    Returns void

fdatasyncSync

  • fdatasyncSync(fd: number): void
  • Synchronous fdatasync.

    Parameters

    • fd: number

    Returns void

fstat

  • Asynchronous fstat. fstat() is identical to stat(), except that the file to be stat-ed is specified by the file descriptor fd.

    Parameters

    Returns void

fstatSync

  • fstatSync(fd: number): Stats
  • Synchronous fstat. fstat() is identical to stat(), except that the file to be stat-ed is specified by the file descriptor fd.

    Parameters

    • fd: number

    Returns Stats

fsync

  • Asynchronous fsync.

    Parameters

    Returns void

fsyncSync

  • fsyncSync(fd: number): void
  • Synchronous fsync.

    Parameters

    • fd: number

    Returns void

ftruncate

  • Asynchronous ftruncate.

    Parameters

    Returns void

  • Parameters

    Returns void

ftruncateSync

  • ftruncateSync(fd: number, len?: number): void
  • Synchronous ftruncate.

    Parameters

    • fd: number
    • Default value len: number = 0

    Returns void

futimes

  • futimes(fd: number, atime: number | Date, mtime: number | Date, cb?: BFSOneArgCallback): void
  • Change the file timestamps of a file referenced by the supplied file descriptor.

    Parameters

    • fd: number
    • atime: number | Date
    • mtime: number | Date
    • Default value cb: BFSOneArgCallback = nopCb

    Returns void

futimesSync

  • futimesSync(fd: number, atime: number | Date, mtime: number | Date): void
  • Change the file timestamps of a file referenced by the supplied file descriptor.

    Parameters

    • fd: number
    • atime: number | Date
    • mtime: number | Date

    Returns void

getFSModule

  • getFSModule(): FS
  • Retrieve the FS object backing the fs module.

    Returns FS

getRootFS

  • NONSTANDARD: Grab the FileSystem instance that backs this API.

    Returns FileSystem | null

    Returns null if the file system has not been initialized.

initialize

lchmod

  • Asynchronous lchmod.

    Parameters

    Returns void

lchmodSync

  • lchmodSync(path: string, mode: number | string): void
  • Synchronous lchmod.

    Parameters

    • path: string
    • mode: number | string

    Returns void

lchown

  • Asynchronous lchown.

    Parameters

    Returns void

lchownSync

  • lchownSync(path: string, uid: number, gid: number): void
  • Synchronous lchown.

    Parameters

    • path: string
    • uid: number
    • gid: number

    Returns void

link

  • Asynchronous link.

    Parameters

    Returns void

linkSync

  • linkSync(srcpath: string, dstpath: string): void
  • Synchronous link.

    Parameters

    • srcpath: string
    • dstpath: string

    Returns void

lstat

  • Asynchronous lstat. lstat() is identical to stat(), except that if path is a symbolic link, then the link itself is stat-ed, not the file that it refers to.

    Parameters

    Returns void

lstatSync

  • lstatSync(path: string): Stats
  • Synchronous lstat. lstat() is identical to stat(), except that if path is a symbolic link, then the link itself is stat-ed, not the file that it refers to.

    Parameters

    • path: string

    Returns Stats

mkdir

  • Asynchronous mkdir.

    Parameters

    • path: string
    • Optional mode: any

      defaults to 0777

    • Default value cb: BFSOneArgCallback = nopCb

    Returns void

mkdirSync

  • mkdirSync(path: string, mode?: number | string): void
  • Synchronous mkdir.

    Parameters

    • path: string
    • Optional mode: number | string

      defaults to 0777

    Returns void

open

  • open(path: string, flag: string, cb?: BFSCallback<number>): void
  • open(path: string, flag: string, mode: number | string, cb?: BFSCallback<number>): void
  • Asynchronous file open. Exclusive mode ensures that path is newly created.

    flags can be:

    • 'r' - Open file for reading. An exception occurs if the file does not exist.
    • 'r+' - Open file for reading and writing. An exception occurs if the file does not exist.
    • 'rs' - Open file for reading in synchronous mode. Instructs the filesystem to not cache writes.
    • 'rs+' - Open file for reading and writing, and opens the file in synchronous mode.
    • 'w' - Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
    • 'wx' - Like 'w' but opens the file in exclusive mode.
    • 'w+' - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
    • 'wx+' - Like 'w+' but opens the file in exclusive mode.
    • 'a' - Open file for appending. The file is created if it does not exist.
    • 'ax' - Like 'a' but opens the file in exclusive mode.
    • 'a+' - Open file for reading and appending. The file is created if it does not exist.
    • 'ax+' - Like 'a+' but opens the file in exclusive mode.
    see

    http://www.manpagez.com/man/2/open/

    Parameters

    • path: string
    • flag: string
    • Optional cb: BFSCallback<number>

    Returns void

  • Parameters

    • path: string
    • flag: string
    • mode: number | string
    • Optional cb: BFSCallback<number>

    Returns void

openSync

  • openSync(path: string, flag: string, mode?: number | string): number
  • Synchronous file open.

    see

    http://www.manpagez.com/man/2/open/

    Parameters

    • path: string
    • flag: string
    • Default value mode: number | string = 420

      defaults to 0644

    Returns number

read

  • read(fd: number, length: number, position: number | null, encoding: string, cb?: BFSThreeArgCallback<string, number>): void
  • read(fd: number, buffer: Buffer, offset: number, length: number, position: number | null, cb?: BFSThreeArgCallback<number, Buffer>): void
  • Read data from the file specified by fd.

    Parameters

    • fd: number
    • length: number

      An integer specifying the number of bytes to read.

    • position: number | null

      An integer specifying where to begin reading from in the file. If position is null, data will be read from the current file position.

    • encoding: string
    • Optional cb: BFSThreeArgCallback<string, number>

    Returns void

  • Parameters

    • fd: number
    • buffer: Buffer
    • offset: number
    • length: number
    • position: number | null
    • Optional cb: BFSThreeArgCallback<number, Buffer>

    Returns void

readFile

  • readFile(filename: string, cb: BFSCallback<Buffer>): void
  • readFile(filename: string, options: object, callback?: BFSCallback<Buffer>): void
  • readFile(filename: string, options: object, callback?: BFSCallback<string>): void
  • readFile(filename: string, encoding: string, cb: BFSCallback<string>): void
  • Asynchronously reads the entire contents of a file.

    example

    Usage example fs.readFile('/etc/passwd', function (err, data) { if (err) throw err; console.log(data); });

    option

    options [String] encoding The string encoding for the file contents. Defaults to null.

    option

    options [String] flag Defaults to 'r'.

    Parameters

    Returns void

  • Parameters

    • filename: string
    • options: object
      • Optional flag?: string
    • Optional callback: BFSCallback<Buffer>

    Returns void

  • Parameters

    • filename: string
    • options: object
      • encoding: string
      • Optional flag?: string
    • Optional callback: BFSCallback<string>

    Returns void

  • Parameters

    • filename: string
    • encoding: string
    • cb: BFSCallback<string>

    Returns void

readFileSync

  • readFileSync(filename: string, options?: object): Buffer
  • readFileSync(filename: string, options: object): string
  • readFileSync(filename: string, encoding: string): string
  • Synchronously reads the entire contents of a file.

    option

    options [String] encoding The string encoding for the file contents. Defaults to null.

    option

    options [String] flag Defaults to 'r'.

    Parameters

    • filename: string
    • Optional options: object
      • Optional flag?: string

    Returns Buffer

  • Parameters

    • filename: string
    • options: object
      • encoding: string
      • Optional flag?: string

    Returns string

  • Parameters

    • filename: string
    • encoding: string

    Returns string

readSync

  • readSync(fd: number, length: number, position: number, encoding: string): string
  • readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number
  • Read data from the file specified by fd.

    Parameters

    • fd: number
    • length: number

      An integer specifying the number of bytes to read.

    • position: number

      An integer specifying where to begin reading from in the file. If position is null, data will be read from the current file position.

    • encoding: string

    Returns string

  • Parameters

    • fd: number
    • buffer: Buffer
    • offset: number
    • length: number
    • position: number

    Returns number

readdir

  • readdir(path: string, cb?: BFSCallback<string[]>): void
  • Asynchronous readdir. Reads the contents of a directory. The callback gets two arguments (err, files) where files is an array of the names of the files in the directory excluding '.' and '..'.

    Parameters

    • path: string
    • Default value cb: BFSCallback<string[]> = nopCb

    Returns void

readdirSync

  • readdirSync(path: string): string[]
  • Synchronous readdir. Reads the contents of a directory.

    Parameters

    • path: string

    Returns string[]

readlink

  • readlink(path: string, cb?: BFSCallback<string>): void
  • Asynchronous readlink.

    Parameters

    • path: string
    • Default value cb: BFSCallback<string> = nopCb

    Returns void

readlinkSync

  • readlinkSync(path: string): string
  • Synchronous readlink.

    Parameters

    • path: string

    Returns string

realpath

  • realpath(path: string, cb?: BFSCallback<string>): void
  • realpath(path: string, cache: object, cb: BFSCallback<string>): void
  • Asynchronous realpath. The callback gets two arguments (err, resolvedPath). May use process.cwd to resolve relative paths.

    example

    Usage example let cache = {'/etc':'/private/etc'}; fs.realpath('/etc/passwd', cache, function (err, resolvedPath) { if (err) throw err; console.log(resolvedPath); });

    Parameters

    Returns void

  • Parameters

    • path: string
    • cache: object
      • [path: string]: string
    • cb: BFSCallback<string>

    Returns void

realpathSync

  • realpathSync(path: string, cache?: object): string
  • Synchronous realpath.

    Parameters

    • path: string
    • Default value cache: object = {}

      An object literal of mapped paths that can be used to force a specific path resolution or avoid additional fs.stat calls for known real paths.

      • [path: string]: string

    Returns string

rename

  • Asynchronous rename. No arguments other than a possible exception are given to the completion callback.

    Parameters

    Returns void

renameSync

  • renameSync(oldPath: string, newPath: string): void
  • Synchronous rename.

    Parameters

    • oldPath: string
    • newPath: string

    Returns void

rmdir

  • Asynchronous rmdir.

    Parameters

    Returns void

rmdirSync

  • rmdirSync(path: string): void
  • Synchronous rmdir.

    Parameters

    • path: string

    Returns void

stat

  • Asynchronous stat.

    Parameters

    Returns void

statSync

  • statSync(path: string): Stats
  • Synchronous stat.

    Parameters

    • path: string

    Returns Stats

symlink

  • Asynchronous symlink.

    Parameters

    Returns void

  • Parameters

    • srcpath: string
    • dstpath: string
    • Optional type: string
    • Optional cb: BFSOneArgCallback

    Returns void

symlinkSync

  • symlinkSync(srcpath: string, dstpath: string, type?: string): void
  • Synchronous symlink.

    Parameters

    • srcpath: string
    • dstpath: string
    • Optional type: string

      can be either 'dir' or 'file' (default is 'file')

    Returns void

truncate

  • Asynchronous truncate.

    Parameters

    Returns void

  • Parameters

    Returns void

truncateSync

  • truncateSync(path: string, len?: number): void
  • Synchronous truncate.

    Parameters

    • path: string
    • Default value len: number = 0

    Returns void

unlink

  • Asynchronous unlink.

    Parameters

    Returns void

unlinkSync

  • unlinkSync(path: string): void
  • Synchronous unlink.

    Parameters

    • path: string

    Returns void

unwatchFile

  • unwatchFile(filename: string, listener?: function): void
  • Parameters

    • filename: string
    • Default value listener: function = nopCb

    Returns void

utimes

  • utimes(path: string, atime: number | Date, mtime: number | Date, cb?: BFSOneArgCallback): void
  • Change file timestamps of the file referenced by the supplied path.

    Parameters

    • path: string
    • atime: number | Date
    • mtime: number | Date
    • Default value cb: BFSOneArgCallback = nopCb

    Returns void

utimesSync

  • utimesSync(path: string, atime: number | Date, mtime: number | Date): void
  • Change file timestamps of the file referenced by the supplied path.

    Parameters

    • path: string
    • atime: number | Date
    • mtime: number | Date

    Returns void

watch

  • watch(filename: string, listener?: function): FSWatcher
  • watch(filename: string, options: object, listener?: function): FSWatcher
  • Parameters

    • filename: string
    • Optional listener: function
        • (event: string, filename: string): any
        • Parameters

          • event: string
          • filename: string

          Returns any

    Returns FSWatcher

  • Parameters

    • filename: string
    • options: object
      • Optional persistent?: boolean
    • Optional listener: function
        • (event: string, filename: string): any
        • Parameters

          • event: string
          • filename: string

          Returns any

    Returns FSWatcher

watchFile

  • watchFile(filename: string, listener: function): void
  • watchFile(filename: string, options: object, listener: function): void
  • Parameters

    • filename: string
    • listener: function

    Returns void

  • Parameters

    • filename: string
    • options: object
      • Optional interval?: number
      • Optional persistent?: boolean
    • listener: function

    Returns void

wrapCallbacks

  • wrapCallbacks(cbWrapper: function): void
  • For unit testing. Passes all incoming callbacks to cbWrapper for wrapping.

    Parameters

    • cbWrapper: function
        • (cb: Function, args: number): Function
        • Parameters

          • cb: Function
          • args: number

          Returns Function

    Returns void

write

  • write(fd: number, buffer: Buffer, offset: number, length: number, cb?: BFSThreeArgCallback<number, Buffer>): void
  • write(fd: number, buffer: Buffer, offset: number, length: number, position: number | null, cb?: BFSThreeArgCallback<number, Buffer>): void
  • write(fd: number, data: any, cb?: BFSThreeArgCallback<number, string>): void
  • write(fd: number, data: any, position: number | null, cb?: BFSThreeArgCallback<number, string>): void
  • write(fd: number, data: any, position: number | null, encoding: string, cb?: BFSThreeArgCallback<number, string>): void
  • Write buffer to the file specified by fd. Note that it is unsafe to use fs.write multiple times on the same file without waiting for the callback.

    Parameters

    • fd: number
    • buffer: Buffer

      Buffer containing the data to write to the file.

    • offset: number

      Offset in the buffer to start reading data from.

    • length: number

      The amount of bytes to write to the file.

    • Optional cb: BFSThreeArgCallback<number, Buffer>

    Returns void

  • Parameters

    • fd: number
    • buffer: Buffer
    • offset: number
    • length: number
    • position: number | null
    • Optional cb: BFSThreeArgCallback<number, Buffer>

    Returns void

  • Parameters

    Returns void

  • Parameters

    • fd: number
    • data: any
    • position: number | null
    • Optional cb: BFSThreeArgCallback<number, string>

    Returns void

  • Parameters

    • fd: number
    • data: any
    • position: number | null
    • encoding: string
    • Optional cb: BFSThreeArgCallback<number, string>

    Returns void

writeFile

  • Asynchronously writes data to a file, replacing the file if it already exists.

    The encoding option is ignored if data is a buffer.

    example

    Usage example fs.writeFile('message.txt', 'Hello Node', function (err) { if (err) throw err; console.log('It\'s saved!'); });

    option

    options [String] encoding Defaults to 'utf8'.

    option

    options [Number] mode Defaults to 0644.

    option

    options [String] flag Defaults to 'w'.

    Parameters

    Returns void

  • Parameters

    • filename: string
    • data: any
    • Optional encoding: string
    • Optional cb: BFSOneArgCallback

    Returns void

  • Parameters

    • filename: string
    • data: any
    • Optional options: object
      • Optional encoding?: string
      • Optional flag?: string
      • Optional mode?: string | number
    • Optional cb: BFSOneArgCallback

    Returns void

writeFileSync

  • writeFileSync(filename: string, data: any, options?: object): void
  • writeFileSync(filename: string, data: any, encoding?: string): void
  • Synchronously writes data to a file, replacing the file if it already exists.

    The encoding option is ignored if data is a buffer.

    option

    options [String] encoding Defaults to 'utf8'.

    option

    options [Number] mode Defaults to 0644.

    option

    options [String] flag Defaults to 'w'.

    Parameters

    • filename: string
    • data: any
    • Optional options: object
      • Optional encoding?: string
      • Optional flag?: string
      • Optional mode?: number | string

    Returns void

  • Parameters

    • filename: string
    • data: any
    • Optional encoding: string

    Returns void

writeSync

  • writeSync(fd: number, buffer: Buffer, offset: number, length: number, position?: number | null): number
  • writeSync(fd: number, data: string, position?: number | null, encoding?: string): number
  • Write buffer to the file specified by fd. Note that it is unsafe to use fs.write multiple times on the same file without waiting for it to return.

    Parameters

    • fd: number
    • buffer: Buffer

      Buffer containing the data to write to the file.

    • offset: number

      Offset in the buffer to start reading data from.

    • length: number

      The amount of bytes to write to the file.

    • Optional position: number | null

      Offset from the beginning of the file where this data should be written. If position is null, the data will be written at the current position.

    Returns number

  • Parameters

    • fd: number
    • data: string
    • Optional position: number | null
    • Optional encoding: string

    Returns number

Generated using TypeDoc