# fs

A Node.js-compatible implementation of the core fs module

Availability
8.3.0
8.3.0
9.2.0
Extends
Object

NOTE

This is an abstract type. Any object of this structure can be used where this type is used.

# Overview

Titanium provides a number of shims and ports of core Node.js module functionality.

This module is intended to provide a Node-compatible port of the fs core module.

More details on the Node.js API can be found in their fs module documentation (opens new window)

The fs module enables interacting with the file system in a way modeled on standard POSIX functions.

To use this module:

const fs = require('fs');

All file system operations have synchronous and asynchronouse callback forms.

NOTE: The Titanium shim for this module does not support the new Promises API yet, nor does it support some of the newer (and a subset of older) APIs.

Some of the APIs are implemented as no-ops:

  • chmod
  • chmodSync
  • chown
  • chownSync
  • fchmod
  • fchmodSync
  • fchown
  • fchownSync
  • fdatasync
  • fdatasyncSync
  • symlink
  • symlinkSync
  • unwatchFile
  • utimes
  • utimesSync
  • watch
  • watchFile

Explicitly unsupported for now are:

  • fs.createReadStream
  • fs.createWriteStream
  • fs.fsync(fd, callback)
  • fs.fsyncSync(fd)
  • fs.ftruncate(fd[, len], callback)
  • fs.ftruncateSync(fd[, len])
  • fs.futimes(fd, atime, mtime, callback)
  • fs.futimesSync(fd, atime, mtime)
  • fs.lchmod(path, mode, callback)
  • fs.lchmodSync(path, mode)
  • fs.lchown(path, uid, gid, callback)
  • fs.lchownSync(path, uid, gid)
  • fs.link(existingPath, newPath, callback)
  • fs.linkSync(existingPath, newPath)
  • fs.opendir
  • fs.opendirSync
  • fs.readlink(path[, options], callback)
  • fs.readlinkSync(path[, options])
  • fs.rm
  • fs.rmSync

# Properties

# constants

Availability
8.3.0
8.3.0
9.2.0
constants :fs.constants

Returns an object containing commonly used constants for file system operations. The specific constants currently defined are described in fs.constants.


# ReadStream

Availability
8.3.0
8.3.0
9.2.0
ReadStream :fs.ReadStream

The class fs.ReadStream


# Stats

Availability
8.3.0
8.3.0
9.2.0
Stats :fs.Stats

The class fs.Stats


# WriteStream

Availability
8.3.0
8.3.0
9.2.0
WriteStream :fs.WriteStream

The class fs.WriteStream

# Methods

# access

Availability
8.3.0
8.3.0
9.2.0
access(path[, mode, callback]) void

Tests a user's permissions for the file or directory specified by path. The mode argument is an optional integer that specifies the accessibility checks to be performed. Check File access constants for possible values of mode. It is possible to create a mask consisting of the bitwise OR of two or more values (e.g. fs.constants.W_OK | fs.constants.R_OK).

Parameters

Name Type Description
path String | buffer.Buffer

filepath

mode Number

mode/permissions to check

callback Function<Error>

typical async callback function

Returns

Type
void

# accessSync

Availability
8.3.0
8.3.0
9.2.0
accessSync(path[, mode]) void

Synchronously tests a user's permissions for the file or directory specified by path. The mode argument is an optional integer that specifies the accessibility checks to be performed. Check File access constants for possible values of mode. It is possible to create a mask consisting of the bitwise OR of two or more values (e.g. fs.constants.W_OK | fs.constants.R_OK).

Parameters

Name Type Description
path String | buffer.Buffer

filepath

mode Number

mode/permissions to check

Returns

Type
void

# appendFile

Availability
8.3.0
8.3.0
9.2.0
appendFile(path, data[, options, callback]) void

Asynchronously append data to a file, creating the file if it does not yet exist. data can be a string or a buffer.Buffer.

Parameters

Name Type Description
path String | buffer.Buffer | Number

filepath or file descriptor

data String | buffer.Buffer

data to append

options fs.appendFile.options | String

options

callback Function<Error>

typical async callback function

Returns

Type
void

# appendFileSync

