Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
clever-buffer
Advanced tools
Buffer write and read utilities.
CleverBuffer adds functionality that is missing from the node Buffer class
npm install clever-buffer
NOTE: Examples below in javascript
{ CleverBufferReader } = require('clever-buffer');
Allocates a new CleverBufferReader with an internal buffer of the specified existingBuffer
var reader = new CleverBufferReader(existingBuffer, { offset: 0, noAssert: true, bigEndian: false});
Returns an Unsigned 8bit Integer from the current offset
var buf = Buffer.from([0xFF, 0x02]);
var reader = new CleverBufferReader(buf);
console.log(reader.getUInt8()); // 255
console.log(reader.getUInt8()); // 2
Returns a Signed 8bit Integer from the current offset
var buf = Buffer.from([0xFF, 0x02]);
var reader = new CleverBufferReader(buf);
console.log(reader.getInt8()); // -1
console.log(reader.getInt8()); // 2
Returns an Unsigned 16bit Integer from the current offset.
var buf = Buffer.from([0xFF, 0xFF, 0x02, 0x00]);
var reader = new CleverBufferReader(buf);
console.log(reader.getUInt16()); // 65535
console.log(reader.getUInt16()); // 2
Returns a Signed 16bit Integer from the current offset
var buf = Buffer.from([0xFF, 0xFF, 0x02, 0x00]);
var reader = new CleverBufferReader(buf);
console.log(reader.getInt16()); # -1
console.log(reader.getInt16()); # 2
Returns an Unsigned 32bit Integer from the current offset.
var buf = Buffer.from([0xFF, 0xFF, 0xFF, 0xFF]);
var reader = new CleverBufferReader(buf);
console.log(reader.getUInt32()); // 4294967295
Returns a Signed 32bit Integer from the current offset
var buf = Buffer.from([0xFF, 0xFF, 0xFF, 0xFF]);
var reader = new CleverBufferReader(buf);
console.log(reader.getInt32()); // -1
Returns an Unsigned 64bit Integer from the current offset.
The value will be returned as a string
var buf = Buffer.from([0xFF, 0xFF, 0xFF, 0xFF,0xFF, 0xFF, 0xFF, 0xFF]);
var reader = new CleverBufferReader(buf);
console.log(reader.getUInt64()); // "18446744073709551615"
Returns a Signed 64bit Integer from the current offset
The value will be returned as a string
var buf = Buffer.from([0xFF, 0xFF, 0xFF, 0xFF,0xFF, 0xFF, 0xFF, 0xFF]);
var reader = new CleverBufferReader(buf);
console.log(reader.getInt64()); // "-1"
Returns utf-8 encoded string of specified length
var buf = Buffer.from([0x48, 0x45, 0x4C, 0x4C, 0x4F]);
var reader = new CleverBufferReader(buf);
console.log(reader.getString(length: 5)); // "HELLO"
{ CleverBufferWriter } = require('clever-buffer');
Allocates a new CleverBufferWriter with an internal buffer of the specified existingBuffer
var writer = new CleverBufferWriter(existingBuffer, {offset: 0, noAssert: true, bigEndian: false});
Writes an Unsigned 8bit Integer to the specified/current offset
var buf = Buffer.alloc(2);
var writer = new CleverBufferWriter(buf);
writer.writeUInt8(255);
writer.writeUInt8(2);
console.log(buf); // [0xFF, 0x02]
Writes an signed 8bit Integer to the specified/current offset
var buf = Buffer.alloc(2);
var writer = new CleverBufferWriter(buf);
writer.writeInt8(-1);
writer.writeInt8(2);
console.log(buf); // [0xFF, 0x02]
Writes an Unsigned 16bit Integer to the specified/current offset
var buf = Buffer.alloc(4);
var writer = new CleverBufferWriter(buf);
writer.writeUInt16(65535);
writer.writeUInt16(2);
console.log(buf); // [0xFF, 0xFF, 0x02, 0x00]
Writes an Signed 16bit Integer to the specified/current offset
buf = Buffer.alloc(4);
writer = new CleverBufferWriter(buf);
writer.writeInt16(-1);
writer.writeInt16(2);
console.log(buf); // [0xFF, 0xFF, 0x02, 0x00]
Writes an Unsigned 32bit Integer to the specified/current offset
var buf = Buffer.alloc(4);
var writer = new CleverBufferWriter(buf);
writer.writeUInt32(4294967295);
console.log(buf); // [0xFF, 0xFF, 0xFF, 0xFF]
Writes an signed 32bit Integer to the specified/current offset
var buf = Buffer.alloc(4);
var writer = new CleverBufferWriter(buf);
writer.writeInt32(-1);
console.log(buf); // [0xFF, 0xFF, 0xFF, 0xFF]
value.length
for non ASCII encodings. If not specified, will default to the right number of bytes for the chosen encoding.Writes string to the buffer
var buf = Buffer.alloc(8);
var writer = new CleverBufferWriter(buf);
var len = writer.writeString("héllo");
console.log(len, buf); // 6, [0x68, 0xc3, 0xa9, 0x6c, 0x6c, 0x6f, 0x00, 0x00]
The following is common to CleverBufferReader and CleverBufferWriter (The examples only show reader)
Gets the current offset of the buffer
var buf = Buffer.from([0xFF, 0x02]);
var reader = new CleverBufferReader(buf);
console.log(reader.getOffset()); // 0
reader.getUInt8();
console.log(reader.getOffset()); // 1
reader.getUInt8();
console.log(reader.getOffset()); // 2
Skips the current offset forward the specified bytes amount
var buf = Buffer.from([0xFF, 0x02]);
var reader = new CleverBufferReader(buf);
console.log(reader.getOffset()); // 0
reader.skip(2);
console.log(reader.getOffset()); // 2
Skips to the specified offset
var buf = Buffer.from([0xFF, 0xFF, 0xFF, 0x01]);
var reader = new CleverBufferReader(buf);
console.log(reader.getOffset()); // 0
reader.skipTo(3);
console.log(reader.getOffset()); // 3
Will return the underlying buffer so you can perform actions directly on it
var buf = Buffer.from([0xFF, 0x02]);
var reader = new CleverBufferReader(buf);
console.log(reader.getBuffer()[1]); // 2
Will return a buffer slice from the start of the buffer to the current offset
var buf = Buffer.from([0xFF, 0x02]);
var reader = new CleverBufferReader(buf);
reader.getUInt8();
console.log(reader.trim()); // [0xFF]
console.log(buf); // [0xFF, 0x02]
npm test
FAQs
Buffer utilities
The npm package clever-buffer receives a total of 15 weekly downloads. As such, clever-buffer popularity was classified as not popular.
We found that clever-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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.