Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Group Node.js Buffers together and extract the parts you need.
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
ftest
test
.gitignore
.travis.yml
LICENSE
README.md
buffer-group.js
index.js
package.json

README.md

buffer-group

Build Status

Group Node.js Buffers together and extract the parts you need. This is useful, for example, when dealing with framing data and the frame size isn't known in advance.

Example

Get access to the BufferGroup:

var BufferGroup = require('buffer-group'),
    bg = new BufferGroup();

Add buffers to the group:

bg.push(new Buffer(10));    // bg.length === 10
bg.push(new Buffer(5));     // bg.length === 15

As you add Buffers to the group, the BufferGroup length grows accordingly to account for all the buffers in it.

You can then extract a fixed size of data from the group:

var eb = bg.extract(12); // Extract 12 bytes from the BufferGroup.
// eb.length === 12
// bg.length === 3

Note that the BufferGroup will remove the number of bytes requested and keep any existing data there. You can then go ahead and push more data in or extract more data as you see fit. The length property should reflect the current size.

Install

npm install buffer-group

Tests

npm test

License

MIT License

Something went wrong with that request. Please try again.