Skip to content

Any way to flush left context? #42

Description

@IanDavey

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions