mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
Handle empty files with fs.readFile
This commit is contained in:
1 parent
c6c77d535f
commit
976926376d
3 files changed
+14
No files matched your search
@@ -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) {
|
||||
|
||||
Vendored
Whitespace-only changes.
@@ -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);
|
||||
});
|
||||
Reference in new issue
Block a user