GeezerVison is showing github.com — stream: fix fd is null when calling clearBuffer · nodejs/node@5112306
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/streams/writable.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -733,7 +733,8 @@ function errorBuffer(state) { |
733 | 733 |
|
734 | 734 | // If there's something in the buffer waiting, then process it. |
735 | 735 | function clearBuffer(stream, state) { |
736 | | - if ((state[kState] & (kDestroyed | kBufferProcessing | kCorked | kBuffered)) !== kBuffered) { |
| 736 | + if ((state[kState] & (kDestroyed | kBufferProcessing | kCorked | kBuffered | kConstructed)) !== |
| 737 | + (kBuffered | kConstructed)) { |
737 | 738 | return; |
738 | 739 | } |
739 | 740 |
|
|
Collapse file
Copy file name to clipboard +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// Test 'uncork' for WritableStream. |
| 4 | +// Refs: https://github.com/nodejs/node/issues/50979 |
| 5 | + |
| 6 | +const common = require('../common'); |
| 7 | +const fs = require('fs'); |
| 8 | +const assert = require('assert'); |
| 9 | +const test = require('node:test'); |
| 10 | +const tmpdir = require('../common/tmpdir'); |
| 11 | + |
| 12 | +const filepath = tmpdir.resolve('write_stream.txt'); |
| 13 | +tmpdir.refresh(); |
| 14 | + |
| 15 | +const data = 'data'; |
| 16 | + |
| 17 | +test('writable stream uncork', () => { |
| 18 | + const fileWriteStream = fs.createWriteStream(filepath); |
| 19 | + |
| 20 | + fileWriteStream.on('finish', common.mustCall(() => { |
| 21 | + const writtenData = fs.readFileSync(filepath, 'utf8'); |
| 22 | + assert.strictEqual(writtenData, data); |
| 23 | + })); |
| 24 | + fileWriteStream.cork(); |
| 25 | + fileWriteStream.write(data, common.mustCall()); |
| 26 | + fileWriteStream.uncork(); |
| 27 | + fileWriteStream.end(); |
| 28 | +}); |