From 32f3d1b49f0844db50a894502711ea37cef52f86 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 3 Jan 2016 17:41:34 +0100 Subject: [PATCH] Fix exception on zero-length buffers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is an issue in node.js, but let’s fix it here so it works today. Node issue: https://github.com/nodejs/node/issues/4517 --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index c8705a7..51cd6b3 100644 --- a/index.js +++ b/index.js @@ -74,6 +74,9 @@ RandomAccessFile.prototype.close = function(callback) { RandomAccessFile.prototype.read = function(offset, length, callback) { this.open(function(err, self) { if (err) return callback(err); + + if (length === 0) return callback(null, new Buffer(0)); + fs.read(self.fd, alloc(length), 0, length, offset, function(err, read, buffer) { if (read !== buffer.length) return callback(new Error('range not satisfied')); callback(err, buffer);