File size: 1,572 Bytes
b332ac0
 
 
 
 
e1d89d9
 
 
b332ac0
 
 
 
 
 
 
e1d89d9
b332ac0
 
e1d89d9
b332ac0
ce0dba2
b332ac0
 
 
 
 
e1d89d9
b332ac0
 
 
 
 
e1d89d9
b332ac0
 
 
e1d89d9
b332ac0
 
 
 
e1d89d9
fcccc22
b332ac0
 
 
 
 
fcccc22
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { __internal_sha256 as shaUnbundledRegular } from "@huggingface/hub-unbundled-regular";
import { __internal_sha256 as shaUnbundled } from "@huggingface/hub-unbundled";
import { __internal_sha256 as shaRegular } from "@huggingface/hub-regular";
import { __internal_sha256 as shaEsm } from "@huggingface/hub-esm";
import { __internal_sha256 as sha } from "@huggingface/hub";

const lfsContent = "0123456789".repeat(1_000_000);

const shas = {
  "hub-unbundled-regular": shaUnbundledRegular,
  "hub-unbundled": shaUnbundled,
  "hub-regular": shaRegular,
  "hub-esm": shaEsm,
  "hub": sha
}

async function test(id) {
  const blob = new Blob([lfsContent]);

  try {
    const iterator = shas[id](blob, { useWebWorker: { minSize: 1 } });
    // Get return value of the generator
    while (1) {
        const { done, value } = await iterator.next();
        if (done) {
            document.getElementById(id).textContent = value;

            const builtInResult = await crypto.subtle.digest("SHA-256", await blob.arrayBuffer());
            const hex =
                builtInResult instanceof ArrayBuffer
                    ? new Uint8Array(builtInResult).reduce((acc, i) => acc + i.toString(16).padStart(2, "0"), "")
                    : builtInResult;

          
            break;
        }

    }
  } catch (err) {
    document.getElementById(id).textContent = err.message;
  }
}
window.document.addEventListener("DOMContentLoaded", () => {
  test("hub-unbundled-regular");
  test("hub-unbundled");
  test("hub-regular");
  test("hub-esm");
  test("hub");
});