1.0.1 • Published 7 years ago

stream-buffer-replace-up v1.0.1

Weekly downloads
60
License
MIT
Repository
github
Last release
7 years ago

stream-buffer-replace-up Build Status

Efficient streaming find and replace. Buffer based and boundary aware.

Note: This repository is an updated fork (Node >= 6) from stream-buffer-replace.

yarn add stream-buffer-replace-up

Advantages

  • Never converts Buffers to strings.
  • Only supports exact matching not patterns / regexs.
  • Finds matches that span chunk boundaries.
  • Finds matches that are bigger than a single chunk.

Usage

Example using strings:

const fs = require('fs')
const replace = require('stream-buffer-replace-up')

fs.writeFileSync('example.txt', 'hello world')

const stream = fs.createReadStream('example.txt')
stream
  .pipe(replace('hello', 'goodbye'))
  .pipe(process.stdout);

// => goodbye world

Example using buffers:

const fs = require('fs');
const replace = require('stream-buffer-replace-up')

fs.writeFileSync('example.txt', 'hello world')

const stream = fs.createReadStream('example.txt')
const replacer = replace(Buffer.from('hello'), Buffer.from('goodbye'))

stream
  .pipe(replace(
    Buffer.from('hello'),
    Buffer.from('goodbye')
  ))
  .pipe(process.stdout)

// => goodbye world

Tests

yarn
yarn test

Contributions welcome.