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

visgl / loaders.gl / 20382848403

19 Dec 2025 09:20PM UTC coverage: 35.219% (+0.1%) from 35.095%
20382848403

push

github

web-flow
feat: Upgrade to handle ArrayBufferLike (#3271)

1190 of 2002 branches covered (59.44%)

Branch coverage included in aggregate %.

157 of 269 new or added lines in 41 files covered. (58.36%)

3 existing lines in 3 files now uncovered.

37536 of 107957 relevant lines covered (34.77%)

0.79 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';
×
NEW
7
import {toArrayBuffer} from '@loaders.gl/loader-utils';
×
8

×
9
/**
×
10
 *
×
11
 */
×
12
export function decompressReadStream(readStream: Readable, headers?: Headers) {
×
13
  switch (headers?.get('content-encoding')) {
×
14
    case 'br':
×
15
      return readStream.pipe(zlib.createBrotliDecompress());
×
16
    case 'gzip':
×
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
×
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