Availability
8.3.0
8.3.0
9.2.0
appendFileSync(path, data[, options]) void

Synchronously append data to a file, creating the file if it does not yet exist. data can be a string or a buffer.Buffer.

Parameters

Name Type Description
path String | buffer.Buffer | Number

filepath or file descriptor

data String | buffer.Buffer

data to append

options fs.appendFile.options | String

options

Returns

Type
void

# chmod

Availability
8.3.0
8.3.0
9.2.0
chmod(path, mode, callback) void

Asynchronously changes the permissions of a file. No arguments other than a possible exception are given to the completion callback.

This is a no-op on Titanium.

Parameters

Name Type Description
path String | buffer.Buffer

filepath

mode String | Number

new mode/permissions

callback Function<Error>

typical async callback function

Returns

Type
void

# chmodSync

Availability
8.3.0
8.3.0
9.2.0
chmodSync(path, mode) void

Synchronously changes the permissions of a file.

This is a no-op on Titanium.

Parameters

Name Type Description
path String | buffer.Buffer

filepath

mode String | Number

new mode/permissions

Returns

Type
void

# chown

Availability
8.3.0
8.3.0
9.2.0
chown(path, uid, gid, callback) void

Asynchronously changes owner and group of a file. No arguments other than a possible exception are given to the completion callback.

This is a no-op on Titanium.

Parameters

Name Type Description
path String | buffer.Buffer

filepath

uid Number

new owner

gid Number

new group

callback Function<Error>

typical async callback function

Returns

Type
void

# chownSync

Availability
8.3.0
8.3.0
9.2.0
chownSync(path, uid, gid) void

Synchronously changes owner and group of a file.

This is a no-op on Titanium.

Parameters

Name Type Description
path String | buffer.Buffer

filepath

uid Number

new owner

gid Number

new group

Returns

Type
void

# close

Availability
8.3.0
8.3.0
9.2.0
close(fd, callback) void

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

Calling fs.close() on any file descriptor (fd) that is currently in use through any other fs operation may lead to undefined behavior.

Parameters

Name Type Description
fd Number

file descriptor

callback Function<Error>

typical async callback function

Returns

Type
void

# closeSync

Availability
8.3.0
8.3.0
9.2.0
closeSync(fd) void

Synchronous close.

Calling fs.close() on any file descriptor (fd) that is currently in use through any other fs operation may lead to undefined behavior.

Parameters

Name Type Description
fd Number

file descriptor

Returns

Type
void

# copyFile

Availability
8.3.0
8.3.0
9.2.0
copyFile(src, dest[, mode, callback]) void

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.

mode is an optional integer that specifies the behavior of the copy operation. It is possible to create a mask consisting of the bitwise OR of two or more values (e.g. fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE).

  • fs.constants.COPYFILE_EXCL: The copy operation will fail if dest already exists.
  • fs.constants.COPYFILE_FICLONE: The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write, then a fallback copy mechanism is used.
  • fs.constants.COPYFILE_FICLONE_FORCE: The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write, then the operation will fail.

Parameters

Name Type Description
src String

source filename to copy

dest String

destination filename of the copy operation

mode Number

modifiers for copy operation.

callback Function<Error>

typical async callback function

Returns

Type
void

# copyFileSync

Availability
8.3.0
8.3.0
9.2.0
copyFileSync(src, dest[, mode]) void

Synchronously copies src to dest. By default, dest is overwritten if it already exists. 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.

mode is an optional integer that specifies the behavior of the copy operation. It is possible to create a mask consisting of the bitwise OR of two or more values (e.g. fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE).

  • fs.constants.COPYFILE_EXCL: The copy operation will fail if dest already exists.
  • fs.constants.COPYFILE_FICLONE: The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write, then a fallback copy mechanism is used.
  • fs.constants.COPYFILE_FICLONE_FORCE: The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write, then the operation will fail.

Parameters

Name Type Description
src String

source filename to copy

dest String

destination filename of the copy operation

mode Number

modifiers for copy operation.

Returns

Type
void

# exists

Availability
8.3.0
8.3.0
9.2.0
exists(path, callback) void

