Skip to content

Commit

Permalink
Fix empty files on Node.js 14.x
Browse files Browse the repository at this point in the history
fixes #226
closes #228
  • Loading branch information
dougwilson committed Jul 9, 2020
1 parent f63f47e commit 6afaf7a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
unreleased
==========

* Fix empty files on Node.js 14.x
* Replace `fd-slicer` module with internal transform stream
* deps: http-errors@~1.8.0
- Fix error creating objects in some environments
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ util.inherits(Form, stream.Writable);
function Form(options) {
var opts = options || {}
var self = this;
stream.Writable.call(self);
stream.Writable.call(self, { emitClose: false })

self.error = null;

Expand Down
22 changes: 18 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,16 @@ var standaloneTests = [
// verification that error event implies unpipe call
assert.ok(err);
assert.ok(unpiped, 'req was unpiped');
assert.equal(req._readableState.flowing, false, 'req not flowing');
assert.equal(req._readableState.pipesCount, 0, 'req has 0 pipes');

assert.ok(!isReadableStreamFlowing(req), 'req not flowing')
assert.equal(getReadableStreamPipeCount(req), 0, 'req has 0 pipes')
cb();
})

form.parse(req)
assert.equal(req._readableState.flowing, true, 'req flowing');
assert.equal(req._readableState.pipesCount, 1, 'req has 1 pipe');

assert.ok(isReadableStreamFlowing(req), 'req flowing')
assert.equal(getReadableStreamPipeCount(req), 1, 'req has 1 pipe')
}
},
{
Expand Down Expand Up @@ -1392,6 +1394,18 @@ function computeSha1(o) {
};
}

function getReadableStreamPipeCount (stream) {
var count = stream._readableState.pipesCount

return typeof count !== 'number'
? stream._readableState.pipes.length
: count
}

function isReadableStreamFlowing (stream) {
return Boolean(stream._readableState.flowing)
}

function uploadFixture(server, path, cb) {
server.once('request', function(req, res) {
var done = false
Expand Down

0 comments on commit 6afaf7a

Please sign in to comment.