Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on Apr 15, 2024 via pnpm

smart-buffer 4.2.0

smart-buffer is a Buffer wrapper that adds automatic read & write offset tracking, string operations, data insertions, and more.
Package summary
Share
0
issues
1
license
1
MIT
Package created
3 Nov 2013
Version published
7 Aug 2021
Maintainers
1
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
smart-buffer@4.2.0
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of smart-buffer 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does smart-buffer do?

Smart-buffer is a package that serves as a wrapper for Buffer in Node.js, offering automated read & write offset tracking, data insertions, string operations, and more. It simplifies buffer management by growing the internal Buffer as needed, tracking read and write offsets automatically, and providing useful string operations such as null-terminating strings. The tool is built in TypeScript but also works in JavaScript environments given its provided type definitions.

How do you use smart-buffer?

To use smart-buffer in your project, you first need to install it using npm or yarn:

npm install smart-buffer
# or
yarn add smart-buffer

You can then require it in your JavaScript files as follows:

const SmartBuffer = require('smart-buffer').SmartBuffer;

If you are using TypeScript, import it like below:

import { SmartBuffer, SmartBufferOptions} from 'smart-buffer';

Smart-buffer allows you to read and write data in various ways. Here is an example of creating a login packet with a protocol specification and reading it back:

// Creating packet
function createLoginPacket(username, password, age, country) {
    const packet = new SmartBuffer();
    packet.writeUInt16LE(0x0060); // Some packet type
    packet.writeStringNT(username);
    packet.writeStringNT(password);
    packet.writeUInt8(age);
    packet.writeStringNT(country);
    packet.insertUInt16LE(packet.length - 2, 2);

    return packet.toBuffer();
}

// Using packet
const login = createLoginPacket("Josh", "secret123", 22, "United States");

// Reading packet
const reader = SmartBuffer.fromBuffer(login);
const logininfo = {
    packetType: reader.readUInt16LE(),
    packetLength: reader.readUInt16LE(),
    username: reader.readStringNT(),
    password: reader.readStringNT(),
    age: reader.readUInt8(),
    country: reader.readStringNT()
};

This package allows you to create packets without having to keep track of the current "cursor" position in your Buffer manually. It similarly reads back packets conveniently.

Where are the smart-buffer docs?

The complete documentation for smart-buffer, detailing all its methods and use-cases, is hosted on GitHub at https://github.com/JoshGlazebrook/smart-buffer/blob/master/README.md. Here, you can find the description and usage of various methods smart-buffer provides, including methods for numbers, strings, buffers, and offset operations among others.