diff options
-rw-r--r-- | lib/torrent.js | 18 | ||||
-rw-r--r-- | package.json | 4 | ||||
-rw-r--r-- | test/node/torrent-events.js | 6 |
3 files changed, 14 insertions, 14 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index 60f1a20..7412158 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -8,7 +8,7 @@ import path from 'path' import addrToIPPort from 'addr-to-ip-port' import BitField from 'bitfield' import CacheChunkStore from 'cache-chunk-store' -import ChunkStoreWriteStream from 'chunk-store-stream/write.js' +import { chunkStoreWrite } from 'chunk-store-iterator' import cpus from 'cpus' import debugFactory from 'debug' import Discovery from 'torrent-discovery' @@ -22,14 +22,12 @@ import parallel from 'run-parallel' import parallelLimit from 'run-parallel-limit' import parseTorrent from 'parse-torrent' import Piece from 'torrent-piece' -import pump from 'pump' import queueMicrotask from 'queue-microtask' import randomIterate from 'random-iterate' import sha1 from 'simple-sha1' import throughput from 'throughput' import utMetadata from 'ut_metadata' import utPex from 'ut_pex' // browser exclude -import { Readable } from 'streamx' import File from './file.js' import Peer from './peer.js' @@ -1830,22 +1828,22 @@ export default class Torrent extends EventEmitter { return done } - load (streams, cb) { + async load (streams, cb) { if (this.destroyed) throw new Error('torrent is destroyed') if (!this.ready) return this.once('ready', () => { this.load(streams, cb) }) if (!Array.isArray(streams)) streams = [streams] if (!cb) cb = noop - const readable = Readable.from(joinIterator(streams)) - const writable = new ChunkStoreWriteStream(this.store, this.pieceLength) - - pump(readable, writable, err => { - if (err) return cb(err) + try { + await chunkStoreWrite(this.store, joinIterator(streams), { chunkLength: this.pieceLength }) this._markAllVerified() this._checkDone() cb(null) - }) + } catch (err) { + cb(err) + return err + } } pause () { diff --git a/package.json b/package.json index 0035def..2b44d51 100644 --- a/package.json +++ b/package.json @@ -40,10 +40,10 @@ "addr-to-ip-port": "^1.5.4", "bitfield": "^4.1.0", "bittorrent-dht": "^10.0.6", - "bittorrent-protocol": "^3.5.5", + "bittorrent-protocol": "^4.0.1", "cache-chunk-store": "^3.2.2", "chrome-net": "^3.3.4", - "chunk-store-stream": "^4.3.0", + "chunk-store-iterator": "^1.0.2", "cpus": "^1.0.3", "create-torrent": "^5.0.6", "debug": "^4.3.4", diff --git a/test/node/torrent-events.js b/test/node/torrent-events.js index bb2de83..32adb1f 100644 --- a/test/node/torrent-events.js +++ b/test/node/torrent-events.js @@ -53,7 +53,7 @@ test('client.add: emit torrent events in order', t => { }) test('client.seed: emit torrent events in order', t => { - t.plan(5) + t.plan(6) const client = new WebTorrent({ dht: false, tracker: false, lsd: false }) @@ -78,7 +78,9 @@ test('client.seed: emit torrent events in order', t => { torrent.on('done', () => { t.equal(++order, 4) - + }) + torrent.on('seed', () => { + t.equal(++order, 5) client.destroy(err => { t.error(err, 'client destroyed') }) }) }) |