-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs: Add file descriptor support to *File() funcs #3163
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -468,9 +468,9 @@ The callback is given the three arguments, `(err, bytesRead, buffer)`. | |
|
||
Synchronous version of `fs.read`. Returns the number of `bytesRead`. | ||
|
||
## fs.readFile(filename[, options], callback) | ||
## fs.readFile(file[, options], callback) | ||
|
||
* `filename` {String} | ||
* `file` {String | Integer} filename or file descriptor | ||
* `options` {Object | String} | ||
* `encoding` {String | Null} default = `null` | ||
* `flag` {String} default = `'r'` | ||
|
@@ -492,18 +492,20 @@ If `options` is a string, then it specifies the encoding. Example: | |
|
||
fs.readFile('/etc/passwd', 'utf8', callback); | ||
|
||
Any specified file descriptor has to support reading. | ||
|
||
## fs.readFileSync(filename[, options]) | ||
_Note: Specified file descriptors will not be closed automatically._ | ||
|
||
Synchronous version of `fs.readFile`. Returns the contents of the `filename`. | ||
## fs.readFileSync(file[, options]) | ||
|
||
Synchronous version of `fs.readFile`. Returns the contents of the `file`. | ||
|
||
If the `encoding` option is specified then this function returns a | ||
string. Otherwise it returns a buffer. | ||
|
||
## fs.writeFile(file, data[, options], callback) | ||
|
||
## fs.writeFile(filename, data[, options], callback) | ||
|
||
* `filename` {String} | ||
* `file` {String | Integer} filename or file descriptor | ||
* `data` {String | Buffer} | ||
* `options` {Object | String} | ||
* `encoding` {String | Null} default = `'utf8'` | ||
|
@@ -528,13 +530,21 @@ If `options` is a string, then it specifies the encoding. Example: | |
|
||
fs.writeFile('message.txt', 'Hello Node.js', 'utf8', callback); | ||
|
||
## fs.writeFileSync(filename, data[, options]) | ||
Any specified file descriptor has to support writing. | ||
|
||
Note that it is unsafe to use `fs.writeFile` multiple times on the same file | ||
without waiting for the callback. For this scenario, | ||
`fs.createWriteStream` is strongly recommended. | ||
|
||
_Note: Specified file descriptors will not be closed automatically._ | ||
|
||
## fs.writeFileSync(file, data[, options]) | ||
|
||
The synchronous version of `fs.writeFile`. Returns `undefined`. | ||
|
||
## fs.appendFile(filename, data[, options], callback) | ||
## fs.appendFile(file, data[, options], callback) | ||
|
||
* `filename` {String} | ||
* `file` {String | Integer} filename or file descriptor | ||
* `data` {String | Buffer} | ||
* `options` {Object | String} | ||
* `encoding` {String | Null} default = `'utf8'` | ||
|
@@ -556,7 +566,11 @@ If `options` is a string, then it specifies the encoding. Example: | |
|
||
fs.appendFile('message.txt', 'data to append', 'utf8', callback); | ||
|
||
## fs.appendFileSync(filename, data[, options]) | ||
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]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that you have the note in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure what you are asking, exactly. The note is present in all asynchronous versions, while being omitted in the synchronous ones, since the latter segments only refer to the asynchronous documentation anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoop. Sorry. Got lost in the diff. Can see that now. |
||
|
||
The synchronous version of `fs.appendFile`. Returns `undefined`. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind adding that data written to fd will be appended?
Guess we don't expose an
lseek()
in fs so users couldn't reposition where data is written. Hm. Future feature.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nm. i see what's happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether data will be appended depends on the flags that the
fd
was created with. Thea
flags will obviously append, but thew
flags will create/truncate instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. I crossed the following code from
fs.append
:Sorry