Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to flush left context? #42

Open
IanDavey opened this issue Sep 8, 2020 · 0 comments
Open

Any way to flush left context? #42

IanDavey opened this issue Sep 8, 2020 · 0 comments

Comments

@IanDavey
Copy link

IanDavey commented Sep 8, 2020

Hello,

Consider the following toy example:

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant