• 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/filesystems/stream-utils.node.ts
1
// loaders.gl
2
// SPDX-License-Identifier: MIT
3
// Copyright (c) vis.gl contributors
4

5
import zlib from 'zlib';
6
import {Readable} from 'stream';
7
import {toArrayBuffer} from '@loaders.gl/loader-utils';
8

9
/**
10
 *
11
 */
12
export function decompressReadStream(readStream: Readable, headers?: Headers) {
UNCOV
13
  switch (headers?.get('content-encoding')) {
×
14
    case 'br':
15
      return readStream.pipe(zlib.createBrotliDecompress());
×
16
    case 'gzip':
UNCOV
17
      return readStream.pipe(zlib.createGunzip());
×
18
    case 'deflate':
19
      return readStream.pipe(zlib.createDeflate());
×
20
    default:
21
      // No compression or an unknown one, just return it as is
UNCOV
22
      return readStream;
×
23
  }
24
}
25

26
/**
27
 *
28
 * @param readStream
29
 * @returns
30
 */
31
export async function concatenateReadStream(readStream): Promise<ArrayBuffer> {
32
  const arrayBufferChunks: ArrayBuffer[] = [];
×
33

34
  return await new Promise((resolve, reject) => {
×
35
    readStream.on('error', error => reject(error));
×
36

37
    // Once the readable callback has been added, stream switches to "flowing mode"
38
    // In Node 10 (but not 12 and 14) this causes `data` and `end` to never be called unless we read data here
39
    readStream.on('readable', () => readStream.read());
×
40

41
    readStream.on('data', chunk => {
×
42
      if (typeof chunk === 'string') {
×
43
        reject(new Error('Read stream not binary'));
×
44
      }
45
      arrayBufferChunks.push(toArrayBuffer(chunk));
×
46
    });
47

48
    readStream.on('end', () => {
×
49
      const arrayBuffer = concatenateArrayBuffers(arrayBufferChunks);
×
50
      resolve(arrayBuffer);
×
51
    });
52
  });
53
}
54

55
/**
56
 * Concatenate a sequence of ArrayBuffers
57
 * @return A concatenated ArrayBuffer
58
 * @note duplicates loader-utils since polyfills should be independent
59
 */
60
export function concatenateArrayBuffers(sources: (ArrayBuffer | Uint8Array)[]): ArrayBuffer {
61
  // Make sure all inputs are wrapped in typed arrays
62
  const sourceArrays = sources.map(source2 =>
×
63
    source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
×
64
  );
65

66
  // Get length of all inputs
67
  const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
×
68

69
  // Allocate array with space for all inputs
70
  const result = new Uint8Array(byteLength);
×
71

72
  // Copy the subarrays
73
  let offset = 0;
×
74
  for (const sourceArray of sourceArrays) {
×
75
    result.set(sourceArray, offset);
×
76
    offset += sourceArray.byteLength;
×
77
  }
78

79
  // We work with ArrayBuffers, discard the typed array wrapper
80
  return result.buffer;
×
81
}
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