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

@xan105/buffer

v1.1.0

Published

Additional Buffer|Uint8Array manipulation

Downloads

4

Readme

About

Additional Buffer|Uint8Array manipulation

📦 Scoped @xan105 packages are for my own personal use but feel free to use them.

Example


import { split } from "@xan105/buffer";

const buffer = Buffer.from("ABCD0001ABCD0002", "hex");
const chuncks = split(buffer, Buffer.from("ABCD", "hex"));
//[ <Buffer 00 01>, <Buffer 00 02> ]
const chuncks = split(buffer, Buffer.from("ABCD",'hex'), { includeSeparator : true });
//[ <Buffer ab cd 00 01>, <Buffer ab cd 00 02> ]

Install

npm install @xan105/buffer

API

⚠️ This module is only available as an ECMAScript module (ESM)

Named export

indexOfAny(buffer: Buffer | Uint8Array, values: Buffer[] | Uint8Array[], offset?: number): { pos: number, length: number }

Like Buffer.indexOf() but for one or more search values.

Return the same value as Buffer.indexOf() and the length of the found value for convenience (zero if not found).

lastIndexOfAny(buffer: Buffer | Uint8Array, values: Buffer[] | Uint8Array[], offset?: number): { pos: number, length: number }

Like Buffer.lastIndexOf() but for one or more search values.

Return the same value as Buffer.lastIndexOf() and the length of the found value for convenience (zero if not found).

indexOfNthOccurrence(buffer: Buffer | Uint8Array, search: Buffer | Uint8Array, n: number): number

Like Buffer.indexOf() but find the n-th occurence of the search value.

split(buffer: Buffer | Uint8Array, separators: Buffer | Buffer[] | Uint8Array | Uint8Array[], option?: object): Buffer[] | Uint8Array[]

Divides a Buffer into an array of Buffer; split at each point where the separator occurs in the given Buffer. This is somehow similar to String.split() but for Buffer.

|option|default|description| |------|-------|-----------| |includeSeparator|false|whether to keep the separator or not when splitting|

When found, separator is removed from the Buffer unless includeSeparator is true.

If separator appears at the beginning or end of the Buffer, it still has the effect of splitting. The result is an empty Buffer (i.e. zero length), but it will be omitted from the returned array.

If separator does not occur in the Buffer, the returned array contains one element consisting of the entire Buffer.

if separator is an empty Buffer (i.e. zero length) then the returned array will be of buffer.length and contains every bytes whether includeSeparator is true or false.

If there are more than one separator, they are tested in the given order.

splitIntoChuncks(buffer: Buffer | Uint8Array, n: number): Buffer[] | Uint8Array[]

Divides a Buffer into an array of n-sized chunks. Throws an error if the given Buffer can not be divided.

concat(buffers: Buffer[] | Uint8Array[], length?: number) : Uint8Array

Like Buffer.concat() but for Uint8Array.

Returns a new Uint8Array which is the result of concatenating the given Uint8Arrays together. if length is 0, then a new zero-length Uint8Array is returned. If length is not provided, it is calculated from the given Uint8Arrays. If length is provided and the combined length of the given Uint8Arrays exceeds length, the result is truncated to length.