# mutable-buffer

> A mutable buffer library for node.js

Latest version **4.0.2** (published 2021-08-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install mutable-buffer
pnpm add mutable-buffer
yarn add mutable-buffer
bun add mutable-buffer
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.2 |
| Published | 2021-08-27 |
| First published | 2015-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10.16 |
| Dependencies | 1 |
| Unpacked size | 37.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | taoyuan |
| Maintainers | towyuan |
| Keywords | buffer, mutable, writable, node, nodejs |

## Links

- npm: https://www.npmjs.com/package/mutable-buffer
- Repository: https://github.com/taoyuan/mutable-buffer
- Issues: https://github.com/taoyuan/mutable-buffer/issues
- npm.io page: https://npm.io/package/mutable-buffer

## Dependencies (1)

- [buffer](https://npm.io/package/buffer.md) ^6.0.3

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 4.0.2 (latest) — 2021-08-27
- 3.0.0-0 (next) — 2020-09-20
- 4.0.1 — 2021-08-27
- 3.0.0 — 2020-09-27
- 2.2.5 — 2020-09-19
- 2.2.4 — 2020-09-19
- 2.2.3 — 2020-09-19
- 2.2.2 — 2020-09-19
- 2.2.1 — 2020-09-19
- 2.2.0 — 2020-09-19
- 2.1.1 — 2018-05-03
- 2.1.0 — 2018-05-02
- 2.0.3 — 2016-03-26
- 2.0.2 — 2016-03-26
- 2.0.1 — 2016-03-24
- … 4 more at https://npm.io/package/mutable-buffer/versions

## README

# mutable-buffer

[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]
[![Coverage percentage][coveralls-image]][coveralls-url]

> A mutable buffer library for both node.js and browser

## Install

```sh
$ npm install mutable-buffer
```

## Usage

### Basic usage

```js
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.render();

// return a fresh Buffer instance
result = buffer.render(true);

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

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

// clear manual
buffer.clear();
```

### Trim null characters

```js
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]
```

## Use in browser

`mutable-buffer` introduced [feross/buffer](https://github.com/feross/buffer) to support for the browser out of box in
`v3.0`.

A front-end packaging tool like `webpack` will recognize the `browser` entry defined in `pacakge.json` and use the
browser version of `mutable-buffer` by default.

You can print `MutableBuffer.target` to confirm that.

```js
// in node
console.log(MutableBuffer.target); // => 'node'

// in browser
console.log(MutableBuffer.target); // => 'web'
```

## License

MIT © [taoyuan](https://github.com/taoyuan)

[npm-image]: https://badge.fury.io/js/mutable-buffer.svg
[npm-url]: https://npmjs.org/package/mutable-buffer
[travis-image]: https://travis-ci.org/taoyuan/mutable-buffer.svg?branch=master
[travis-url]: https://travis-ci.org/taoyuan/mutable-buffer
[coveralls-image]: https://coveralls.io/repos/taoyuan/mutable-buffer/badge.svg
[coveralls-url]: https://coveralls.io/r/taoyuan/mutable-buffer

---
_Source: https://npm.io/package/mutable-buffer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
