-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test writing chunk wile flowing with buffer
Reproduces #27, cause of npm/cli#3884
- Loading branch information
Caleb ツ Everett
committed
Dec 1, 2021
1 parent
9bfcf55
commit 7f71279
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Reproduces an issue where write is called while the stream is flowing but a | ||
// destination cannot accept all of the buffered chunks. minipass should add | ||
// the chunk to the end of the buffer instead of emitting it before the buffer | ||
// is cleared. | ||
// | ||
// This caused issues when piping make-fetch-happen stream to tar.extract | ||
// https://github.com/npm/cli/issues/3884 | ||
const Minipass = require('../') | ||
const t = require('tap') | ||
|
||
class Pauser extends Minipass { | ||
write (chunk, encoding, callback) { | ||
super.write(chunk, encoding, callback) | ||
return false | ||
} | ||
} | ||
|
||
const src = new Minipass({encoding: 'utf8'}) | ||
const pauser = new Pauser({encoding: 'utf8'}) | ||
|
||
// queue up two chunks while the src is buffering | ||
src.write('1') | ||
src.write('2') | ||
|
||
// when the src starts flowing write a third chunk | ||
src.once('resume', () => src.write('3')) | ||
|
||
// pipe the src to the pauser which will request the src stops after the first | ||
// chunk. | ||
src.pipe(pauser) | ||
|
||
src.end() | ||
|
||
// we should expect the chunks in the original order. | ||
t.resolveMatch(pauser.collect(), ['1', '2', '3'], '123') |