1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-30 16:40:57 -05:00
denoland-deno/std/bytes
tokiedokie 3d65177dbc
docs(std): version all imports in README (#7442)
Use $STD_VERSION in std/ README files to automatically
display proper version.
2020-10-04 14:18:36 +02:00
..
mod.ts refactor: shift copyBytes and tweak deps to reduce dependencies (#6469) 2020-06-25 06:40:51 -04:00
README.md docs(std): version all imports in README (#7442) 2020-10-04 14:18:36 +02:00
test.ts feat(fmt): Sort named import and export specifiers (#7711) 2020-09-27 12:22:32 +02:00

bytes

bytes module is made to provide helpers to manipulation of bytes slice.

usage

All the following functions are exposed in mod.ts.

findIndex

Find first index of binary pattern from given binary array.

import { findIndex } from "https://deno.land/std@$STD_VERSION/bytes/mod.ts";

findIndex(
  new Uint8Array([1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 3]),
  new Uint8Array([0, 1, 2]),
);

// => returns 2

findLastIndex

Find last index of binary pattern from given binary array.

import { findLastIndex } from "https://deno.land/std@$STD_VERSION/bytes/mod.ts";

findLastIndex(
  new Uint8Array([0, 1, 2, 0, 1, 2, 0, 1, 3]),
  new Uint8Array([0, 1, 2]),
);

// => returns 3

equal

Check whether given binary arrays are equal to each other.

import { equal } from "https://deno.land/std@$STD_VERSION/bytes/mod.ts";

equal(new Uint8Array([0, 1, 2, 3]), new Uint8Array([0, 1, 2, 3])); // returns true
equal(new Uint8Array([0, 1, 2, 3]), new Uint8Array([0, 1, 2, 4])); // returns false

hasPrefix

Check whether binary array has binary prefix.

import { hasPrefix } from "https://deno.land/std@$STD_VERSION/bytes/mod.ts";

hasPrefix(new Uint8Array([0, 1, 2]), new Uint8Array([0, 1])); // returns true
hasPrefix(new Uint8Array([0, 1, 2]), new Uint8Array([1, 2])); // returns false

repeat

Repeat bytes of given binary array and return new one.

import { repeat } from "https://deno.land/std@$STD_VERSION/bytes/mod.ts";

repeat(new Uint8Array([1]), 3); // returns Uint8Array(3) [ 1, 1, 1 ]

concat

Concatenate two binary arrays and return new one.

import { concat } from "https://deno.land/std@$STD_VERSION/bytes/mod.ts";

concat(new Uint8Array([1, 2]), new Uint8Array([3, 4])); // returns Uint8Array(4) [ 1, 2, 3, 4 ]

copyBytes

Copy bytes from one binary array to another.

import { copyBytes } from "https://deno.land/std@$STD_VERSION/bytes/mod.ts";

const dst = new Uint8Array(4);
const src = Uint8Array.of(1, 2, 3, 4);
const len = copyBytes(src, dest); // returns len = 4