mirror of https://github.com/lukechilds/node.git
Browse Source
These changes affect the following functions and their synchronous counterparts: * fs.readFile() * fs.writeFile() * fs.appendFile() If the first parameter is a uint32, it is treated as a file descriptor. In all other cases, the original implementation is used to ensure backwards compatibility. File descriptor ownership is never taken from the user. The documentation was adjusted to reflect these API changes. A note was added to make the user aware of file descriptor ownership and the conditions under which a file descriptor can be used by each of these functions. Tests were extended to test for file descriptor parameters under the conditions noted in the relevant documentation. PR-URL: https://github.com/nodejs/node/pull/3163 Reviewed-By: Trevor Norris <trev.norris@gmail.com>v5.x
Johannes Wüller
9 years ago
committed by
Rod Vagg
7 changed files with 230 additions and 29 deletions
@ -0,0 +1,47 @@ |
|||
'use strict'; |
|||
var common = require('../common'); |
|||
var assert = require('assert'); |
|||
|
|||
var path = require('path'), |
|||
fs = require('fs'), |
|||
fn = path.join(common.fixturesDir, 'empty.txt'); |
|||
|
|||
tempFd(function(fd, close) { |
|||
fs.readFile(fd, function(err, data) { |
|||
assert.ok(data); |
|||
close(); |
|||
}); |
|||
}); |
|||
|
|||
tempFd(function(fd, close) { |
|||
fs.readFile(fd, 'utf8', function(err, data) { |
|||
assert.strictEqual('', data); |
|||
close(); |
|||
}); |
|||
}); |
|||
|
|||
tempFdSync(function(fd) { |
|||
assert.ok(fs.readFileSync(fd)); |
|||
}); |
|||
|
|||
tempFdSync(function(fd) { |
|||
assert.strictEqual('', fs.readFileSync(fd, 'utf8')); |
|||
}); |
|||
|
|||
function tempFd(callback) { |
|||
fs.open(fn, 'r', function(err, fd) { |
|||
if (err) throw err; |
|||
|
|||
callback(fd, function() { |
|||
fs.close(fd, function(err) { |
|||
if (err) throw err; |
|||
}); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
function tempFdSync(callback) { |
|||
var fd = fs.openSync(fn, 'r'); |
|||
callback(fd); |
|||
fs.closeSync(fd); |
|||
} |
Loading…
Reference in new issue