MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / _getBytes

Function _getBytes

lib.esm/utils/data.js:8–25  ·  view source on GitHub ↗
(value, name, copy)

Source from the content-addressed store, hash-verified

6 */
7import { assert, assertArgument } from "./errors.js";
8function _getBytes(value, name, copy) {
9 if (value instanceof Uint8Array) {
10 if (copy) {
11 return new Uint8Array(value);
12 }
13 return value;
14 }
15 if (typeof (value) === "string" && value.match(/^0x(?:[0-9a-f][0-9a-f])*$/i)) {
16 const result = new Uint8Array((value.length - 2) / 2);
17 let offset = 2;
18 for (let i = 0; i < result.length; i++) {
19 result[i] = parseInt(value.substring(offset, offset + 2), 16);
20 offset += 2;
21 }
22 return result;
23 }
24 assertArgument(false, "invalid BytesLike value", name || "value", value);
25}
26/**
27 * Get a typed Uint8Array for %%value%%. If already a Uint8Array
28 * the original %%value%% is returned; if a copy is required use

Callers 2

getBytesFunction · 0.70
getBytesCopyFunction · 0.70

Calls 1

assertArgumentFunction · 0.90

Tested by

no test coverage detected