diff --git a/HISTORY.md b/HISTORY.md index 59d62a3..8e60bd2 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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 diff --git a/index.js b/index.js index 550561a..9e2d997 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/test/test.js b/test/test.js index 55c138f..8bf82a8 100644 --- a/test/test.js +++ b/test/test.js @@ -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') } }, { @@ -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