Skip to content

Commit

Permalink
perf: drop streamx (#2462)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaUnknown committed Jan 28, 2023
1 parent 86ac634 commit cde79ed
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/peer.js
Original file line number Diff line number Diff line change
@@ -1,5 1,5 @@
import EventEmitter from 'events'
import { Transform } from 'stream'
import { Transform, pipeline } from 'streamx'
import arrayRemove from 'unordered-array-remove'
import debugFactory from 'debug'
import Wire from 'bittorrent-protocol'
Expand Down Expand Up @@ -181,25 181,27 @@ export default class Peer extends EventEmitter {

setThrottlePipes () {
const self = this
this.conn
.pipe(this.throttleGroups.down.throttle())
.pipe(new Transform({
transform (chunk, _, callback) {
pipeline(
this.conn,
this.throttleGroups.down.throttle(),
new Transform({
transform (chunk, callback) {
self.emit('download', chunk.length)
if (self.destroyed) return
callback(null, chunk)
}
}))
.pipe(this.wire)
.pipe(this.throttleGroups.up.throttle())
.pipe(new Transform({
transform (chunk, _, callback) {
}),
this.wire,
this.throttleGroups.up.throttle(),
new Transform({
transform (chunk, callback) {
self.emit('upload', chunk.length)
if (self.destroyed) return
callback(null, chunk)
}
}))
.pipe(this.conn)
}),
this.conn
)
}

/**
Expand Down

0 comments on commit cde79ed

Please sign in to comment.