Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2015-08-22 18:58:22 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-08-22 18:58:22 +0300
commit0d7035160ac8f1fd765f3c90815b95b77bcc6aa6 (patch)
tree00525626a4ce60493373955bb8fa5608a4437dc6 /lib/file.js
parent07948311409a908605e8bb002edaafdbcccfb07d (diff)
file: make file.createReadStream work on zero-length file
Diffstat (limited to 'lib/file.js')
-rw-r--r--lib/file.js21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/file.js b/lib/file.js
index 44e8c6b..5149047 100644
--- a/lib/file.js
+++ b/lib/file.js
@@ -7,6 +7,7 @@ var FileStream = require('./file-stream')
var inherits = require('inherits')
var mime = require('./mime.json')
var path = require('path')
+var stream = require('stream')
inherits(File, EventEmitter)
@@ -67,14 +68,22 @@ File.prototype.deselect = function () {
*/
File.prototype.createReadStream = function (opts) {
var self = this
- var stream = new FileStream(self, opts)
- self._torrent.select(stream._startPiece, stream._endPiece, true, function () {
- stream._notify()
+ if (this.length === 0) {
+ var empty = new stream.PassThrough()
+ process.nextTick(function () {
+ empty.end()
+ })
+ return empty
+ }
+
+ var fileStream = new FileStream(self, opts)
+ self._torrent.select(fileStream._startPiece, fileStream._endPiece, true, function () {
+ fileStream._notify()
})
- eos(stream, function () {
- self._torrent.deselect(stream._startPiece, stream._endPiece, true)
+ eos(fileStream, function () {
+ self._torrent.deselect(fileStream._startPiece, fileStream._endPiece, true)
})
- return stream
+ return fileStream
}
/**