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:
authorThaUnknown <6506529+ThaUnknown@users.noreply.github.com>2022-06-26 19:32:59 +0300
committerThaUnknown <6506529+ThaUnknown@users.noreply.github.com>2022-06-26 19:32:59 +0300
commit8b97ee8cc18b05e0d20135ea8f1651e97bb65c6f (patch)
tree91ca9bbb72e50fe667035a7d664dec34edc964ee
parent4be86f5151381b34820a9892d3179afe0176fbfb (diff)
fix: use streamx instead of stream
-rw-r--r--lib/file-stream.js24
-rw-r--r--lib/file.js2
-rw-r--r--package.json1
3 files changed, 12 insertions, 15 deletions
diff --git a/lib/file-stream.js b/lib/file-stream.js
index a3682b1..cb6eb63 100644
--- a/lib/file-stream.js
+++ b/lib/file-stream.js
@@ -1,6 +1,5 @@
-const stream = require('stream')
+const { Readable } = require('streamx')
const debugFactory = require('debug')
-const eos = require('end-of-stream')
const debug = debugFactory('webtorrent:file-stream')
@@ -12,7 +11,7 @@ const debug = debugFactory('webtorrent:file-stream')
* @param {number} opts.start stream slice of file, starting from this byte (inclusive)
* @param {number} opts.end stream slice of file, ending with this byte (inclusive)
*/
-class FileStream extends stream.Readable {
+class FileStream extends Readable {
constructor (file, opts) {
super(opts)
@@ -39,26 +38,22 @@ class FileStream extends stream.Readable {
this._torrent.select(this._startPiece, this._endPiece, true, () => {
this._notify()
})
-
- // Ensure that cleanup happens even if destroy() is never called (readable-stream v3 currently doesn't call it automaticallly)
- eos(this, (err) => {
- this.destroy(err)
- })
}
- _read () {
+ _read (cb) {
if (this._reading) return
this._reading = true
- this._notify()
+ this._notify(cb)
}
- _notify () {
- if (!this._reading || this._missing === 0) return
+ _notify (cb = () => {}) {
+ if (!this._reading || this._missing === 0) return cb()
if (!this._torrent.bitfield.get(this._piece)) {
+ cb()
return this._torrent.critical(this._piece, this._piece + this._criticalLength)
}
- if (this._notifying) return
+ if (this._notifying) return cb()
this._notifying = true
if (this._torrent.destroyed) return this.destroy(new Error('Torrent removed'))
@@ -92,11 +87,12 @@ class FileStream extends stream.Readable {
this.push(buffer)
if (this._missing === 0) this.push(null)
+ cb()
})
this._piece += 1
}
- _destroy (err, cb) {
+ _destroy (cb, err) {
if (!this._torrent.destroyed) {
this._torrent.deselect(this._startPiece, this._endPiece, true)
}
diff --git a/lib/file.js b/lib/file.js
index c5e5f1e..35d9438 100644
--- a/lib/file.js
+++ b/lib/file.js
@@ -1,5 +1,5 @@
const EventEmitter = require('events')
-const { PassThrough } = require('stream')
+const { PassThrough } = require('streamx')
const path = require('path')
const render = require('render-media')
const streamToBlob = require('stream-to-blob')
diff --git a/package.json b/package.json
index b4b8d73..6175ad1 100644
--- a/package.json
+++ b/package.json
@@ -74,6 +74,7 @@
"stream-to-blob": "^2.0.1",
"stream-to-blob-url": "^3.0.2",
"stream-with-known-length-to-buffer": "^1.0.4",
+ "streamx": "^2.12.4",
"throughput": "^1.0.1",
"torrent-discovery": "^9.4.13",
"torrent-piece": "^2.0.1",