diff --git a/src/duplex.js b/src/duplex.js index ac7b9b7..ff4c040 100644 --- a/src/duplex.js +++ b/src/duplex.js @@ -1,6 +1,7 @@ const { Readable, Writable, Duplex } = require('stream') const getIterator = require('get-iterator') const Fifo = require('p-fifo') +const { Buffer } = require('buffer') const END_CHUNK = Buffer.alloc(0) module.exports = function toDuplex (duplex, options) { diff --git a/test/helpers/streams.js b/test/helpers/streams.js index 55b1938..4ec4209 100644 --- a/test/helpers/streams.js +++ b/test/helpers/streams.js @@ -4,7 +4,8 @@ const { Writable, pipeline } = require('stream') function pipe (...streams) { return new Promise((resolve, reject) => { pipeline(...streams, err => { - if (err) return reject(err) + // work around bug in node to make 'should end mid stream' test pass - https://github.com/nodejs/node/issues/23890 + if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') return reject(err) resolve() }) }) diff --git a/test/transform.test.js b/test/transform.test.js index 173474e..9982b2b 100644 --- a/test/transform.test.js +++ b/test/transform.test.js @@ -1,5 +1,6 @@ const test = require('ava') const { Readable } = require('stream') +const { Buffer } = require('buffer') const toStream = require('../') const { collect } = require('./helpers/streams') const { randomInt, randomBytes } = require('./helpers/random')