
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
fast-buffer
Advanced tools
A faster way of handling Buffers, or so I say.
Notice: This is NOT a real buffer. But works faster for certain use cases.
new Buffer from buffer x 260,001 ops/sec ±2.06% (79 runs sampled)
new Buffer from byte array x 215,698 ops/sec ±2.31% (73 runs sampled)
new Buffer from size x 277,193 ops/sec ±2.09% (91 runs sampled)
new fastBuffer from buffer x 189,329 ops/sec ±2.73% (74 runs sampled)
new fastBuffer from byte array x 3,486,441 ops/sec ±0.28% (93 runs sampled)
new fastBuffer from size x 1,726,193 ops/sec ±0.40% (97 runs sampled)
new fasterBuffer from buffer x 212,569 ops/sec ±2.41% (81 runs sampled)
new fasterBuffer from byte array x 7,866,879 ops/sec ±0.19% (99 runs sampled)
new fasterBuffer from size x 14,760,543 ops/sec ±0.42% (100 runs sampled)
$ npm install fast-buffer --save
Installing the latest version
$ npm install git+https://github.com/majimboo/node-fast-buffer.git
or for those without git
$ npm install http://github.com/majimboo/node-fast-buffer/tarball/master
var fastBuffer = require('fast-buffer').fastBuffer;
var buf = new fastBuffer(5);
buf.writeUInt8(0x01);
buf.writeUInt8(0x02);
buf.writeUInt8(0x03);
buf.writeUInt8(0x04);
buf.writeUInt8(0x05);
var buf = new fastBuffer([0x01, 0x02, 0x03, 0x04, 0x05]);
var buf = new fastBuffer(new Buffer([0x01, 0x02, 0x03, 0x04, 0x05]));
// create new buffer
var buf = new fastBuffer([0x05, 0x07, 0x02, 0x05, 0x09]);
// do some processing like
// - encrypt the buffer
for (var i = 0; i < buf.length; i++) {
buf[i] ^= 0x02;
buf[i] ^= 0x03;
buf[i] ^= 0x01;
buf[i] ^= 0x02;
buf[i] ^= 0x03;
}
// - append the size
var buf_w_size = new fastBuffer([0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
buf.copy(buf_w_size, 1);
buf_w_size.writeUInt8(buf_w_size.length, 0);
// send data
socket.write(buf_w_size.encode());
var fasterBuffer = require('fast-buffer').fasterBuffer;
var mainBuf = new fasterBuffer(5);
var buf = mainBuf.bytes;
buf.writeUInt8(0x01);
buf.writeUInt8(0x02);
buf.writeUInt8(0x03);
buf.writeUInt8(0x04);
buf.writeUInt8(0x05);
var buf = new fasterBuffer([0x01, 0x02, 0x03, 0x04, 0x05]);
var buf = new fasterBuffer(new Buffer([0x01, 0x02, 0x03, 0x04, 0x05]));
I needed a fast protocol for a MMOG server I was developing in Node.JS. My workflow was creating buffers, writing bits into it, encrypting,
then sent the data with socket.write().
I noticed the performance difference when I was doing some benchmark which results can be seen here.
How slow?
var buf = new Buffer([0x00, 0x01, 0x03, 0x04]);
socket.write(buf);
When benchmarked gives:
buffer x 112,474 ops/sec ±11.07% (52 runs sampled)
As UTF-8 strings, it would be like
var buf = '\x00\x01\x03\x04';
socket.write(buf);
Now let us see some benchmark:
utf-8 x 1,629,796 ops/sec ±29.13% (54 runs sampled)
You can try the benchmark here by running
node benchmark/buffer-vs-utf8
As you can see, there is a huge difference in speed, using utf-8 strings gives you about x14 more performance than using buffers.
FAQs
A faster way of handling buffers.
The npm package fast-buffer receives a total of 5 weekly downloads. As such, fast-buffer popularity was classified as not popular.
We found that fast-buffer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.