Fix #325. Add test and check for zero-length file contents in fs.readFileSync
This commit is contained in:
parent
38f8665f3a
commit
8ff7954165
@ -112,9 +112,11 @@ fs.readFileSync = function (path, encoding) {
|
|||||||
i.copy(buffer,offset,0,i._bytesRead);
|
i.copy(buffer,offset,0,i._bytesRead);
|
||||||
offset += i._bytesRead;
|
offset += i._bytesRead;
|
||||||
})
|
})
|
||||||
} else {
|
} else if (buffers.length) {
|
||||||
//buffers has exactly 1 (possibly zero length) buffer, so this should be a shortcut
|
//buffers has exactly 1 (possibly zero length) buffer, so this should be a shortcut
|
||||||
buffer = buffers[0].slice(0, buffers[0]._bytesRead);
|
buffer = buffers[0].slice(0, buffers[0]._bytesRead);
|
||||||
|
} else {
|
||||||
|
buffer = new Buffer(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encoding) buffer = buffer.toString(encoding);
|
if (encoding) buffer = buffer.toString(encoding);
|
||||||
|
@ -12,4 +12,7 @@ fs.readFile(fn, function(err, data) {
|
|||||||
|
|
||||||
fs.readFile(fn, 'utf8', function(err, data) {
|
fs.readFile(fn, 'utf8', function(err, data) {
|
||||||
assert.strictEqual('', data);
|
assert.strictEqual('', data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
assert.ok(fs.readFileSync(fn));
|
||||||
|
assert.strictEqual('', fs.readFileSync(fn, 'utf8'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user