node/test/parallel/test-fs-readfile-fd.js
Tobias Kieslich 7525df7af2 test: use common.fixtures.path()
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>
2017-10-10 22:47:05 -07:00

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);
}