close
Skip to main content
This release is versions behind 1.0.6 — the latest version of @std/bytes.
Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
Downloads16,122/wk
Published2 years ago (0.200.0)

Utilities to manipulate Uint8Arrays that are not built-in to JavaScript

Classes

c

An abstraction of multiple Uint8Arrays

  • add(
    value: Uint8Array,
    start?: number,
    end?
    ): void

    Push bytes with given offset infos

  • concat(): Uint8Array

    Concatenate chunks into single Uint8Array copied.

  • get(i: number): number

    Get indexed byte from chunks

  • getChunkIndex(pos: number): number

    Find chunk index in which pos locates by binary-search returns -1 if out of range

  • iterator(start?: number): IterableIterator<number>

    Iterator of bytes from given position

  • shift(n: number): void

    Drop head n bytes.

  • Total size of bytes

  • slice(
    start: number,
    end?: number
    ): Uint8Array

    Returns subset of bytes copied

Functions

f
concat(...buf: Uint8Array[]): Uint8Array

Concatenate the given arrays into a new Uint8Array.

f
copy(
src: Uint8Array,
dst: Uint8Array,
off?: number
): number

Copy bytes from the src array to the dst array. Returns the number of bytes copied.

f
endsWith(
source: Uint8Array,
suffix: Uint8Array
): boolean

Returns true if the suffix array appears at the end of the source array, false otherwise.

f
equals(
a: Uint8Array,
b: Uint8Array
): boolean

Check whether binary arrays are equal to each other.

f
includesNeedle(
source: Uint8Array,
needle: Uint8Array,
start?: number
): boolean

Returns true if the source array contains the needle array, false otherwise.

f
indexOfNeedle(
source: Uint8Array,
needle: Uint8Array,
start?: number
): number

Returns the index of the first occurrence of the needle array in the source array, or -1 if it is not present.

f
lastIndexOfNeedle(
source: Uint8Array,
needle: Uint8Array,
start?: number
): number

Returns the index of the last occurrence of the needle array in the source array, or -1 if it is not present.

f
repeat(
source: Uint8Array,
count: number
): Uint8Array

Returns a new Uint8Array composed of count repetitions of the source array.

f
startsWith(
source: Uint8Array,
prefix: Uint8Array
): boolean

Returns true if the prefix array appears at the start of the source array, false otherwise.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/bytes

Import symbol

import * as mod from "@std/bytes";
or

Import directly with a jsr specifier

import * as mod from "jsr:@std/bytes";