UNPKG

binary-stream-replace

Version:

efficiently replace a sequence of bytes in a binary or text stream with a different sequence of bytes. Can be restricted to first n occurrences only.

24 lines (18 loc) 760 B
[![npm version](https://badge.fury.io/js/binary-stream-replace.svg)](http://badge.fury.io/js/binary-stream-replace) [![browser support](https://ci.testling.com/regular/binary-stream-replace.png)](https://ci.testling.com/regular/binary-stream-replace) binary-stream-replace === A transform-stream for Node and browsers that efficeintly replaces sequences of bytes in a binary stream. Can be restricted to replace first n occurrences only. Usage --- ``` js var ReplaceStream = require('binary-stream-replace'); // replace first 10 occurrences of byte sequence `fe fe` with // `00 00 01` var rs = ReplaceStream( new Buffer([0xfe, 0xfe]), new Buffer([0x00, 0x00, 0x01]), { maxOccurrences: 10 } ); process.stdin.pipe(rs).pipe(process.stdout); ```