buffer-splice
Splice a buffer.. like array and string splice
Installation
npm i --save buffer-splice
Usage
splice(buffer, [start], [count], [...insert])
Splice a buffer
- @param {Buffer|Object} buffer input buffer or opts: { buffer: }
- @param {Integer} [start] default: buffer.length
- @param {Integer} [count] default: buffer.length
- @param {Buffer,String,Number,Object,Array} [...items] items to insert into buffer (will be casted to buffer)
- @param {Integer} [count] default: buffer.length
- @return {Buffer} modified buffer of removed buffer if
opts
is passed
Examples
var splice = var buffer = 'helloworld' // new Buffer('helloworld') // new Buffer('hello') // new Buffer('helloFOO') // Want the removed buffer too?// Pass `opts` and splice will work more like `Array.splice`// Unlike Arrays, Buffers cannot be modified directly.// When you pass an `opts` w/ `buffer` property `buffer-splice` can update the `buffer` reference. var opts = buffer: buffervar removed = // removed: new Buffer('elloworld')optsbuffer // modified: new Buffer('h') // ref was changed
More Examples
// buffer-splice supports all types for items,// it uses cast-buffer to cast `items` to buffers // new Buffer('hello') // new Buffer('helloFOO') // new Buffer('helloFOO') // new Buffer('hello10') // new Buffer('hello["array"]') // new Buffer('hello{"object":true}') // new Buffer('helloFOO10QUX')
License
MIT