New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

buffercursor.ts

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

buffercursor.ts

A simple package that allows you to traverse a Buffer iteratively

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-70%
Maintainers
0
Weekly downloads
 
Created
Source

BufferCursor.ts

A simple package that allows you to traverse a Buffer iteratively. You can read and write different types and the cursor's position will update with the proper size, which you can see through .tell() you can also .seek()

Example

import { BufferCursor } from "buffercursor.ts";

const bc = new BufferCursor(Buffer.alloc(10));
bc.writeUInt16BE(123456789);
bc.writeUInt8(123456789);
bc.writeUInt32BE(123456789);
bc.seek(0);
bc.readUInt16BE();
bc.readUInt8();
bc.readUInt32BE();
console.log(bc.tell()); // Current cursor position (7)

Methods

See .d.ts

For the most part BufferCursor and Buffer share the same methods, there's just a slight alteration in method signature, read and write methods don't take an offset. (BigInt support)

So .readUInt16LE(10) in Buffer is equivalent to bc.seek(10); bc.readUInt16LE();

All read and write methods are reproduced, as are toString, write, fill, copy, and slice. All of these methods will move the cursor through the buffer and do not take an offset parameter, where an end parameter would normaly be used, here you supply a length.

Additional methods:

  • move(steps) Moves the cursors by the amount of steps given.
  • seek(value) Moves the cursor to given position.
  • tell() Return the cursor position.
  • eof() Checks and returns if the cursor is at the end of the buffer.
  • getBuffer() Makes a copy of the part of the buffer before the cursor position.
  • writeBuff(buff, length) Writes a buffer to the buffer of given length.

Properties

  • buffer The raw buffer
  • length Size of the raw buffer

OverflowError

The OverflowError is throw when trying to read or write beyond buffer.

Inspiration

This project was heavily inspired by node-buffercursor by tjfontaine, but it is sadly no longer maintained. My first attempt at building this library was based on a fork of node-buffercursor. Since the project has matured, it was moved out to its own repository.

Keywords

FAQs

Package last updated on 12 Oct 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc