smarter-buffer

0.0.2 • Public • Published

Build Status

smarter-buffer

Adds smarterConcat method the Node.js Buffer object that ignores null and undefined list items

Motivation

The Node.js Buffer.concat function balks when it encounters null or undefined items in the array.

In the Location IO project, a buffer is used to store the unprocessed data from the socket. There can be several callbacks from the socket before the data is processed. After each callback, the buffer from the socket is concatenated with the existing buffer which contains the sum of the data from previous callbacks. When using the Buffer.concat function, the problem is the first callback from the socket. The buffer containing the unprocessed data is null (or undefined).

Usage

require('smarter-buffer');

buffer1 = new Buffer("hello ");
buffer2 = new Buffer("world");
resultingBuffer = Buffer.smarterConcat([buffer1, null, undefined, buffer2]);

// resultingBuffer contains "hello world"

Readme

Keywords

none

Package Sidebar

Install

npm i smarter-buffer

Weekly Downloads

19

Version

0.0.2

License

none

Last publish

Collaborators

  • alexbirkett