Skip to content

Commit ca2ab09

Browse files
committed
chore: remove double-pipe
1 parent e5fdd3e commit ca2ab09

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

package-lock.json

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@
8181
"abortable-iterator": "^5.0.1",
8282
"denque": "^2.1.0",
8383
"it-length-prefixed": "^9.0.4",
84-
"it-map": "^3.0.5",
85-
"it-merge": "^3.0.3",
8684
"it-pipe": "^3.0.1",
8785
"it-pushable": "^3.2.3",
8886
"multiformats": "^13.0.1",

src/stream.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { abortableSource } from 'abortable-iterator'
22
import { encode, decode } from 'it-length-prefixed'
3-
import map from 'it-map'
4-
import merge from 'it-merge'
53
import { pipe } from 'it-pipe'
64
import { pushable, type Pushable } from 'it-pushable'
75
import type { Stream } from '@libp2p/interface'
@@ -18,24 +16,17 @@ interface InboundStreamOpts {
1816
}
1917

2018
export class OutboundStream {
21-
private readonly pushable: Pushable<Uint8Array>
22-
private readonly lpPushable: Pushable<Uint8ArrayList>
19+
private readonly pushable: Pushable<Uint8Array | Uint8ArrayList>
2320
private readonly closeController: AbortController
2421
private readonly maxBufferSize: number
2522

2623
constructor (private readonly rawStream: Stream, errCallback: (e: Error) => void, opts: OutboundStreamOpts) {
27-
this.pushable = pushable({ objectMode: false })
28-
this.lpPushable = pushable({ objectMode: false })
24+
this.pushable = pushable()
2925
this.closeController = new AbortController()
3026
this.maxBufferSize = opts.maxBufferSize ?? Infinity
3127

3228
pipe(
33-
abortableSource(
34-
merge(
35-
this.lpPushable,
36-
map(this.pushable, buf => encode.single(buf))
37-
), this.closeController.signal, { returnOnAbort: true }
38-
),
29+
abortableSource(this.pushable, this.closeController.signal, { returnOnAbort: true }),
3930
this.rawStream
4031
).catch(errCallback)
4132
}
@@ -51,24 +42,23 @@ export class OutboundStream {
5142
throw Error(`OutboundStream buffer full, size > ${this.maxBufferSize}`)
5243
}
5344

54-
this.pushable.push(data)
45+
this.pushable.push(encode.single(data))
5546
}
5647

5748
/**
5849
* Same to push() but this is prefixed data so no need to encode length prefixed again
5950
*/
6051
pushPrefixed (data: Uint8ArrayList): void {
61-
if (this.lpPushable.readableLength > this.maxBufferSize) {
52+
if (this.pushable.readableLength > this.maxBufferSize) {
6253
throw Error(`OutboundStream buffer full, size > ${this.maxBufferSize}`)
6354
}
64-
this.lpPushable.push(data)
55+
this.pushable.push(data)
6556
}
6657

6758
async close (): Promise<void> {
6859
this.closeController.abort()
6960
// similar to pushable.end() but clear the internal buffer
7061
await this.pushable.return()
71-
await this.lpPushable.return()
7262
await this.rawStream.close()
7363
}
7464
}

0 commit comments

Comments
 (0)