# fs

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

- Source: https://titaniumsdk.com/docs/sdk/main/fs
- Titanium SDK version: main
- Kind: pseudo
- Platforms: Android, iPhone, iPad, macOS
- Since: Titanium SDK 8.3.0

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](https://nodejs.org/api/fs.html)

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

To use this module:

``` javascript
const fs = require('fs');
```

All file system operations have synchronous and asynchronous 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

- Type: fs.constants
- Platforms: Android, iPhone, iPad, macOS

Returns an object containing commonly used constants for file system operations. The specific constants currently defined are described in [FS constants](https://titaniumsdk.com/docs/sdk/fs.constants.md).

### ReadStream

- Type: fs.ReadStream
- Platforms: Android, iPhone, iPad, macOS

The class `fs.ReadStream`

### Stats

- Type: fs.Stats
- Platforms: Android, iPhone, iPad, macOS

The class `fs.Stats`

### WriteStream

- Type: fs.WriteStream
- Platforms: Android, iPhone, iPad, macOS

The class `fs.WriteStream`

## Methods

### access

- Platforms: Android, iPhone, iPad, macOS

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:

- `path` (String | buffer.Buffer): filepath
- `mode` (Number, optional): mode/permissions to check Default: `fs.constants.F_OK`.
- `callback` (Function<Error>): typical async callback function

### accessSync

- Platforms: Android, iPhone, iPad, macOS

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:

- `path` (String | buffer.Buffer): filepath
- `mode` (Number, optional): mode/permissions to check Default: `fs.constants.F_OK`.

### appendFile

- Platforms: Android, iPhone, iPad, macOS

Asynchronously append `data` to a file, creating the file if it does not yet exist. `data` can be a `string` or a [buffer.Buffer](https://titaniumsdk.com/docs/sdk/buffer.Buffer.md).

Parameters:

- `path` (String | buffer.Buffer | Number): filepath or file descriptor
- `data` (String | buffer.Buffer): data to append
- `options` (fs.appendFile.options | String, optional): options
- `callback` (Function<Error>): typical async callback function

### appendFileSync

- Platforms: Android, iPhone, iPad, macOS

Synchronously append `data` to a file, creating the file if it does not yet exist. `data` can be a `string` or a [buffer.Buffer](https://titaniumsdk.com/docs/sdk/buffer.Buffer.md).

Parameters:

- `path` (String | buffer.Buffer | Number): filepath or file descriptor
- `data` (String | buffer.Buffer): data to append
- `options` (fs.appendFile.options | String, optional): options

### chmod

- Platforms: Android, iPhone, iPad, macOS

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:

- `path` (String | buffer.Buffer): filepath
- `mode` (String | Number): new mode/permissions
- `callback` (Function<Error>): typical async callback function

### chmodSync

- Platforms: Android, iPhone, iPad, macOS

Synchronously changes the permissions of a file.

**This is a no-op on Titanium.**

Parameters:

- `path` (String | buffer.Buffer): filepath
- `mode` (String | Number): new mode/permissions

### chown

- Platforms: Android, iPhone, iPad, macOS

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:

- `path` (String | buffer.Buffer): filepath
- `uid` (Number): new owner
- `gid` (Number): new group
- `callback` (Function<Error>): typical async callback function

### chownSync

- Platforms: Android, iPhone, iPad, macOS

Synchronously changes owner and group of a file.

**This is a no-op on Titanium.**

Parameters:

- `path` (String | buffer.Buffer): filepath
- `uid` (Number): new owner
- `gid` (Number): new group

### close

- Platforms: Android, iPhone, iPad, macOS

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:

- `fd` (Number): file descriptor
- `callback` (Function<Error>): typical async callback function

### closeSync

- Platforms: Android, iPhone, iPad, macOS

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:

- `fd` (Number): file descriptor

### copyFile

- Platforms: Android, iPhone, iPad, macOS

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:

- `src` (String): source filename to copy
- `dest` (String): destination filename of the copy operation
- `mode` (Number, optional): modifiers for copy operation. Default: `0`.
- `callback` (Function<Error>): typical async callback function

### copyFileSync

- Platforms: Android, iPhone, iPad, macOS

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:

- `src` (String): source filename to copy
- `dest` (String): destination filename of the copy operation
- `mode` (Number, optional): modifiers for copy operation. Default: `0`.

### exists

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `path` (String | buffer.Buffer): file path
- `callback` (Function<Boolean>): atypical async callback function that received the result as a single boolean arguments

### existsSync(path)

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `path` (String | buffer.Buffer): file path

Returns: Boolean

### fchmod

- Platforms: Android, iPhone, iPad, macOS

Asynchronous `fchmod`.

**This is a no-op on Titanium.**

Parameters:

- `fd` (Number): file descriptor
- `mode` (String | Number): new mode/permissions
- `callback` (Function<Error>): typical async callback function

### fchmodSync

- Platforms: Android, iPhone, iPad, macOS

Synchronous `fchmod`.

**This is a no-op on Titanium.**

Parameters:

- `fd` (Number): file descriptor
- `mode` (String | Number): new mode/permissions

### fchown

- Platforms: Android, iPhone, iPad, macOS

Asynchronous `fchown`.

**This is a no-op on Titanium.**

Parameters:

- `fd` (Number): file descriptor
- `uid` (Number): new owner
- `gid` (Number): new group
- `callback` (Function<Error>): typical async callback function

### fchownSync

- Platforms: Android, iPhone, iPad, macOS

Synchronous `fchown`.

**This is a no-op on Titanium.**

Parameters:

- `fd` (Number): file descriptor
- `uid` (Number): new owner
- `gid` (Number): new group

### fdatasync

- Platforms: Android, iPhone, iPad, macOS

Asynchronous `fdatasync`.

**This is a no-op on Titanium.**

Parameters:

- `fd` (Number): file descriptor
- `callback` (Function<Error>): typical async callback function

### fdatasyncSync

- Platforms: Android, iPhone, iPad, macOS

Synchronous `fdatasync`.

**This is a no-op on Titanium.**

Parameters:

- `fd` (Number): file descriptor

### fstat

- Platforms: Android, iPhone, iPad, macOS

Asynchronous `fstat`.
The `callback` gets two arguments `(err, stats)` where `stats` is an [fs.Stats](https://titaniumsdk.com/docs/sdk/fs.Stats.md) object.
`fstat()` is identical to `stat()`, except that the file to be stat-ed is specified by the file descriptor `fd`.

Parameters:

- `fd` (Number): file descriptor
- `options` (fs.stat.options, optional): options
- `callback` (Function<Error, fs.Stats>): typical async callback function

### fstatSync

- Platforms: Android, iPhone, iPad, macOS

Synchronous `fstat`.

Parameters:

- `fd` (Number): file descriptor
- `options` (fs.stat.options, optional): options

Returns: fs.Stats

### lstat

- Platforms: Android, iPhone, iPad, macOS

Asynchronous `lstat`.

Parameters:

- `path` (String | buffer.Buffer): file path
- `options` (fs.stat.options, optional): options
- `callback` (Function<Error, fs.Stats>): typical async callback function

### lstatSync

- Platforms: Android, iPhone, iPad, macOS

Synchronous `lstat`.

Parameters:

- `path` (String | buffer.Buffer): file path
- `options` (fs.stat.options, optional): options

Returns: fs.Stats

### mkdir

- Platforms: Android, iPhone, iPad, macOS

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:

- `path` (String | buffer.Buffer): file path
- `options` (fs.mkdir.options, optional): options
- `callback` (Function<Error, String>): typical async callback function. The second argument is an optional path `string`.

### mkdirSync

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `path` (String | buffer.Buffer): file path
- `options` (fs.mkdir.options, optional): options

Returns: String - will return `undefined` if `recursive` option is not `true`

### mkdtemp

- Platforms: Android, iPhone, iPad, macOS

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:

- `prefix` (String): file prefix
- `options` (String | fs.mkdtemp.options, optional): encoding if `string`
- `callback` (Function<Error, String>): typical async callback function. The second argument is the generated path `string`.

### mkdtempSync

- Platforms: Android, iPhone, iPad, macOS

For detailed information, see the documentation of the asynchronous version of this API: [fs.mkdtemp](https://titaniumsdk.com/docs/sdk/fs.md#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:

- `prefix` (String): file prefix
- `options` (String | fs.mkdtemp.options, optional): encoding if `string`

Returns: String - Returns the created directory path.

### open

- Platforms: Android, iPhone, iPad, macOS

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:

- `path` (String | buffer.Buffer): file path
- `flags` (String | Number, optional): file system flags Default: `r`.
- `mode` (Number | String, optional): file permissions Default: `438`.
- `callback` (Function<Error, Number>): typical async callback function, the second argument is an integer representing a file descriptor

### openSync

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `path` (String | buffer.Buffer): file path
- `flags` (String | Number, optional): file system flags Default: `r`.
- `mode` (Number | String, optional): file permissions Default: `438`.

Returns: Number - Returns an integer representing the file descriptor.

### read

- Platforms: Android, iPhone, iPad, macOS

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:

- `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

### readdir

- Platforms: Android, iPhone, iPad, macOS

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:

- `path` (String | buffer.Buffer): file path
- `options` (fs.readdir.options, optional): options
- `callback` (Function<Error, Array<String>>): Typical async callback function. The second argument is an array of results which may be `String`s, [buffer.Buffer](https://titaniumsdk.com/docs/sdk/buffer.Buffer.md)s, or [fs.Dirent](https://titaniumsdk.com/docs/sdk/fs.Dirent.md)s

### readdirSync

- Platforms: Android, iPhone, iPad, macOS

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:

- `path` (String | buffer.Buffer): file path
- `options` (fs.readdir.options, optional): options

Returns: Array<String> | Array<buffer.Buffer> | Array<fs.Dirent> - an array of results which may be `String`s, [buffer.Buffer](https://titaniumsdk.com/docs/sdk/buffer.Buffer.md)s, or [fs.Dirent](https://titaniumsdk.com/docs/sdk/fs.Dirent.md)s

### readFile

- Platforms: Android, iPhone, iPad, macOS

Asynchronously reads the entire contents of a file.

Parameters:

- `path` (String | buffer.Buffer): file path
- `options` (fs.readFile.options | String, optional): 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](https://titaniumsdk.com/docs/sdk/buffer.Buffer.md)

### readFileSync

- Platforms: Android, iPhone, iPad, macOS

Synchronously reads the entire contents of a file.

Parameters:

- `path` (String | buffer.Buffer): file path
- `options` (fs.readFile.options | String, optional): encoding `string`, or an options object

Returns: String | buffer.Buffer - either a `string` or a [buffer.Buffer](https://titaniumsdk.com/docs/sdk/buffer.Buffer.md), based upon `options.encoding`

### readSync

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `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, optional): where to begin reading from in the file. *Unused/unsupported in Titanium.*

Returns: Number - Returns the number of bytesRead.

### realpath

- Platforms: Android, iPhone, iPad, macOS

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:

- `path` (String | buffer.Buffer): file path
- `options` (Object, optional): options
- `callback` (Function<Error, String>): typical async callback function

### realpath.native

- Platforms: Android, iPhone, iPad, macOS

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:

- `path` (String | buffer.Buffer): file path
- `options` (Object, optional): options
- `callback` (Function<Error, String>): typical async callback function

### realpathSync

- Platforms: Android, iPhone, iPad, macOS

Returns the resolved pathname.

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

Parameters:

- `path` (String | buffer.Buffer): file path
- `options` (Object, optional): options

Returns: String

### realpathSync.native

- Platforms: Android, iPhone, iPad, macOS

Synchronous `realpath`.

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

Parameters:

- `path` (String | buffer.Buffer): file path
- `options` (Object, optional): options

Returns: String

### rename

- Platforms: Android, iPhone, iPad, macOS

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:

- `oldPath` (String | buffer.Buffer): source file path
- `newPath` (String | buffer.Buffer): destination file path
- `callback` (Function<Error>): typical async callback function

### renameSync

- Platforms: Android, iPhone, iPad, macOS

Synchronous `rename`. Returns `undefined`.

Parameters:

- `oldPath` (String | buffer.Buffer): source file path
- `newPath` (String | buffer.Buffer): destination file path

### rmdir

- Platforms: Android, iPhone, iPad, macOS

Asynchronous `rmdir`

Parameters:

- `path` (String | buffer.Buffer): file path
- `options` (fs.rmDir.options, optional): options
- `callback` (Function<Error>): typical async callback function

### rmSync

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `path` (String | buffer.Buffer): file path
- `options` (fs.rm.options, optional): options

### stat

- Platforms: Android, iPhone, iPad, macOS

Asynchronous `stat`. The `callback` gets two arguments `(err, stats)` where `stats` is an [fs.Stats](https://titaniumsdk.com/docs/sdk/fs.Stats.md) 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:

- `path` (String | buffer.Buffer): file path
- `options` (Object, optional): fs.stat.options
- `callback` (Function<Error, fs.Stats>): typical async callback function

### statSync

- Platforms: Android, iPhone, iPad, macOS

Synchronous `stat`.

Parameters:

- `path` (String | buffer.Buffer): file path
- `options` (fs.stat.options, optional): options

Returns: fs.Stats

### symlink

- Platforms: Android, iPhone, iPad, macOS

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:

- `target` (String | buffer.Buffer): target of the new symlink
- `path` (String | buffer.Buffer): the symlink path
- `callback` (Function<Error>): typical async callback function

### symlinkSync

- Platforms: Android, iPhone, iPad, macOS

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:

- `target` (String | buffer.Buffer): target of the new symlink
- `path` (String | buffer.Buffer): the symlink path

### truncate

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `path` (String | buffer.Buffer): file path
- `len` (Number, optional): target length to truncate to Default: `0`.
- `callback` (Function<Error>): typical async callback function

### truncateSync

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `path` (String | buffer.Buffer): file path
- `len` (Number, optional): target length to truncate to Default: `0`.

### unlink

- Platforms: Android, iPhone, iPad, macOS

Asynchronous `unlink`. Returns `undefined`.

Parameters:

- `path` (String | buffer.Buffer): file path
- `callback` (Function<Error>): typical async callback function

### unlinkSync

- Platforms: Android, iPhone, iPad, macOS

Synchronous `unlink`. Returns `undefined`.

Parameters:

- `path` (String | buffer.Buffer): file path

### unwatchFile

- Platforms: Android, iPhone, iPad, macOS

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:

- `filename` (String | buffer.Buffer): file path
- `listener` (Function, optional): callback function when file changes Default: `undefined`.

### utimes

- Platforms: Android, iPhone, iPad, macOS

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

**This is a no-op on Titanium.**

Parameters:

- `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

### utimesSync

- Platforms: Android, iPhone, iPad, macOS

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

**This is a no-op on Titanium.**

Parameters:

- `path` (String | buffer.Buffer): file path
- `atime` (Number | String | Date): access time
- `mtime` (Number | String | Date): modification time

### watch

- Platforms: Android, iPhone, iPad, macOS

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

**This is a no-op on Titanium.**

Parameters:

- `filename` (String | buffer.Buffer): file path
- `options` (Object, optional): options
- `listener` (Function, optional): callback function when file changes Default: `undefined`.

### watchFile

- Platforms: Android, iPhone, iPad, macOS

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:

- `filename` (String | buffer.Buffer): file path
- `options` (Object, optional): options
- `listener` (Function): callback function when file changes

### write

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `fd` (Number): file descriptor
- `buffer` (String | buffer.Buffer): buffer contents to write
- `offset` (Number, optional): from the beginning of the file where this data should be written
- `length` (String | Number, optional): length in bytes of `Buffer`; or string character `encoding`
- `position` (Number, optional): 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

### writeFile

- Platforms: Android, iPhone, iPad, macOS

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:

- `file` (String | buffer.Buffer | Number): filename or file descriptor
- `data` (String | buffer.Buffer | Object): data to write
- `options` (fs.writeFile.options, optional): from the beginning of the file where this data should be written
- `callback` (Function<Error>): typical async callback function

### writeFileSync

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `file` (String | buffer.Buffer | Number): filename or file descriptor
- `data` (String | buffer.Buffer | Object): data to write
- `options` (fs.writeFile.options, optional): from the beginning of the file where this data should be written

### writeSync

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `fd` (Number): file descriptor
- `buffer` (String | buffer.Buffer): buffer contents to write
- `offset` (Number, optional): from the beginning of the file where this data should be written
- `length` (String | Number, optional): length in bytes of `Buffer`; or string character `encoding`
- `position` (Number, optional): offset from the beginning of the file where this data should be written (if data to be written is a `Buffer`)

Returns: Number - bytes written

---

- This corpus documents Titanium SDK 13.4.1. Anything here that does not name a version describes 13.4.1.
- Titanium is maintained by TiDev. The Appcelerator toolchain is retired: there is no `appc` CLI, no Appcelerator Studio and no hosted build service. The supported CLI is `titanium` on npm, invoked as `ti`.

