# bufferjs

> Pure JavaScript Buffer utils.

Latest version **3.0.1** (published 2016-06-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install bufferjs
pnpm add bufferjs
yarn add bufferjs
bun add bufferjs
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2016-06-08 |
| First published | 2011-01-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.2.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 32 |
| Author | AJ ONeal |
| Maintainers | alexbooker, coolaj86 |
| Keywords | util, buffer, chunk, indexOf |

## Links

- npm: https://www.npmjs.com/package/bufferjs
- Repository: https://github.com/coolaj86/node-bufferjs
- Homepage: https://github.com/coolaj86/node-bufferjs#readme
- Issues: https://github.com/coolaj86/node-bufferjs/issues
- npm.io page: https://npm.io/package/bufferjs

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 3.0.1 (latest) — 2016-06-08
- 3.0.0 — 2016-06-03
- 2.0.0 — 2012-10-26
- 1.2.1 — 2012-10-26
- 1.2.0 — 2012-10-26
- 1.1.0 — 2012-03-05
- 1.0.2 — 2012-02-16
- 1.0.1 — 2011-05-18
- 1.0.0 — 2011-03-28
- 0.2.3 — 2011-03-23
- 0.2.1 — 2011-02-27
- 0.2.0 — 2011-01-11

## README

node-bufferjs
====

Pure JavaScript utils which extend the global `Buffer` object in Node.JS.

    npm install bufferjs

API
====

    require('bufferjs');

  * buffer.addChunk(chunk)
  * Buffer.indexOf(haystack, needle, startIndex)
  * buffer.indexOf(needle, startIndex)

buffer.addChunk(chunk)
----

Adds a buffer `chunk` to `buffer`.

Returns `true` when full

Returns `new Buffer` if buffer overflows

    require('bufferjs/add-chunk');

    var buffer = new Buffer(9),
      overflow;

    buffer.addChunk(new Buffer("abc"));
    buffer.addChunk(new Buffer("def"));
    buffer.toString(); // "abcdef???"
    // Note: "???" is whatever random garbage was internally `malloc`d.    


    console.log(true === buffer.addChunk(new Buffer("ghi"))); // true, buffer is full
    // true when buffer is full


    // adding past the index will throw an error
    overflow = buffer.addChunk(new Buffer("jkl"));
    buffer.toString(); // abcdefghi
    overflow.toString(); // jkl


Buffer.indexOf(haystack, needle, startIndex)
----

Searches the given _haystack_ Buffer for the given _needle_ Buffer. Returns the index
of the first occurence of `needle`, or `-1` if the pattern was not found. `needle` may also
be a regular String, for convenience. `startIndex` tells at which index to begin the search.

    require('bufferjs/indexOf');

    var haystack = new Buffer(10);
    var needle = '\r\n';
    haystack.write(needle, 5);
    
    Buffer.indexOf(haystack, needle); // 5
    Buffer.indexOf(haystack, 'NOT_IN_HAYSTACK'); // -1


buffer.indexOf(needle, startIndex)
----

OO-style variant of `Buffer.indexOf`. `this` is the _haystack_, and only _needle_ needs
to be supplied when called.

    require('bufferjs/indexOf');
  
    var haystack = new Buffer(10);
    var needle = '\r\n';
    haystack.write(needle, 5);

    haystack.indexOf(needle); // 5
    haystack.indexOf('NOT_IN_HAYSTACK'); // -1

Buffer.concat(list, [totalLength])
----

**Deprecated**: Node.JS 0.8.x has Buffer.concat built-in (compatible).
See http://nodejs.org/api/buffer.html#buffer_class_method_buffer_concat_list_totallength

**WARNING**: v1.2.1 uses NON-NATIVE concat. v2.0.0 uses NATIVE concat ONLY.

Returns a new `Buffer` with the contents of all buffers in the `Array`.

    require('bufferjs/concat');

    var buffers = [
            new Buffer("abc")
          , new Buffer("def")
          , new Buffer("ghi")
        ]
      , buffer
      ;

    buffer = Buffer.concat(buffers);
    console.log(buffer.toString('utf8'));
    // abcdefghi

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