diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2014-05-18 12:25:05 +0400 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2014-05-18 12:25:05 +0400 |
commit | c8b6faa507e142c041962551dac53b01e6e0fb09 (patch) | |
tree | e0c62545f9e92095efe89e9937af9e9ae8d5ad18 /lib/fs_storage.js | |
parent | 4014d986ae7d3b67d1608a717854503c216cee8c (diff) |
code cleanup
Diffstat (limited to 'lib/fs_storage.js')
-rw-r--r-- | lib/fs_storage.js | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/fs_storage.js b/lib/fs_storage.js index f07d509..124a3a1 100644 --- a/lib/fs_storage.js +++ b/lib/fs_storage.js @@ -86,7 +86,7 @@ FSStorage.prototype.readBlock = function (index, offset, length, cb) { if (!cb) return console.error('FSStorage.readBlock requires a callback') var piece = self.pieces[index] - if (!piece) return cb(new Error("invalid piece index " + index)) + if (!piece) return cb(new Error('invalid piece index ' + index)) if (piece.verified && piece.buffer) { // piece is verified and cached in memory, so read directly from its buffer @@ -101,13 +101,13 @@ FSStorage.prototype.readBlock = function (index, offset, length, cb) { return (target.to > rangeFrom && target.from < rangeTo) }) - if (!targets.length) return cb(new Error("no file matching the requested range?")) + if (!targets.length) return cb(new Error('no file matching the requested range?')) var buffers = [] var end = targets.length var i = 0 - var readFromNextFile = function(err, buffer) { + var readFromNextFile = function (err, buffer) { if (err) return cb(err) if (buffer) buffers.push(buffer) if (i >= end) return cb(null, Buffer.concat(buffers)) @@ -118,13 +118,13 @@ FSStorage.prototype.readBlock = function (index, offset, length, cb) { var to = target.to var offset = target.offset - if(to > rangeTo) to = rangeTo - if(from < rangeFrom) { + if (to > rangeTo) to = rangeTo + if (from < rangeFrom) { offset += rangeFrom - from from = rangeFrom } - target.open(function(err, file) { + target.open(function (err, file) { if (err) return cb(err) file.read(offset, to - from, readFromNextFile) }) @@ -140,14 +140,14 @@ FSStorage.prototype._onPieceDone = function (piece) { var end = targets.length var i = 0 - var writeToNextFile = function(err) { + var writeToNextFile = function (err) { if (err) return self.emit('error', err) if (i >= end) { return Storage.prototype._onPieceDone.call(self, piece) } var target = targets[i++] - target.open(function(err, file) { + target.open(function (err, file) { if (err) return self.emit('error', err) file.write(target.offset, piece.buffer.slice(target.from, target.to), writeToNextFile) }) @@ -193,4 +193,3 @@ FSStorage.prototype.close = function (cb) { process.nextTick(loop) }) } - |