node/test/parallel/test-fs-readfile-fd.js
Michaël Zasso d1aabd6264 test: fix style issues after eslint update
Replace var keyword with const or let.

PR-URL: https://github.com/nodejs/io.js/pull/2286
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-01-13 23:16:17 +01:00

47 lines
912 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const 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);
}