# replace-buffer **Repository Path**: mirrors_kevva/replace-buffer ## Basic Information - **Project Name**: replace-buffer - **Description**: Replace matches in a Buffer - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-25 - **Last Updated**: 2026-05-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # replace-buffer [![Build Status](https://travis-ci.org/kevva/replace-buffer.svg?branch=master)](https://travis-ci.org/kevva/replace-buffer) > Replace matches in a Buffer ## Install ``` $ npm install replace-buffer ``` ## Usage ```js const replaceBuffer = require('replace-buffer'); const input = Buffer.from('My friend has a dog. I want a dog too!'); replaceBuffer(input, 'dog', 'unicorn').toString(); //=> 'My friend has a unicorn. I want a unicorn too!' ``` ## API ### replaceBuffer(input, needle, replacement, [options]) Returns a new `Buffer` with all needle matches replaced with replacement. #### input Type: `Buffer` `Buffer` to work on. #### needle Type: `string` String to match in `input`. #### replacement Type: `string` `Function` Replacement for needle matches. If a function, it receives the following arguments; the `needle`, the match count, and the `input`: ```js replaceBuffer(Buffer.from('Foo Unicorn Bar'), 'Unicorn', (needle, matchCount, input) => `${needle}❤️`); //=> 'Foo Unicorn❤️ Bar' ``` #### options Type: `Object` ##### fromIndex Type: `number`
Default: `0` Index at which to start replacing. ## Related * [splice-buffer](https://github.com/kevva/splice-buffer) - Remove or replace part of a `Buffer` like `Array#splice` ## License MIT © [Kevin Mårtensson](http://github.com/kevva)