eugeneware / eugeneware/replacestream
Any way to flush left context?
- Dominant language
- JavaScript
- Stars
- 177
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
Consider the following toy example:
```js
const replaceStream = require('replacestream');
const { PassThrough } = require('stream');
const input = new PassThrough(), param = new PassThrough(), out = new PassThrough();
input.end('hello{{sep}}world');
param.end(', ');
const replace = replaceStream('{{sep}}', match => {
replace.pause();
param.on('end', () => replace.resume());
param.pipe(out, { end: false });
return '';
});
input.pipe(replace).pipe(out);
```
What I was expecting `out` to contain: `hello, world`
What `out` actually contained: `, helloworld`
Without knowing the internals, my best guess is that the stream before the match is still being held on to when `pause` is called, making chunks arrive in `out` out of the expected order. Is there a way to force the left context out beforehand?
Contributor guide
Research direction
Reproduce the reported example in issue #42 using replacestream, PassThrough, and Node.js streams. Trace how data preceding {{sep}} is emitted when the replacement callback pauses the stream, then define completion as preserving the expected hello, world ordering without breaking chunk-boundary handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100