mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 16:22:29 +00:00

PR-URL: https://github.com/nodejs/node/pull/16112 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
46 lines
902 B
JavaScript
46 lines
902 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const fixtures = require('../common/fixtures');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const fn = fixtures.path('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) {
|
|
assert.ifError(err);
|
|
callback(fd, function() {
|
|
fs.close(fd, function(err) {
|
|
assert.ifError(err);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
function tempFdSync(callback) {
|
|
const fd = fs.openSync(fn, 'r');
|
|
callback(fd);
|
|
fs.closeSync(fd);
|
|
}
|