PortablePosPrinterHamekara/node_modules/mutable-buffer
mehranz c2686e7110 initial commit 2025-11-15 13:33:50 +03:30
..
dist initial commit 2025-11-15 13:33:50 +03:30
src initial commit 2025-11-15 13:33:50 +03:30
LICENSE initial commit 2025-11-15 13:33:50 +03:30
README.md initial commit 2025-11-15 13:33:50 +03:30
package.json initial commit 2025-11-15 13:33:50 +03:30

README.md

mutable-buffer

NPM version Build Status Coverage percentage

A mutable buffer library for both node.js and browser

Install

$ npm install mutable-buffer

Usage

Basic usage

const {MutableBuffer} = require('mutable-buffer');

const buffer = new MutableBuffer(/* initialSize, blockSize */);

// use it like node Buffer
buffer.writeUInt8(8);
buffer.writeUInt16LE(0x1234);

buffer.write('hello');
buffer.write(otherBuffer);

// write a string to the buffer utf8 encoded and adds a null character (\0) at the end.
buffer.writeCString('hello');

// write a char
buffer.writeChar('a');

// get size of mutable buffer
buffer.size();

// get current capacity of mutable buffer
buffer.capacity();

// return a sliced Buffer instance
result = buffer.join();

// or return a sliced Buffer instance and clear buffer
result = buffer.flush();

// clear manual
buffer.clear();

Trim null characters

const {MutableBuffer} = require('mutable-buffer');

const buffer = new MutableBuffer(/* initialSize, blockSize */);

// trimLeft
buffer.write([0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00]);
buffer.trimLeft().flush(); // => [0x01, 0x02, 0x00, 0x00, 0x00]

// trimRight
buffer.write([0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00]);
buffer.trimRight().flush(); // => [0x00, 0x00, 0x01, 0x02]

// trim
buffer.write([0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00]);
buffer.trim().flush(); // => [0x01, 0x02]

License

MIT © taoyuan