All files / crypto / testdata / digest_large_inputs.ts

100.00% Branches 0/0
100.00% Lines 20/20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
x2
x2
x2
 
x2
 
x2
 
x2
x2
x2
 
x2
 
x2
x2
x2
 
x2
 
 
x2
x2
x2
x2
x2
x2
x2



























// Copyright 2018-2025 the Deno authors. MIT license.
import { crypto as stdCrypto } from "../crypto.ts";
import { __wbindgen_memory } from "../_wasm/lib/deno_std_wasm_crypto.internal.mjs";
import { encodeHex } from "../../encoding/hex.ts";

const memory = __wbindgen_memory() as WebAssembly.Memory;

const heapBytesInitial = memory.buffer.byteLength;

const smallData = new Uint8Array(64);
const smallDigest = encodeHex(
  stdCrypto.subtle.digestSync("BLAKE3", smallData.buffer),
);
const heapBytesAfterSmall = memory.buffer.byteLength;

const largeData = new Uint8Array(64_000_000);
const largeDigest = encodeHex(
  stdCrypto.subtle.digestSync("BLAKE3", largeData.buffer),
);
const heapBytesAfterLarge = memory.buffer.byteLength;

// deno-lint-ignore no-console
console.log(JSON.stringify({
  heapBytesInitial,
  smallDigest,
  heapBytesAfterSmall,
  largeDigest,
  heapBytesAfterLarge,
}));