streamsearch icon indicating copy to clipboard operation
streamsearch copied to clipboard

make it writable stream?

Open sidorares opened this issue 12 years ago • 6 comments

Is there any reason why you use push('chunk') as an api instead of write? I'd like to be able to use search as a stream:

var cmd = cp.spawn(...);
   var s = new StreamSearch('some text');
   cmd.stdout.pipe(s);
   cmd.stdout.pipe(process.stdout);
   s.once('info', function(info) {
     console.log(info);
   });

sidorares avatar Nov 18 '13 00:11 sidorares

:+1: to this!

benjamn avatar Oct 09 '14 17:10 benjamn

The reason is that it was originally written in 2012, well before streams2 and when writing a stream implementation by hand was a pain :-)

mscdex avatar Oct 09 '14 19:10 mscdex

Here is a hacky solution for this:

var cmd = cp.spawn(...);
var s = new StreamSearch('some text');
s.write = s.end = s.push.bind(s);
cmd.stdout.pipe(s);
cmd.stdout.pipe(process.stdout);
s.once('info', function(info) {
  console.log(info);
});

yf-hk avatar Jun 22 '16 03:06 yf-hk

@mscdex would you accept a PR to make it a writable stream?

terales avatar Dec 30 '17 21:12 terales

Would rather wish for something that's more based upon iterators that's more node/deno/browser friendlier. no need to involve NodeJS streams.

for (const chunk of new StreamSearch(iterable)) {
  ...
}

Also would prefer Uint8array instead of using node Buffer

jimmywarting avatar Jun 16 '23 19:06 jimmywarting

I forked and swapped out Buffer for Uint8Array and added web streams (i.e. async iterable): https://github.com/alanshaw/streamsearch-web - also types!

alanshaw avatar May 22 '24 13:05 alanshaw