From ba10ea8f3af4a1af5c2f7df3e4f5af348f09e97b Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 12 May 2016 20:52:39 +0200 Subject: [PATCH] doc: add `added:` information for fs Ref: https://github.com/nodejs/node/issues/6578 PR-URL: https://github.com/nodejs/node/pull/6717 Reviewed-By: Robert Lindstaedt Reviewed-By: James M Snell --- doc/api/fs.md | 272 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) diff --git a/doc/api/fs.md b/doc/api/fs.md index 9ecd61b1b6..8fa1fb348d 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -90,6 +90,9 @@ Error: EISDIR: illegal operation on a directory, read ``` ## Buffer API + `fs` functions support passing and receiving paths as both strings and Buffers. The latter is intended to make it possible to work with @@ -102,10 +105,16 @@ will always be encoded as UTF-8. On such file systems, passing non-UTF-8 encoded Buffers to `fs` functions will not work as expected. ## Class: fs.FSWatcher + Objects returned from `fs.watch()` are of this type. ### Event: 'change' + * `event` {String} The type of fs change * `filename` {String | Buffer} The filename that changed (if relevant/available) @@ -127,31 +136,49 @@ fs.watch('./tmp', {encoding: 'buffer'}, (event, filename) => { ``` ### Event: 'error' + * `error` {Error} Emitted when an error occurs. ### watcher.close() + Stop watching for changes on the given `fs.FSWatcher`. ## Class: fs.ReadStream + `ReadStream` is a [Readable Stream][]. ### Event: 'open' + * `fd` {Integer} Integer file descriptor used by the ReadStream. Emitted when the ReadStream's file is opened. ### Event: 'close' + Emitted when the `ReadStream`'s underlying file descriptor has been closed using the `fs.close()` method. ### readStream.path + The path to the file the stream is reading from as specified in the first argument to `fs.createReadStream()`. If `path` is passed as a string, then @@ -159,6 +186,9 @@ argument to `fs.createReadStream()`. If `path` is passed as a string, then `readStream.path` will be a `Buffer`. ## Class: fs.Stats + Objects returned from [`fs.stat()`][], [`fs.lstat()`][] and [`fs.fstat()`][] and their synchronous counterparts are of this type. @@ -229,26 +259,41 @@ systems. Note that as of v0.12, `ctime` is not "creation time", and on Unix systems, it never was. ## Class: fs.WriteStream + `WriteStream` is a [Writable Stream][]. ### Event: 'open' + * `fd` {Integer} Integer file descriptor used by the WriteStream. Emitted when the WriteStream's file is opened. ### Event: 'close' + Emitted when the `WriteStream`'s underlying file descriptor has been closed using the `fs.close()` method. ### writeStream.bytesWritten + The number of bytes written so far. Does not include data that is still queued for writing. ### writeStream.path + The path to the file the stream is writing to as specified in the first argument to `fs.createWriteStream()`. If `path` is passed as a string, then @@ -256,6 +301,9 @@ argument to `fs.createWriteStream()`. If `path` is passed as a string, then `writeStream.path` will be a `Buffer`. ## fs.access(path[, mode], callback) + * `path` {String | Buffer} * `mode` {Integer} @@ -286,6 +334,9 @@ fs.access('/etc/passwd', fs.constants.R_OK | fs.constants.W_OK, (err) => { ``` ## fs.accessSync(path[, mode]) + * `path` {String | Buffer} * `mode` {Integer} @@ -294,6 +345,9 @@ Synchronous version of [`fs.access()`][]. This throws if any accessibility checks fail, and does nothing otherwise. ## fs.appendFile(file, data[, options], callback) + * `file` {String | Buffer | Number} filename or file descriptor * `data` {String | Buffer} @@ -326,6 +380,9 @@ Any specified file descriptor has to have been opened for appending. _Note: Specified file descriptors will not be closed automatically._ ## fs.appendFileSync(file, data[, options]) + * `file` {String | Buffer | Number} filename or file descriptor * `data` {String | Buffer} @@ -337,6 +394,9 @@ _Note: Specified file descriptors will not be closed automatically._ The synchronous version of [`fs.appendFile()`][]. Returns `undefined`. ## fs.chmod(path, mode, callback) + * `path` {String | Buffer} * `mode` {Integer} @@ -346,6 +406,9 @@ Asynchronous chmod(2). No arguments other than a possible exception are given to the completion callback. ## fs.chmodSync(path, mode) + * `path` {String | Buffer} * `mode` {Integer} @@ -353,6 +416,9 @@ to the completion callback. Synchronous chmod(2). Returns `undefined`. ## fs.chown(path, uid, gid, callback) + * `path` {String | Buffer} * `uid` {Integer} @@ -363,6 +429,9 @@ Asynchronous chown(2). No arguments other than a possible exception are given to the completion callback. ## fs.chownSync(path, uid, gid) + * `path` {String | Buffer} * `uid` {Integer} @@ -371,6 +440,9 @@ to the completion callback. Synchronous chown(2). Returns `undefined`. ## fs.close(fd, callback) + * `fd` {Integer} * `callback` {Function} @@ -379,6 +451,9 @@ Asynchronous close(2). No arguments other than a possible exception are given to the completion callback. ## fs.closeSync(fd) + * `fd` {Integer} @@ -391,6 +466,9 @@ operations. The specific constants currently defined are described in [FS Constants][]. ## fs.createReadStream(path[, options]) + * `path` {String | Buffer} * `options` {String | Object} @@ -447,6 +525,9 @@ fs.createReadStream('sample.txt', {start: 90, end: 99}); If `options` is a string, then it specifies the encoding. ## fs.createWriteStream(path[, options]) + * `path` {String | Buffer} * `options` {String | Object} @@ -491,6 +572,10 @@ Like [`ReadStream`][], if `fd` is specified, `WriteStream` will ignore the If `options` is a string, then it specifies the encoding. ## fs.exists(path, callback) + Stability: 0 - Deprecated: Use [`fs.stat()`][] or [`fs.access()`][] instead. @@ -513,6 +598,10 @@ call `fs.open()` directly and handle the error raised if the file is non-existent. ## fs.existsSync(path) + Stability: 0 - Deprecated: Use [`fs.statSync()`][] or [`fs.accessSync()`][] instead. @@ -523,6 +612,9 @@ Synchronous version of [`fs.exists()`][]. Returns `true` if the file exists, `false` otherwise. ## fs.fchmod(fd, mode, callback) + * `fd` {Integer} * `mode` {Integer} @@ -532,6 +624,9 @@ Asynchronous fchmod(2). No arguments other than a possible exception are given to the completion callback. ## fs.fchmodSync(fd, mode) + * `fd` {Integer} * `mode` {Integer} @@ -539,6 +634,9 @@ are given to the completion callback. Synchronous fchmod(2). Returns `undefined`. ## fs.fchown(fd, uid, gid, callback) + * `fd` {Integer} * `uid` {Integer} @@ -549,6 +647,9 @@ Asynchronous fchown(2). No arguments other than a possible exception are given to the completion callback. ## fs.fchownSync(fd, uid, gid) + * `fd` {Integer} * `uid` {Integer} @@ -557,6 +658,9 @@ to the completion callback. Synchronous fchown(2). Returns `undefined`. ## fs.fdatasync(fd, callback) + * `fd` {Integer} * `callback` {Function} @@ -565,12 +669,18 @@ Asynchronous fdatasync(2). No arguments other than a possible exception are given to the completion callback. ## fs.fdatasyncSync(fd) + * `fd` {Integer} Synchronous fdatasync(2). Returns `undefined`. ## fs.fstat(fd, callback) + * `fd` {Integer} * `callback` {Function} @@ -580,12 +690,18 @@ Asynchronous fstat(2). The callback gets two arguments `(err, stats)` where except that the file to be stat-ed is specified by the file descriptor `fd`. ## fs.fstatSync(fd) + * `fd` {Integer} Synchronous fstat(2). Returns an instance of `fs.Stats`. ## fs.fsync(fd, callback) + * `fd` {Integer} * `callback` {Function} @@ -594,12 +710,18 @@ Asynchronous fsync(2). No arguments other than a possible exception are given to the completion callback. ## fs.fsyncSync(fd) + * `fd` {Integer} Synchronous fsync(2). Returns `undefined`. ## fs.ftruncate(fd, len, callback) + * `fd` {Integer} * `len` {Integer} @@ -609,6 +731,9 @@ Asynchronous ftruncate(2). No arguments other than a possible exception are given to the completion callback. ## fs.ftruncateSync(fd, len) + * `fd` {Integer} * `len` {Integer} @@ -616,6 +741,9 @@ given to the completion callback. Synchronous ftruncate(2). Returns `undefined`. ## fs.futimes(fd, atime, mtime, callback) + * `fd` {Integer} * `atime` {Integer} @@ -626,6 +754,9 @@ Change the file timestamps of a file referenced by the supplied file descriptor. ## fs.futimesSync(fd, atime, mtime) + * `fd` {Integer} * `atime` {Integer} @@ -634,6 +765,9 @@ descriptor. Synchronous version of [`fs.futimes()`][]. Returns `undefined`. ## fs.lchmod(path, mode, callback) + * `path` {String | Buffer} * `mode` {Integer} @@ -645,6 +779,9 @@ are given to the completion callback. Only available on Mac OS X. ## fs.lchmodSync(path, mode) + * `path` {String | Buffer} * `mode` {Integer} @@ -652,6 +789,9 @@ Only available on Mac OS X. Synchronous lchmod(2). Returns `undefined`. ## fs.lchown(path, uid, gid, callback) + * `path` {String | Buffer} * `uid` {Integer} @@ -662,6 +802,9 @@ Asynchronous lchown(2). No arguments other than a possible exception are given to the completion callback. ## fs.lchownSync(path, uid, gid) + * `path` {String | Buffer} * `uid` {Integer} @@ -670,6 +813,9 @@ to the completion callback. Synchronous lchown(2). Returns `undefined`. ## fs.link(srcpath, dstpath, callback) + * `srcpath` {String | Buffer} * `dstpath` {String | Buffer} @@ -679,6 +825,9 @@ Asynchronous link(2). No arguments other than a possible exception are given to the completion callback. ## fs.linkSync(srcpath, dstpath) + * `srcpath` {String | Buffer} * `dstpath` {String | Buffer} @@ -686,6 +835,9 @@ the completion callback. Synchronous link(2). Returns `undefined`. ## fs.lstat(path, callback) + * `path` {String | Buffer} * `callback` {Function} @@ -696,12 +848,18 @@ except that if `path` is a symbolic link, then the link itself is stat-ed, not the file that it refers to. ## fs.lstatSync(path) + * `path` {String | Buffer} Synchronous lstat(2). Returns an instance of `fs.Stats`. ## fs.mkdir(path[, mode], callback) + * `path` {String | Buffer} * `mode` {Integer} @@ -711,6 +869,9 @@ Asynchronous mkdir(2). No arguments other than a possible exception are given to the completion callback. `mode` defaults to `0o777`. ## fs.mkdirSync(path[, mode]) + * `path` {String | Buffer} * `mode` {Integer} @@ -718,6 +879,9 @@ to the completion callback. `mode` defaults to `0o777`. Synchronous mkdir(2). Returns `undefined`. ## fs.mkdtemp(prefix, callback) + Creates a unique temporary directory. @@ -737,11 +901,17 @@ fs.mkdtemp('/tmp/foo-', (err, folder) => { ``` ## fs.mkdtempSync(template) + The synchronous version of [`fs.mkdtemp()`][]. Returns the created folder path. ## fs.open(path, flags[, mode], callback) + * `path` {String | Buffer} * `flags` {String | Number} @@ -823,6 +993,9 @@ fs.open('', 'a+', (err, fd) => { ``` ## fs.openSync(path, flags[, mode]) + * `path` {String | Buffer} * `flags` {String | Number} @@ -832,6 +1005,9 @@ Synchronous version of [`fs.open()`][]. Returns an integer representing the file descriptor. ## fs.read(fd, buffer, offset, length, position, callback) + * `fd` {Integer} * `buffer` {String | Buffer} @@ -854,6 +1030,9 @@ If `position` is `null`, data will be read from the current file position. The callback is given the three arguments, `(err, bytesRead, buffer)`. ## fs.readdir(path[, options], callback) + * `path` {String | Buffer} * `options` {String | Object} @@ -870,6 +1049,9 @@ the filenames passed to the callback. If the `encoding` is set to `'buffer'`, the filenames returned will be passed as `Buffer` objects. ## fs.readdirSync(path[, options]) + * `path` {String | Buffer} * `options` {String | Object} @@ -884,6 +1066,9 @@ the filenames passed to the callback. If the `encoding` is set to `'buffer'`, the filenames returned will be passed as `Buffer` objects. ## fs.readFile(file[, options], callback) + * `file` {String | Buffer | Integer} filename or file descriptor * `options` {Object | String} @@ -916,6 +1101,9 @@ Any specified file descriptor has to support reading. _Note: Specified file descriptors will not be closed automatically._ ## fs.readFileSync(file[, options]) + * `file` {String | Buffer | Integer} filename or file descriptor * `options` {Object | String} @@ -928,6 +1116,9 @@ If the `encoding` option is specified then this function returns a string. Otherwise it returns a buffer. ## fs.readlink(path[, options], callback) + * `path` {String | Buffer} * `options` {String | Object} @@ -943,6 +1134,9 @@ the link path passed to the callback. If the `encoding` is set to `'buffer'`, the link path returned will be passed as a `Buffer` object. ## fs.readlinkSync(path[, options]) + * `path` {String | Buffer} * `options` {String | Object} @@ -956,6 +1150,9 @@ the link path passed to the callback. If the `encoding` is set to `'buffer'`, the link path returned will be passed as a `Buffer` object. ## fs.readSync(fd, buffer, offset, length, position) + * `fd` {Integer} * `buffer` {String | Buffer} @@ -966,6 +1163,9 @@ the link path returned will be passed as a `Buffer` object. Synchronous version of [`fs.read()`][]. Returns the number of `bytesRead`. ## fs.realpath(path[, options], callback) + * `path` {String | Buffer} * `options` {String | Object} @@ -981,6 +1181,9 @@ the path passed to the callback. If the `encoding` is set to `'buffer'`, the path returned will be passed as a `Buffer` object. ## fs.realpathSync(path[, options]) + * `path` {String | Buffer}; * `options` {String | Object} @@ -994,6 +1197,9 @@ the path passed to the callback. If the `encoding` is set to `'buffer'`, the path returned will be passed as a `Buffer` object. ## fs.rename(oldPath, newPath, callback) + * `oldPath` {String | Buffer} * `newPath` {String | Buffer} @@ -1003,6 +1209,9 @@ Asynchronous rename(2). No arguments other than a possible exception are given to the completion callback. ## fs.renameSync(oldPath, newPath) + * `oldPath` {String | Buffer} * `newPath` {String | Buffer} @@ -1010,6 +1219,9 @@ to the completion callback. Synchronous rename(2). Returns `undefined`. ## fs.rmdir(path, callback) + * `path` {String | Buffer} * `callback` {Function} @@ -1018,12 +1230,18 @@ Asynchronous rmdir(2). No arguments other than a possible exception are given to the completion callback. ## fs.rmdirSync(path) + * `path` {String | Buffer} Synchronous rmdir(2). Returns `undefined`. ## fs.stat(path, callback) + * `path` {String | Buffer} * `callback` {Function} @@ -1033,12 +1251,18 @@ Asynchronous stat(2). The callback gets two arguments `(err, stats)` where information. ## fs.statSync(path) + * `path` {String | Buffer} Synchronous stat(2). Returns an instance of [`fs.Stats`][]. ## fs.symlink(target, path[, type], callback) + * `target` {String | Buffer} * `path` {String | Buffer} @@ -1061,6 +1285,9 @@ fs.symlink('./foo', './new-port'); It creates a symbolic link named "new-port" that points to "foo". ## fs.symlinkSync(target, path[, type]) + * `target` {String | Buffer} * `path` {String | Buffer} @@ -1069,6 +1296,9 @@ It creates a symbolic link named "new-port" that points to "foo". Synchronous symlink(2). Returns `undefined`. ## fs.truncate(path, len, callback) + * `path` {String | Buffer} * `len` {Integer} @@ -1079,6 +1309,9 @@ given to the completion callback. A file descriptor can also be passed as the first argument. In this case, `fs.ftruncate()` is called. ## fs.truncateSync(path, len) + * `path` {String | Buffer} * `len` {Integer} @@ -1086,6 +1319,9 @@ first argument. In this case, `fs.ftruncate()` is called. Synchronous truncate(2). Returns `undefined`. ## fs.unlink(path, callback) + * `path` {String | Buffer} * `callback` {Function} @@ -1094,12 +1330,18 @@ Asynchronous unlink(2). No arguments other than a possible exception are given to the completion callback. ## fs.unlinkSync(path) + * `path` {String | Buffer} Synchronous unlink(2). Returns `undefined`. ## fs.unwatchFile(filename[, listener]) + * `filename` {String | Buffer} * `listener` {Function} @@ -1116,6 +1358,9 @@ _Note: [`fs.watch()`][] is more efficient than `fs.watchFile()` and `fs.unwatchF when possible._ ## fs.utimes(path, atime, mtime, callback) + * `path` {String | Buffer} * `atime` {Integer} @@ -1133,6 +1378,9 @@ follow the below rules: `Date.now()`. ## fs.utimesSync(path, atime, mtime) + * `path` {String | Buffer} * `atime` {Integer} @@ -1141,6 +1389,9 @@ follow the below rules: Synchronous version of [`fs.utimes()`][]. Returns `undefined`. ## fs.watch(filename[, options][, listener]) + * `filename` {String | Buffer} * `options` {String | Object} @@ -1225,6 +1476,9 @@ fs.watch('somedir', (event, filename) => { ``` ## fs.watchFile(filename[, options], listener) + * `filename` {String | Buffer} * `options` {Object} @@ -1268,6 +1522,9 @@ _Note: [`fs.watch()`][] is more efficient than `fs.watchFile` and `fs.unwatchFile` when possible._ ## fs.write(fd, buffer, offset, length[, position], callback) + * `fd` {Integer} * `buffer` {String | Buffer} @@ -1296,6 +1553,9 @@ The kernel ignores the position argument and always appends the data to the end of the file. ## fs.write(fd, data[, position[, encoding]], callback) + * `fd` {Integer} * `data` {String | Buffer} @@ -1329,6 +1589,9 @@ The kernel ignores the position argument and always appends the data to the end of the file. ## fs.writeFile(file, data[, options], callback) + * `file` {String | Buffer | Integer} filename or file descriptor * `data` {String | Buffer} @@ -1368,6 +1631,9 @@ without waiting for the callback. For this scenario, _Note: Specified file descriptors will not be closed automatically._ ## fs.writeFileSync(file, data[, options]) + * `file` {String | Buffer | Integer} filename or file descriptor * `data` {String | Buffer} @@ -1379,6 +1645,9 @@ _Note: Specified file descriptors will not be closed automatically._ The synchronous version of [`fs.writeFile()`][]. Returns `undefined`. ## fs.writeSync(fd, buffer, offset, length[, position]) + * `fd` {Integer} * `buffer` {String | Buffer} @@ -1387,6 +1656,9 @@ The synchronous version of [`fs.writeFile()`][]. Returns `undefined`. * `position` {Integer} ## fs.writeSync(fd, data[, position[, encoding]]) + * `fd` {Integer} * `data` {String | Buffer}