npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xrtlibrary-bufferutilities

v1.0.4

Published

Buffer utilities module of XRT library.

Downloads

3

Readme

XRTLibrary-BufferUtilities

Introduction

This library provides following buffer utilities:

  • Buffer fetcher (fetch several bytes synchronously from a Buffer object).
  • Blocked buffer fetcher (fetch several bytes synchronously from a Buffer array).
  • Buffer merger (merge a buffer array into one).

Installation

To install this package, you can use NPM by typing following command:

npm install xrtlibrary-bufferutilities --save

Then you can import this library in your JavaScript code:

const XRTLibBufferUtilities = require("xrtlibrary-bufferutilities");

API

(Class) BufferFetcher

Buffer fetcher.

new BufferFetcher(buffer)

Construct a new object.

Parameter(s):

  • buffer (Buffer): The buffer.

fetcher.isEnd()

Get whether the cursor reached the end.

Return value:

  • (Boolean) True if ended.

fetcher.reset()

Reset the cursor.

fetcher.fetch()

Fetch one byte.

Exception(s):

  • BufferFetcher.EndOfStreamError: Raised if the stream was already ended.

Return value:

  • (Number) The byte.

Example:

let fetcher = new XRTLibBufferUtilities.BufferFetcher(
    Buffer.from([10, 9, 8, 7])
);
while (!fetcher.isEnd()) {
    console.log(fetcher.fetch());
}
//  Output:
//    10
//    9
//    8
//    7

fetcher.fetchTo(output)

Fetch bytes to output buffer.

Parameter(s):

  • output (Buffer): The output buffer.

Return value:

  • (Number) The count of copied bytes.

Example:

let fetcher = new XRTLibBufferUtilities.BufferFetcher(
    Buffer.from([1, 2, 3, 4])
);
while (!fetcher.isEnd()) {
    let output = Buffer.alloc(2);
    fetcher.fetchTo(output);
    console.log(output);
}
//  Output:
//    <Buffer 01 02>
//    <Buffer 03 04>

fetcher.fetchToWithStart(output, outputStart)

Fetch bytes to output buffer (with start position).

Parameter(s):

  • output (Buffer): The output buffer.
  • outputStart (Number): The start position of the output buffer.

Return value:

  • (Number) The count of copied bytes.

fetcher.fetchAll()

Fetch all bytes.

Return value:

  • (Buffer): The bytes.

Example:

let fetcher = new XRTLibBufferUtilities.BufferFetcher(
    Buffer.from([1, 2, 3, 4])
);
console.log(fetcher.fetch());
console.log(fetcher.fetchAll());
//  Output:
//    1
//    <Buffer 02 03 04>

fetcher.fetchBytes(count)

Fetch specific bytes.

Parameter(s):

  • count (Number): The bytes count.

Return value:

  • (Buffer) The bytes.

fetcher.skip(steps)

Skip specific bytes.

Parameter(s):

  • steps (Number): The count of bytes to be skipped.

Return value:

  • (Number): The count of skipped bytes.

Example:

let fetcher = new XRTLibBufferUtilities.BufferFetcher(
    Buffer.from([1, 2, 3, 4])
);
console.log(fetcher.fetch());
fetcher.skip(2);
console.log(fetcher.fetch());
//  Output:
//    1
//    4

fetcher.getRemainingCount()

Get the count of remaining bytes.

Return value:

  • (Number): The count.

fetcher.reinitialize(newBuffer)

Parameter(s):

  • newBuffer (Buffer): New buffer.

(Class) BufferFetcher.Error

Buffer fetcher error.

Extend(s):

  • Error

(Class) BufferFetcher.EndOfStreamError

Buffer fetcher end of stream error.

Extend(s):

  • BufferFetcher.Error

(Class) BlockBufferFetcher

Block buffer fetcher.

new BlockBufferFetcher(blocks)

Construct a new object.

Parameter(s):

  • blocks (Buffer[]): The buffer blocks.

blockfetcher.isEnd()

Get whether the cursor reached the end.

Return value:

  • (Boolean) True if ended.

blockfetcher.reset()

Reset the cursor.

blockfetcher.fetch()

Fetch one byte.

Exception(s):

  • BlockBufferFetcher.EndOfStreamError: Raised if the stream was already ended.

Return value:

  • (Number) The byte.

blockfetcher.fetchTo(output)

Fetch bytes to output buffer.

Parameter(s):

  • output (Buffer): The output buffer.

Return value:

  • (Number) The count of copied bytes.

blockfetcher.fetchAll()

Fetch all bytes.

Return value:

  • (Buffer) The bytes.

blockfetcher.fetchAllAsBlocks([outBytesCount = new OutputParameter()])

Fetch all remaining bytes as blocks (faster).

Parameter(s):

  • outBytesCount (OutputParameter): (Optional, Out) The size of output buffer blocks.

