concatenate all data chunks that fall within a time window
concatenate all the data chunks that fall within a time window
Every time there is a write on stdin, wait 1 second to buffer up more data and concatenate everything in that 1 second window together:
var timeWindow = ;var through = ;var tw = ;processstdin;
$ (echo -n abc; sleep 0.5; echo -n def; sleep 2; echo -n hi; sleep 0.1; echo -n jkl) | node tw.js'abcdef''hijkl'
'def' are only separated by 0.5 seconds, so they get put into the
same chunk. The pause of 2 seconds breaks the chunk and then
'jkl' because only 0.1 seconds elapsed between them.
var timeWindow =
Create a new time window through stream
tw that on a write will wait
milliseconds to concatenate more writes together in the same batch.
tw will output arrays of objects with all the
objects that were written during the time window. Otherwise,
tw will output
buffers with the concatenated data written during the time window.
With npm do:
npm install time-window-stream