Test whether or not the given path exists by checking with the file system.

Parameters

Name Type Description
path String | buffer.Buffer

file path

callback Function<Boolean>

atypical async callback function that received the result as a single boolean arguments

Returns

Type
void

# existsSync(path)

Availability
8.3.0
8.3.0
9.2.0
existsSync(path)(path) Boolean

Test whether or not the given path exists by checking with the file system.

Parameters

Name Type Description
path String | buffer.Buffer

file path

Returns

Type
Boolean

# fchmod

Availability
8.3.0
8.3.0
9.2.0
fchmod(fd, mode, callback) void

Asynchronous fchmod.

This is a no-op on Titanium.

Parameters

Name Type Description
fd Number

file descriptor

mode String | Number

new mode/permissions

callback Function<Error>

typical async callback function

Returns

Type
void

# fchmodSync

Availability
8.3.0
8.3.0
9.2.0
fchmodSync(fd, mode) void

Synchronous fchmod.

This is a no-op on Titanium.

Parameters

Name Type Description
fd Number

file descriptor

mode String | Number

new mode/permissions

Returns

Type
void

# fchown

Availability
8.3.0
8.3.0
9.2.0
fchown(fd, uid, gid, callback) void

Asynchronous fchown.

This is a no-op on Titanium.

Parameters

Name Type Description
fd Number

file descriptor

uid Number

new owner

gid Number

new group

callback Function<Error>

typical async callback function

Returns

Type
void

# fchownSync

Availability
8.3.0
8.3.0
9.2.0
fchownSync(fd, uid, gid) void

Synchronous fchown.

This is a no-op on Titanium.

Parameters

Name Type Description
fd Number

file descriptor

uid Number

new owner

gid Number

new group

Returns

Type
void

# fdatasync

Availability
8.3.0
8.3.0
9.2.0
fdatasync(fd, callback) void

Asynchronous fdatasync.

This is a no-op on Titanium.

Parameters

Name Type Description
fd Number

file descriptor

callback Function<Error>

typical async callback function

Returns

Type
void

# fdatasyncSync

Availability
8.3.0
8.3.0
9.2.0
fdatasyncSync(fd) void

Synchronous fdatasync.

This is a no-op on Titanium.

Parameters

Name Type Description
fd Number

file descriptor

Returns

Type
void

# fstat

Availability
8.3.0
8.3.0
9.2.0
fstat(fd[, options, callback]) void

Asynchronous fstat. The callback gets two arguments (err, stats) where stats is an fs.Stats object. fstat() is identical to stat(), except that the file to be stat-ed is specified by the file descriptor fd.

Parameters

Name Type Description
fd Number

file descriptor

options fs.stat.options

options

callback Function<Error, fs.Stats>

typical async callback function

Returns

Type
void

# fstatSync

Availability
8.3.0
8.3.0
9.2.0
fstatSync(fd[, options]) fs.Stats

Synchronous fstat.

Parameters

Name Type Description
fd Number

file descriptor

options fs.stat.options

options

Returns

Type
fs.Stats

# lstat

Availability
8.3.0
8.3.0
9.2.0
lstat(path[, options, callback]) void

Asynchronous lstat.

Parameters

Name Type Description
path String | buffer.Buffer

file path

options fs.stat.options

options

callback Function<Error, fs.Stats>

typical async callback function

Returns

Type
void

# lstatSync

Availability
8.3.0
8.3.0
9.2.0
lstatSync(path[, options]) fs.Stats

Synchronous lstat.

Parameters

Name Type Description
path String | buffer.Buffer

file path

options fs.stat.options

options

Returns

Type
fs.Stats

# mkdir

Availability
8.3.0
8.3.0
9.2.0
mkdir(path[, options, callback]) void

Asynchronously creates a directory.

The callback is given a possible exception and, if recursive is true, the first directory path created, (err, [path]).

The optional options argument can be an integer specifying mode (permission and sticky bits), or an object with a mode property and a recursive property indicating whether parent directories should be created. Calling fs.mkdir() when path is a directory that exists results in an error only when recursive is false.

Parameters