Return value:

  • (Buffer[]) The blocks.

blockfetcher.fetchBytes(count)

Fetch specific bytes.

Parameter(s):

  • count (Number): The bytes count.

Return value:

  • (Buffer) The bytes.

blockfetcher.fetchBytesAsBlocks(count)

Fetch specific bytes as blocks.

Warning(s):

  • This method has been deprecated (but still usable).
  • Use blockfetcher.fetchBytesAsBlocks2() instead.

Parameter(s):

  • count (Number): The bytes count.

Return value:

  • (Object) The fetch result.
    • buffers (Buffer[]): The buffer array.
    • length (Number): The length of bytes fetched.

blockfetcher.fetchBytesAsBlocks2(count, [outBytesCount = new OutputParameter()])

Fetch specific bytes as blocks.

Parameter(s):

  • count (Number): The bytes count.
  • outBytesCount (OutputParameter): (Optional, Out) The size of output buffer blocks.

Return value:

  • (Buffer[]) The buffer blocks.

blockfetcher.skip(steps)

Skip specific bytes.

Parameter(s):

  • steps (Number): The count of bytes to be skipped.

Return value:

  • (Number) The count of skipped bytes.

blockfetcher.reinitialize(newBlocks)

Reinitialize the object.

Parameter(s):

  • newBlocks (Buffer[]): New blocks.

(Class) BlockBufferFetcher.Error

Block buffer fetcher error.

Extend(s):

  • Error

(Class) BlockBufferFetcher.EndOfStreamError

Block buffer fetcher end of stream error.

Extend(s):

  • BlockBufferFetcher.Error

(Class) BufferMerger

Buffer merger.

new BufferMerger()

Construct a new object.

merger.push(data)

Push a buffer.

Parameter(s):

  • data (Buffer): The buffer.

merger.merge()

Merge pushed buffers.

Return value:

  • (Buffer) The concatencated buffer.

merger.reset()

Clear pushed buffers.

(Class) BufferEmitter

Buffer emitter.

Extend(s):

  • BufferMerger

new BufferEmitter()

Construct a new object.

emitter.writeUInt8(value)

Write an 8-bit unsigned integer.

Parameter(s):

  • value (Number): The integer value.

emitter.writeInt8(value)

Write an 8-bit signed integer.

Parameter(s):

  • value (Number): The integer value.

emitter.writeUInt16LE(value)

Write an 16-bit little endian unsigned integer.

Parameter(s):

  • value (Number): The integer value.

emitter.writeUInt16BE(value)

Write an 16-bit big endian unsigned integer.

Parameter(s):

  • value (Number): The integer value.

emitter.writeInt16LE(value)

Write an 16-bit little endian signed integer.

Parameter(s):

  • value (Number): The integer value.

emitter.writeInt16BE(value)

Write an 16-bit big endian signed integer.

Parameter(s):

  • value (Number): The integer value.

emitter.writeUInt32LE(value)

Write an 32-bit little endian unsigned integer.

Parameter(s):

  • value (Number): The integer value.

emitter.writeUInt32BE(value)

Write an 32-bit big endian unsigned integer.

Parameter(s):

  • value (Number): The integer value.

emitter.writeInt32LE(value)

Write an 32-bit little endian signed integer.

Parameter(s):

  • value (Number): The integer value.

emitter.writeInt32BE(value)

Write an 32-bit big endian signed integer.

Parameter(s):

  • value (Number): The integer value.

emitter.writeUIntLE(value, byteLength)

Write an custom byte length little endian unsigned integer.

Parameter(s):

  • value (Number): The integer value.
  • byteLength (Number): The byte size.

emitter.writeUIntBE(value, byteLength)

Write an custom byte length big endian unsigned integer.

Parameter(s):

  • value (Number): The integer value.
  • byteLength (Number): The byte size.

emitter.writeIntLE(value, byteLength)

Write an custom byte length little endian signed integer.

Parameter(s):

  • value (Number): The integer value.
  • byteLength (Number): The byte size.

emitter.writeIntBE(value, byteLength)

Write an custom byte length big endian signed integer.

Parameter(s):

  • value (Number): The integer value.
  • byteLength (Number): The byte size.

emitter.writeFloatLE(value)

Write a little-endian float.

Parameter(s):

  • value (Number): The float value.

emitter.writeFloatBE(value)

Write a big-endian float.

Parameter(s):

  • value (Number): The float value.

emitter.writeDoubleLE(value)

Write a little-endian double.

Parameter(s):

  • value (Number): The float value.

emitter.writeDoubleBE(value)

Write a big-endian double.

Parameter(s):

  • value (Number): The float value.

MergeBufferBlocks(blocks)

Merge buffer blocks to one buffer.

Parameter(s):

  • blocks (Buffer[]): The blocks to be concatencated.

Return value:

  • (Buffer) The concatencated buffer.