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

accessSync

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

appendFile

  • appendFile(filename: string, data: any, cb?: BFSOneArgCallback): void
  • appendFile(filename: string, data: any, options?: undefined | object, cb?: BFSOneArgCallback): void
  • appendFile(filename: string, data: any, encoding?: undefined | string, cb?: BFSOneArgCallback): 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

    Returns void

  • Parameters

    • filename: string
    • data: any
    • Optional options: undefined | object
    • Optional cb: BFSOneArgCallback

    Returns void

  • Parameters

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

    Returns void

appendFileSync

  • appendFileSync(filename: string, data: any, options?: undefined | object): void
  • appendFileSync(filename: string, data: any, encoding?: undefined | 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: undefined | object

    Returns void

  • Parameters

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

    Returns void

changeFSModule

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

    Parameters

    • newFs: FS

    Returns void

chmod

chmodSync

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

    Parameters

    • path: string
    • mode: string | number

    Returns void

chown

chownSync

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

    Parameters

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

    Returns void

close

closeSync

  • closeSync(fd: number): void

createReadStream

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

createWriteStream

  • createWriteStream(path: string, options?: undefined | object): 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

fchmodSync

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

    Parameters

    • fd: number
    • mode: number | string

    Returns void

fchown

fchownSync

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

    Parameters

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

    Returns void

fdatasync

fdatasyncSync

  • fdatasyncSync(fd: number): 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

fsyncSync

  • fsyncSync(fd: number): void

ftruncate

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

lchmodSync

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

    Parameters

    • path: string
    • mode: number | string

    Returns void

lchown

lchownSync

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

    Parameters

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

    Returns void

link

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

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): void
  • open(path: string, flag: string, mode: number | string, cb?: BFSCallback): 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

    Returns void

  • Parameters

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

    Returns void

openSync

  • openSync(path: string, flag: string, mode?: number | string): number

read

  • read(fd: number, length: number, position: number | null, encoding: string, cb?: BFSThreeArgCallback): void
  • read(fd: number, buffer: Buffer, offset: number, length: number, position: number | null, cb?: BFSThreeArgCallback): 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

    Returns void

  • Parameters

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

    Returns void

readFile

  • readFile(filename: string, cb: BFSCallback): void
  • readFile(filename: string, options: object, callback: BFSCallback): void
  • readFile(filename: string, options: object, callback: BFSCallback): void
  • readFile(filename: string, encoding: string, cb?: BFSCallback): 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?: undefined | string
    • callback: BFSCallback

    Returns void

  • Parameters

    • filename: string
    • options: object
      • encoding: string
      • Optional flag?: undefined | string
    • callback: BFSCallback

    Returns void

  • Parameters

    • filename: string
    • encoding: string
    • Optional cb: BFSCallback

    Returns void

readFileSync

  • readFileSync(filename: string, options?: undefined | 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: undefined | object

    Returns Buffer

  • Parameters

    • filename: string
    • options: object
      • encoding: string
      • Optional flag?: undefined | 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

  • 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

    Returns void

readdirSync

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

    Parameters

    • path: string

    Returns string[]

readlink

readlinkSync

  • readlinkSync(path: string): string

realpath

  • 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

    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

rmdirSync

  • rmdirSync(path: string): void

stat

statSync

  • statSync(path: string): Stats

symlink

  • symlink(srcpath: string, dstpath: string, cb?: BFSOneArgCallback): void
  • symlink(srcpath: string, dstpath: string, type?: undefined | string, cb?: BFSOneArgCallback): void

symlinkSync

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

    Parameters

    • srcpath: string
    • dstpath: string
    • Optional type: undefined | string

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

    Returns void

truncate

truncateSync

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

    Parameters

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

    Returns void

unlink

unlinkSync

  • unlinkSync(path: string): void

unwatchFile

  • unwatchFile(filename: string, listener?: function): 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?: undefined | function): FSWatcher
  • watch(filename: string, options: object, listener?: undefined | function): FSWatcher
  • Parameters

    • filename: string
    • Optional listener: undefined | function

    Returns FSWatcher

  • Parameters

    • filename: string
    • options: object
      • Optional persistent?: undefined | true | false
    • Optional listener: undefined | function

    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?: undefined | number
      • Optional persistent?: undefined | true | false
    • 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 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

    Returns void

  • Parameters

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

    Returns void

  • Parameters

    Returns void

  • Parameters

    Returns void

  • Parameters

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

    Returns void

writeFile

  • writeFile(filename: string, data: any, cb?: BFSOneArgCallback): void
  • writeFile(filename: string, data: any, encoding?: undefined | string, cb?: BFSOneArgCallback): void
  • writeFile(filename: string, data: any, options?: undefined | object, cb?: BFSOneArgCallback): void
  • 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: undefined | string
    • Optional cb: BFSOneArgCallback

    Returns void

  • Parameters

    • filename: string
    • data: any
    • Optional options: undefined | object
    • Optional cb: BFSOneArgCallback

    Returns void

writeFileSync

  • writeFileSync(filename: string, data: any, options?: undefined | object): void
  • writeFileSync(filename: string, data: any, encoding?: undefined | 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: undefined | object

    Returns void

  • Parameters

    • filename: string
    • data: any
    • Optional encoding: undefined | 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?: undefined | 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: undefined | string

    Returns number

Generated using TypeDoc