Skip to content

Commit df0e72c

Browse files
committed
Fix passthrough streams
1 parent a467e81 commit df0e72c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

index.js

+6
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ exports.Transform = class Transform extends stream.Transform {
186186

187187
if (this._transform !== stream.Transform.prototype._transform) {
188188
this._transform = transform.bind(this, this._transform)
189+
} else {
190+
this._transform = passthrough
189191
}
190192
}
191193

@@ -271,6 +273,10 @@ function destroy (destroy, cb) {
271273
destroy.call(this, stream.getStreamError(this), cb)
272274
}
273275

276+
function passthrough (data, cb) {
277+
cb(null, data.chunk)
278+
}
279+
274280
function byteLengthWritable (data) {
275281
return data.chunk.byteLength
276282
}

test.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const test = require('brittle')
2-
const { Readable, Writable, Duplex, Transform } = require('.')
2+
const { Readable, Writable, Duplex, Transform, PassThrough } = require('.')
33

44
test('readable', (t) => {
55
t.plan(3)
@@ -445,3 +445,29 @@ test('transform, write with encoding', (t) => {
445445

446446
stream.write('\xab\xcd', 'ascii')
447447
})
448+
449+
test('passthrough', (t) => {
450+
t.plan(4)
451+
452+
const writable = new Writable({
453+
write (data, encoding, cb) {
454+
t.is(this, writable)
455+
t.alike(data, Buffer.from('hello'))
456+
t.is(encoding, 'buffer')
457+
}
458+
})
459+
460+
const readable = new Readable({
461+
read (size) {
462+
t.is(this, readable)
463+
464+
this.push('hello')
465+
this.push(null)
466+
}
467+
})
468+
469+
const passthrough = new PassThrough()
470+
471+
readable.pipe(passthrough).pipe(writable)
472+
readable.read()
473+
})

0 commit comments

Comments
 (0)