mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
Handle empty files with fs.readFile
This commit is contained in:
parent
c6c77d535f
commit
976926376d
@ -51,6 +51,10 @@ fs.readFile = function (path, encoding_, callback) {
|
||||
var buffer = new Buffer(size);
|
||||
var offset = 0;
|
||||
function doRead() {
|
||||
if (size < 1) {
|
||||
callback(null, buffer);
|
||||
return;
|
||||
}
|
||||
// position is offset or null so we can read files on unseekable mediums
|
||||
binding.read(fd, buffer, offset, size - offset, offset || null, function (err, amount) {
|
||||
if (err) {
|
||||
|
0
test/fixtures/empty.txt
vendored
Normal file
0
test/fixtures/empty.txt
vendored
Normal file
10
test/simple/test-fs-readfile-empty.js
Normal file
10
test/simple/test-fs-readfile-empty.js
Normal file
@ -0,0 +1,10 @@
|
||||
require('../common');
|
||||
|
||||
var
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
fn = path.join(fixturesDir, 'empty.txt');
|
||||
|
||||
fs.readFile(fn, function(err, data) {
|
||||
assert.ok(data);
|
||||
});
|
Loading…
Reference in New Issue
Block a user