Skip to content

Commit

Permalink
fix: add buffer require (#4)
Browse files Browse the repository at this point in the history
* fix: add buffer require

Future versions of webpack will not bundle node internals so we have to `require` them as they won't be globals any more.

Weirdly `buffer` was already a dep of this module but wasn't used in the actual source 🤷‍♂️

* fix: work around bug in node that makes writable test fail

Exiting an async iterator in a pipline early causes a `ERR_STREAM_PREMATURE_CLOSE`
to be thrown.

This should be fixed in a future node release: nodejs/node#23890
  • Loading branch information
achingbrain authored Jul 2, 2020
1 parent 7e2390f commit 6136e12
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/duplex.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion test/helpers/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand Down
1 change: 1 addition & 0 deletions test/transform.test.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down

0 comments on commit 6136e12

Please sign in to comment.