Skip to content

Commit 6afaf7a

Browse files
committed
Fix empty files on Node.js 14.x
fixes #226 closes #228
1 parent f63f47e commit 6afaf7a

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
unreleased
22
==========
33

4+
* Fix empty files on Node.js 14.x
45
* Replace `fd-slicer` module with internal transform stream
56
* deps: http-errors@~1.8.0
67
- Fix error creating objects in some environments

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ util.inherits(Form, stream.Writable);
5050
function Form(options) {
5151
var opts = options || {}
5252
var self = this;
53-
stream.Writable.call(self);
53+
stream.Writable.call(self, { emitClose: false })
5454

5555
self.error = null;
5656

test/test.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,16 @@ var standaloneTests = [
348348
// verification that error event implies unpipe call
349349
assert.ok(err);
350350
assert.ok(unpiped, 'req was unpiped');
351-
assert.equal(req._readableState.flowing, false, 'req not flowing');
352-
assert.equal(req._readableState.pipesCount, 0, 'req has 0 pipes');
351+
352+
assert.ok(!isReadableStreamFlowing(req), 'req not flowing')
353+
assert.equal(getReadableStreamPipeCount(req), 0, 'req has 0 pipes')
353354
cb();
354355
})
355356

356357
form.parse(req)
357-
assert.equal(req._readableState.flowing, true, 'req flowing');
358-
assert.equal(req._readableState.pipesCount, 1, 'req has 1 pipe');
358+
359+
assert.ok(isReadableStreamFlowing(req), 'req flowing')
360+
assert.equal(getReadableStreamPipeCount(req), 1, 'req has 1 pipe')
359361
}
360362
},
361363
{
@@ -1392,6 +1394,18 @@ function computeSha1(o) {
13921394
};
13931395
}
13941396

1397+
function getReadableStreamPipeCount (stream) {
1398+
var count = stream._readableState.pipesCount
1399+
1400+
return typeof count !== 'number'
1401+
? stream._readableState.pipes.length
1402+
: count
1403+
}
1404+
1405+
function isReadableStreamFlowing (stream) {
1406+
return Boolean(stream._readableState.flowing)
1407+
}
1408+
13951409
function uploadFixture(server, path, cb) {
13961410
server.once('request', function(req, res) {
13971411
var done = false

0 commit comments

Comments
 (0)