MCPcopy Create free account
hub / github.com/ScattrdBlade/bigFileUpload / toArrayBuffer

Function toArrayBuffer

utils/s3.ts:35–45  ·  view source on GitHub ↗
(data: ArrayBuffer | Uint8Array | string)

Source from the content-addressed store, hash-verified

33const textEncoder = new TextEncoder();
34
35function toArrayBuffer(data: ArrayBuffer | Uint8Array | string): ArrayBuffer {
36 if (typeof data === "string") {
37 return textEncoder.encode(data).buffer as ArrayBuffer;
38 }
39
40 if (data instanceof Uint8Array) {
41 return new Uint8Array(data).buffer;
42 }
43
44 return data;
45}
46
47function toHex(buffer: ArrayBuffer): string {
48 return Array.from(new Uint8Array(buffer), b => b.toString(16).padStart(2, "0")).join("");

Callers 2

sha256HexFunction · 0.85
hmacSha256Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected