eugeneware / eugeneware/replacestream

Any way to flush left context?

Open
#42 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.