Name Type Description
path String | buffer.Buffer

file path

options fs.mkdir.options

options

callback Function<Error, String>

typical async callback function. The second argument is an optional path string.

Returns

Type
void

# mkdirSync

Availability
8.3.0
8.3.0
9.2.0
mkdirSync(path[, options]) String

Synchronously creates a directory. Returns undefined, or if recursive istrue, the first directory path created. This is the synchronous version offs.mkdir()`.

Parameters

Name Type Description
path String | buffer.Buffer

file path

options fs.mkdir.options

options

Returns

will return undefined if recursive option is not true

Type
String

# mkdtemp

Availability
8.3.0
8.3.0
9.2.0
mkdtemp(prefix[, options, callback]) void

Creates a unique temporary directory.

Generates six random characters to be appended behind a required prefix to create a unique temporary directory. Due to platform inconsistencies, avoid trailing X characters in prefix. Some platforms, notably the BSDs, can return more than six random characters, and replace trailing X characters in prefix with random characters.

The created directory path is passed as a string to the callback's second parameter.

The optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use.

Parameters

Name Type Description
prefix String

file prefix

options String | fs.mkdtemp.options

encoding if string

callback Function<Error, String>

typical async callback function. The second argument is the generated path string.

Returns

Type
void

# mkdtempSync

Availability
8.3.0
8.3.0
9.2.0
mkdtempSync(prefix[, options]) String

For detailed information, see the documentation of the asynchronous version of this API: mkdtemp.

The optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use.

Parameters

Name Type Description
prefix String

file prefix

options String | fs.mkdtemp.options

encoding if string

Returns

Returns the created directory path.

Type
String

# open

Availability
8.3.0
8.3.0
9.2.0
open(path[, flags[, mode, callback]]) void

Asynchronous file open. See open(2).

mode sets the file mode (permission and sticky bits), but only if the file was created. On Windows, only the write permission can be manipulated; see fs.chmod().

The callback gets two arguments (err, fd).

Parameters

Name Type Description
path String | buffer.Buffer

file path

flags String | Number

file system flags

mode Number | String

file permissions

callback Function<Error, Number>

typical async callback function, the second argument is an integer representing a file descriptor

Returns

Type
void

# openSync

Availability
8.3.0
8.3.0
9.2.0
openSync(path[, flags[, mode]]) Number

For detailed information, see the documentation of the asynchronous version of this API: fs.open().

Parameters

Name Type Description
path String | buffer.Buffer

file path

flags String | Number

file system flags

mode Number | String

file permissions

Returns

Returns an integer representing the file descriptor.

Type
Number

# read

Availability
8.3.0
8.3.0
9.2.0
read(fd, buffer, offset, length, position, callback) void

Read data from the file specified by fd.

buffer is the buffer that the data (read from the fd) will be written to.

offset is the offset in the buffer to start writing at.

length is an integer specifying the number of bytes to read.

position is an argument specifying where to begin reading from in the file. If position is null, data will be read from the current file position, and the file position will be updated. If position is an integer, the file position will remain unchanged.

The callback is given the three arguments, (err, bytesRead, buffer).

If the file is not modified concurrently, the end-of-file is reached when the number of bytes read is zero.

Parameters

Name Type Description
fd Number

file descriptor

buffer buffer.Buffer | Titanium.Buffer

buffer to read

offset Number

the offset in the buffer to start writing at.

length Number

integer specifying the number of bytes to read.

position Number

where to begin reading from in the file. Unused/unsupported in Titanium.

callback Function<Error, Number, buffer.Buffer>

async callback function

Returns

Type
void

# readdir

Availability
8.3.0
8.3.0
9.2.0
readdir(path[, options, callback]) 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 '..'.

The optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use for the filenames passed to the callback. If the encoding is set to 'buffer', the filenames returned will be passed as Buffer objects.

If options.withFileTypes is set to true, the files array will contain fs.Dirent objects. NOTE: Titanium does not yet support this.

Parameters

Name Type Description
path String | buffer.Buffer

file path

options fs.readdir.options

options

callback Function<Error, Array<String>>

Typical async callback function. The second argument is an array of results which may be Strings, buffer.Buffers, or fs.Dirents

Returns

Type
void

# readdirSync

Availability
8.3.0
8.3.0
9.2.0
readdirSync(path[, options]) Array<String> | Array<buffer.Buffer> | Array<fs.Dirent>

Synchronous readdir.

The optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use for the filenames returned. If the encoding is set to 'buffer', the filenames returned will be passed as Buffer objects.

If options.withFileTypes is set to true, the result will contain fs.Dirent objects. Note: Titanium does not yet support this.

Parameters

Name Type Description
path String | buffer.Buffer

file path

options fs.readdir.options

options

Returns

an array of results which may be Strings, buffer.Buffers, or fs.Dirents

Type
Array<String> | Array<buffer.Buffer> | Array<fs.Dirent>

# readFile

Availability
8.3.0
8.3.0
9.2.0
readFile(path[, options, callback]) void

Asynchronously reads the entire contents of a file.

Parameters

Name Type Description
path String | buffer.Buffer

file path

options fs.readFile.options | String

encoding string, or an options object

callback Function<Error, String>

typical async callback function, the second argument is either a string or a buffer.Buffer

Returns

Type
void

# readFileSync

Availability
8.3.0
8.3.0
9.2.0
readFileSync(path[, options]) String | buffer.Buffer

Synchronously reads the entire contents of a file.

Parameters

Name Type Description
path String | buffer.Buffer

file path

options fs.readFile.options | String

encoding string, or an options object

Returns

either a string or a buffer.Buffer, based upon options.encoding

Type
String | buffer.Buffer

# readSync

Availability
8.3.0
8.3.0
9.2.0
readSync(fd, buffer, offset, length[, position]) Number

For detailed information, see the documentation of the asynchronous version of this API: fs.read().

Parameters

Name Type Description
fd Number

file descriptor

buffer buffer.Buffer | Titanium.Buffer

buffer to read

offset Number

the offset in the buffer to start writing at.

length Number

integer specifying the number of bytes to read.

position Number

where to begin reading from in the file. Unused/unsupported in Titanium.

Returns

Returns the number of bytesRead.

Type
Number

# realpath

Availability
8.3.0
8.3.0
9.2.0
realpath(path[, options, callback]) void

Asynchronously computes the canonical pathname by resolving ., .. and symbolic links.

A canonical pathname is not necessarily unique. Hard links and bind mounts can expose a file system entity through many pathnames.

Parameters

Name Type Description
path String | buffer.Buffer

file path

options Object

options

callback Function<Error, String>

typical async callback function

Returns

Type
void

# realpath.native

Availability
8.3.0
8.3.0
9.2.0
realpath.native(path[, options, callback]) void

Asynchronous realpath.

The callback gets two arguments (err, resolvedPath).

Only paths that can be converted to UTF8 strings are supported.

The optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use for the path passed to the callback. If the encoding is set to 'buffer', the path returned will be passed as a Buffer object.

Parameters

Name Type Description
path String | buffer.Buffer

file path

options Object

options

callback Function<Error, String>

typical async callback function

Returns

Type
void

# realpathSync

Availability
8.3.0
8.3.0
9.2.0
realpathSync(path[, options]) String

Returns the resolved pathname.

For detailed information, see the documentation of the asynchronous version of this API: fs.realpath().

Parameters

Name Type Description
path String | buffer.Buffer

file path

options Object

options

Returns

Type
String

# realpathSync.native

Availability
8.3.0
8.3.0
9.2.0
realpathSync.native(path[, options]) String

Synchronous realpath.

Only paths that can be converted to UTF8 strings are supported.

Parameters

Name Type Description
path String | buffer.Buffer

file path

options Object

options

Returns

Type
String

# rename

Availability
8.3.0
8.3.0
9.2.0
rename(oldPath, newPath, callback) void

Asynchronously rename file at oldPath to the pathname provided as newPath. In the case that newPath already exists, it will be overwritten. If there is a directory at newPath, an error will be raised instead. No arguments other than a possible exception are given to the completion callback.

Parameters

Name Type Description
oldPath String | buffer.Buffer

source file path

newPath String | buffer.Buffer

destination file path

callback Function<Error>

typical async callback function

Returns

Type
void

# renameSync

Availability
8.3.0
8.3.0
9.2.0
renameSync(oldPath, newPath) void

Synchronous rename. Returns undefined.

Parameters

Name Type Description
oldPath String | buffer.Buffer

source file path

newPath String | buffer.Buffer

destination file path

Returns

Type
void

# rmdir

Availability
8.3.0
8.3.0
9.2.0
rmdir(path[, options, callback]) void

Asynchronous rmdir

Parameters

Name Type Description
path String | buffer.Buffer

file path

options fs.rmDir.options

options

callback Function<Error>

typical async callback function

Returns

Type
void

# rmSync

Availability
8.3.0
8.3.0
9.2.0
rmSync(path[, options]) void

Synchronously removes files and directories (modeled on the standard POSIX rm utility). Returns undefined.

Parameters

Name Type Description
path String | buffer.Buffer

file path

options fs.rm.options

options

Returns

Type
void

# stat

Availability
8.3.0
8.3.0
9.2.0
stat(path[, options, callback]) void

Asynchronous stat. The callback gets two arguments (err, stats) where stats is an fs.Stats object.

In case of an error, the err.code will be one of Common System Errors.

Using fs.stat() to check for the existence of a file before calling fs.open(), fs.readFile() or fs.writeFile() is not recommended. Instead, user code should open/read/write the file directly and handle the error raised if the file is not available.

To check if a file exists without manipulating it afterwards, fs.access() is recommended.

Parameters

Name Type Description
path String | buffer.Buffer

file path

options Object

fs.stat.options

callback Function<Error, fs.Stats>

typical async callback function

Returns

Type
void

# statSync

Availability
8.3.0
8.3.0
9.2.0
statSync(path[, options]) fs.Stats

Synchronous stat.

Parameters

Name Type Description
path String | buffer.Buffer

file path

options fs.stat.options

options

Returns

Type
fs.Stats

Availability
8.3.0
8.3.0
9.2.0
symlink(target, path, callback) void

Asynchronous symlink which creates the link called path pointing to target. No arguments other than a possible exception are given to the completion callback.

This is a no-op on Titanium.

Parameters

Name Type Description
target String | buffer.Buffer

target of the new symlink

path String | buffer.Buffer

the symlink path

callback Function<Error>

typical async callback function

Returns

Type
void

# symlinkSync

Availability
8.3.0
8.3.0
9.2.0
symlinkSync(target, path) void

Synchronous symlink which creates the link called path pointing to target. No arguments other than a possible exception are given to the completion callback.

This is a no-op on Titanium.

Parameters

Name Type Description
target String | buffer.Buffer

target of the new symlink

path String | buffer.Buffer

the symlink path

Returns

Type
void

# truncate

Availability
8.3.0
8.3.0
9.2.0
truncate(path[, len, callback]) void

Asynchronous truncate. Returns undefined. A file descriptor can also be passed as the first argument. In this case, fs.ftruncateSync() is called.

Parameters

Name Type Description
path String | buffer.Buffer

file path

len Number

target length to truncate to

callback Function<Error>

typical async callback function

Returns

Type
void

# truncateSync

Availability
8.3.0
8.3.0
9.2.0
truncateSync(path[, len]) void

Synchronous truncate. Returns undefined. A file descriptor can also be passed as the first argument. In this case, fs.ftruncateSync() is called.

Parameters

Name Type Description
path String | buffer.Buffer

file path

len Number

target length to truncate to

Returns

Type
void

Availability
8.3.0
8.3.0
9.2.0
unlink(path, callback) void

Asynchronous unlink. Returns undefined.

Parameters

Name Type Description
path String | buffer.Buffer

file path

callback Function<Error>

typical async callback function

Returns

Type
void

# unlinkSync

Availability
8.3.0
8.3.0
9.2.0
unlinkSync(path) void

Synchronous unlink. Returns undefined.

Parameters

Name Type Description
path String | buffer.Buffer

file path

Returns

Type
void

# unwatchFile

Availability
8.3.0
8.3.0
9.2.0
unwatchFile(filename[, listener]) void

Stop watching for changes on filename. If listener is specified, only that particular listener is removed. Otherwise, all listeners are removed, effectively stopping watching of filename.

This is a no-op on Titanium.

Parameters

Name Type Description
filename String | buffer.Buffer

file path

listener Function

callback function when file changes

Returns

Type
void

# utimes

Availability
8.3.0
8.3.0
9.2.0
utimes(path, atime, mtime, callback) void

Change the file system timestamps of the object referenced by path.

This is a no-op on Titanium.

Parameters

Name Type Description
path String | buffer.Buffer

file path

atime Number | String | Date

access time

mtime Number | String | Date

modification time

callback Function<Error>

typical async callback function

Returns

Type
void

# utimesSync

Availability
8.3.0
8.3.0
9.2.0
utimesSync(path, atime, mtime) void

Change the file system timestamps of the object referenced by path.

This is a no-op on Titanium.

Parameters

Name Type Description
path String | buffer.Buffer

file path

atime Number | String | Date

access time

mtime Number | String | Date

modification time

Returns

Type
void

# watch

Availability
8.3.0
8.3.0
9.2.0
watch(filename[, options[, listener]]) void

Watch for changes on filename, where filename is either a file or a directory.

This is a no-op on Titanium.

Parameters

Name Type Description
filename String | buffer.Buffer

file path

options Object

options

listener Function

callback function when file changes

Returns

Type
void

# watchFile

Availability
8.3.0
8.3.0
9.2.0
watchFile(filename[, options, listener]) void

Watch for changes on filename. The callback listener will be called each time the file is accessed.

This is a no-op on Titanium.

Parameters

Name Type Description
filename String | buffer.Buffer

file path

options Object

options

listener Function

callback function when file changes

Returns

Type
void

# write

Availability
8.3.0
8.3.0
9.2.0
write(fd, buffer[, offset[, length[, position, callback]]]) void

For detailed information, see the documentation of the asynchronous version of this API.

Parameters

Name Type Description
fd Number

file descriptor

buffer String | buffer.Buffer

buffer contents to write

offset Number

from the beginning of the file where this data should be written

length String | Number

length in bytes of Buffer; or string character encoding

position Number

offset from the beginning of the file where this data should be written (if data to be written is a Buffer)

callback Function<Error>

typical async callback function

Returns

Type
void

# writeFile

Availability
8.3.0
8.3.0
9.2.0
writeFile(file, data[, options, callback]) void

When file is a filename, asynchronously writes data to the file, replacing the file if it already exists. data can be a string or a buffer.

When file is a file descriptor, the behavior is similar to calling fs.write() directly (which is recommended). See the notes below on using a file descriptor.

The encoding option is ignored if data is a buffer. If data is a normal object, it must have an own toString function property.

Parameters

Name Type Description
file String | buffer.Buffer | Number

filename or file descriptor

data String | buffer.Buffer | Object

data to write

options fs.writeFile.options

from the beginning of the file where this data should be written

callback Function<Error>

typical async callback function

Returns

Type
void

# writeFileSync

Availability
8.3.0
8.3.0
9.2.0
writeFileSync(file, data[, options]) void

For detailed information, see the documentation of the asynchronous version of this API: fs.writeFile().

Parameters

Name Type Description
file String | buffer.Buffer | Number

filename or file descriptor

data String | buffer.Buffer | Object

data to write

options fs.writeFile.options

from the beginning of the file where this data should be written

Returns

Type
void

# writeSync

Availability
8.3.0
8.3.0
9.2.0
writeSync(fd, buffer[, offset[, length[, position]]]) Number

For detailed information, see the documentation of the asynchronous version of this API.

Parameters

Name Type Description
fd Number

file descriptor

buffer String | buffer.Buffer

buffer contents to write

offset Number

from the beginning of the file where this data should be written

length String | Number

length in bytes of Buffer; or string character encoding

position Number

offset from the beginning of the file where this data should be written (if data to be written is a Buffer)

Returns

bytes written

Type
Number