
Security News
/Research
Popular node-ipc npm Package Infected with Credential Stealer
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
@devgrid/smartbuffer
Advanced tools
An enhanced and modernized version of ByteBuffer.js for Node.js with TypeScript support, improved performance, and additional features.
While SmartBuffer is primarily optimized for Node.js, it can be used in browsers through modern bundlers like webpack, Rollup, or esbuild. Here are a few things to keep in mind:
// webpack/rollup will handle the Buffer polyfill automatically
import { SmartBuffer } from '@devgrid/smartbuffer';
// webpack.config.js
module.exports = {
resolve: {
fallback: {
"buffer": require.resolve("buffer/")
}
}
};
// Your application code
import { Buffer } from 'buffer';
import { SmartBuffer } from '@devgrid/smartbuffer';
// Now you can use SmartBuffer in the browser
const buffer = new SmartBuffer();
buffer.writeString("Hello Browser!");
npm install @devgrid/smartbuffer
# or
yarn add @devgrid/smartbuffer
import { SmartBuffer } from '@devgrid/smartbuffer';
// Create a new buffer
const buffer = new SmartBuffer();
// Write some data
buffer
.writeInt32LE(12345)
.writeString("Hello World")
.writeFloat64BE(3.14);
// Reset read position
buffer.reset();
// Read data back
const number = buffer.readInt32LE(); // 12345
const string = buffer.readString(11); // "Hello World"
const float = buffer.readFloat64BE(); // 3.14
const buffer = new SmartBuffer();
// Integer types
buffer.writeInt8(1);
buffer.writeInt16LE(2);
buffer.writeInt32BE(3);
buffer.writeUInt64LE(4);
// Floating point
buffer.writeFloatLE(1.1);
buffer.writeDoubleBE(2.2);
// BigInt support
buffer.writeBigIntLE(BigInt("9007199254740991"));
// Strings with various encodings
buffer.writeString("Hello"); // UTF8
buffer.writeCString("World"); // Null-terminated
buffer.writeVString("!"); // Length-prefixed
const buffer = new SmartBuffer();
// Write variable length integers
buffer.writeVarint32(1234);
buffer.writeVarint64(9007199254740991);
// Write zigzag encoded variants
buffer.writeVarint32ZigZag(-1234);
buffer.writeVarint64ZigZag(-9007199254740991);
const buffer = new SmartBuffer();
// Append data
buffer.write("Hello");
buffer.append(" World");
// Slice and copy
const slice = buffer.slice(0, 5);
const copy = buffer.copy();
// Compact and resize
buffer.compact();
buffer.resize(1024);
// Convert to different formats
const nodeBuffer = buffer.toBuffer();
const arrayBuffer = buffer.toArrayBuffer();
const base64 = buffer.toBase64();
const hex = buffer.toHex();
const buffer = new SmartBuffer();
// BitSet operations
buffer.writeBitSet([true, false, true]);
// Debug output
console.log(buffer.toDebug());
// Concatenate multiple buffers
const combined = SmartBuffer.concat([buffer1, buffer2, buffer3]);
// Handle different endianness
buffer.writeInt32LE(12345); // Little-endian
buffer.writeInt32BE(12345); // Big-endian
new SmartBuffer(capacity?: number, noAssert?: boolean)
capacity: Initial buffer size (default: 64)noAssert: Skip argument validation for better performance (default: false)| Method | Description |
|---|---|
readInt8() | Read 8-bit signed integer |
readUInt8() | Read 8-bit unsigned integer |
readInt16LE/BE() | Read 16-bit signed integer |
readUInt16LE/BE() | Read 16-bit unsigned integer |
readInt32LE/BE() | Read 32-bit signed integer |
readUInt32LE/BE() | Read 32-bit unsigned integer |
readBigIntLE/BE() | Read 64-bit signed BigInt |
readFloatLE/BE() | Read 32-bit float |
readDoubleLE/BE() | Read 64-bit float |
readString() | Read UTF-8 string |
readCString() | Read null-terminated string |
readVString() | Read length-prefixed string |
readVarint32/64() | Read variable-length integer |
| Method | Description |
|---|---|
writeInt8() | Write 8-bit signed integer |
writeUInt8() | Write 8-bit unsigned integer |
writeInt16LE/BE() | Write 16-bit signed integer |
writeUInt16LE/BE() | Write 16-bit unsigned integer |
writeInt32LE/BE() | Write 32-bit signed integer |
writeUInt32LE/BE() | Write 32-bit unsigned integer |
writeBigIntLE/BE() | Write 64-bit signed BigInt |
writeFloatLE/BE() | Write 32-bit float |
writeDoubleLE/BE() | Write 64-bit float |
writeString() | Write UTF-8 string |
writeCString() | Write null-terminated string |
writeVString() | Write length-prefixed string |
writeVarint32/64() | Write variable-length integer |
| Method | Description |
|---|---|
slice() | Create a new buffer from a portion of this buffer |
copy() | Create a copy of this buffer |
compact() | Optimize buffer size to content |
reset() | Reset read/write positions |
reverse() | Reverse buffer contents |
append() | Append data to buffer |
prepend() | Prepend data to buffer |
MIT License
Based on ByteBuffer.js by Daniel Wirtz.
FAQs
Smart buffer
The npm package @devgrid/smartbuffer receives a total of 36 weekly downloads. As such, @devgrid/smartbuffer popularity was classified as not popular.
We found that @devgrid/smartbuffer demonstrated a healthy version release cadence and project activity because the last version was released less than 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
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.