• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

visgl / loaders.gl / 24153816851

08 Apr 2026 07:17PM UTC coverage: 53.247% (-12.1%) from 65.319%
24153816851

push

github

web-flow
chore: Move from tape to vitest (#3351)

8651 of 17291 branches covered (50.03%)

Branch coverage included in aggregate %.

7 of 7 new or added lines in 1 file covered. (100.0%)

2031 existing lines in 296 files now uncovered.

17563 of 31940 relevant lines covered (54.99%)

5279.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/modules/polyfills/src/crypto/node-hash.ts
1
// loaders.gl
2
// SPDX-License-Identifier: MIT
3
// Copyright vis.gl contributors
4

5
// This dependency is too big, application must provide it
6
import {Hash} from '@loaders.gl/crypto';
7
import * as crypto from 'crypto'; // Node.js builtin
8

9
type CryptoHashOptions = {
10
  crypto: {
11
    algorithm: string;
12
    onEnd?: (result: {hash: string}) => any;
13
  };
14
};
15

16
/**
17
 * Calculates Cryptographic Hash using Node.js crypto library
18
 * @deprecated Warning, experimental class
19
 */
20
export class NodeHash extends Hash {
UNCOV
21
  readonly name = 'crypto-node';
×
22

23
  options: CryptoHashOptions;
24
  // @ts-ignore
25
  private _algorithm;
26
  // @ts-ignore
27
  private _hash;
28

29
  constructor(options: CryptoHashOptions) {
UNCOV
30
    super();
×
UNCOV
31
    this.options = options;
×
UNCOV
32
    if (!this.options?.crypto?.algorithm) {
×
33
      throw new Error(this.name);
×
34
    }
35
  }
36

37
  /**
38
   * Atomic hash calculation
39
   * @returns base64 encoded hash
40
   */
41
  async hash(input: ArrayBuffer, encoding: 'hex' | 'base64'): Promise<string> {
42
    // await this.preload();
UNCOV
43
    const algorithm = this.options?.crypto?.algorithm?.toLowerCase();
×
UNCOV
44
    try {
×
UNCOV
45
      if (!crypto.createHash) {
×
46
        throw new Error('crypto.createHash not available');
×
47
      }
UNCOV
48
      const hash = crypto.createHash?.(algorithm);
×
UNCOV
49
      const inputArray = new Uint8Array(input);
×
UNCOV
50
      return hash.update(inputArray).digest('base64');
×
51
    } catch (error) {
52
      throw Error(`${algorithm} hash not available. ${error}`);
×
53
    }
54
  }
55

56
  async *hashBatches(
57
    asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
58
    encoding: 'hex' | 'base64' = 'base64'
×
59
  ): AsyncIterable<ArrayBuffer> {
60
    // await this.preload();
61
    if (!crypto.createHash) {
×
62
      throw new Error('crypto.createHash not available');
×
63
    }
64
    const hash = crypto.createHash?.(this.options?.crypto?.algorithm?.toLowerCase());
×
65
    for await (const chunk of asyncIterator) {
×
66
      // https://stackoverflow.com/questions/25567468/how-to-decrypt-an-arraybuffer
67
      const inputArray = new Uint8Array(chunk);
×
68
      hash.update(inputArray);
×
69
      yield chunk;
×
70
    }
71
    // We can pass our encoding constant directly to Node.js digest as it already supports `hex` and `base64`
72
    const digest = hash.digest(encoding);
×
73
    this.options?.crypto?.onEnd?.({hash: digest});
×
74
  }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc