• 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

77.6
/modules/loader-utils/src/lib/binary-utils/array-buffer-utils.ts
1
import {TypedArray} from '../../types';
1✔
2

1✔
3
/**
1✔
4
 * compare two binary arrays for equality
1✔
5
 * @param a
1✔
6
 * @param b
1✔
7
 * @param byteLength
1✔
8
 */
1✔
9
export function compareArrayBuffers(
1✔
NEW
10
  arrayBuffer1: ArrayBufferLike,
×
NEW
11
  arrayBuffer2: ArrayBufferLike,
×
12
  byteLength?: number
×
13
): boolean {
×
14
  byteLength = byteLength || arrayBuffer1.byteLength;
×
15
  if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {
×
16
    return false;
×
17
  }
×
18
  const array1 = new Uint8Array(arrayBuffer1);
×
19
  const array2 = new Uint8Array(arrayBuffer2);
×
20
  for (let i = 0; i < array1.length; ++i) {
×
21
    if (array1[i] !== array2[i]) {
×
22
      return false;
×
23
    }
×
24
  }
×
25
  return true;
×
26
}
×
27

1✔
28
/**
1✔
29
 * Concatenate a sequence of ArrayBuffers from arguments
1✔
30
 * @return A concatenated ArrayBuffer
1✔
31
 */
1✔
32
export function concatenateArrayBuffers(...sources: (ArrayBuffer | Uint8Array)[]): ArrayBuffer {
1✔
33
  return concatenateArrayBuffersFromArray(sources);
9✔
34
}
9✔
35

1✔
36
/**
1✔
37
 * Concatenate a sequence of ArrayBuffers from array
1✔
38
 * @return A concatenated ArrayBuffer
1✔
39
 */
1✔
40
export function concatenateArrayBuffersFromArray(
1✔
41
  sources: (ArrayBuffer | Uint8Array)[]
9✔
42
): ArrayBuffer {
9✔
43
  // Make sure all inputs are wrapped in typed arrays
9✔
44
  const sourceArrays = sources.map((source2) =>
9✔
45
    source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
19✔
46
  );
9✔
47

9✔
48
  // Get length of all inputs
9✔
49
  const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
9✔
50

9✔
51
  // Allocate array with space for all inputs
9✔
52
  const result = new Uint8Array(byteLength);
9✔
53

9✔
54
  // Copy the subarrays
9✔
55
  let offset = 0;
9✔
56
  for (const sourceArray of sourceArrays) {
9✔
57
    result.set(sourceArray, offset);
19✔
58
    offset += sourceArray.byteLength;
19✔
59
  }
19✔
60

9✔
61
  // We work with ArrayBuffers, discard the typed array wrapper
9✔
62
  return result.buffer;
9✔
63
}
9✔
64

1✔
65
/**
1✔
66
 * Concatenate arbitrary count of typed arrays
1✔
67
 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
1✔
68
 * @param - list of arrays. All arrays should be the same type
1✔
69
 * @return A concatenated TypedArray
1✔
70
 */
1✔
71
export function concatenateTypedArrays<T>(...typedArrays: T[]): T {
1✔
72
  // @ts-ignore
4✔
73
  const arrays = typedArrays as TypedArray[];
4✔
74
  // @ts-ignore
4✔
75
  const TypedArrayConstructor = (arrays && arrays.length > 1 && arrays[0].constructor) || null;
4✔
76
  if (!TypedArrayConstructor) {
4✔
77
    throw new Error(
2✔
78
      '"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types'
2✔
79
    );
2✔
80
  }
2✔
81

2✔
82
  const sumLength = arrays.reduce((acc, value) => acc + value.length, 0);
2✔
83
  // @ts-ignore typescript does not like dynamic constructors
2✔
84
  const result = new TypedArrayConstructor(sumLength);
2✔
85
  let offset = 0;
2✔
86
  for (const array of arrays) {
4✔
87
    result.set(array, offset);
5✔
88
    offset += array.length;
5✔
89
  }
5✔
90
  return result;
2✔
91
}
2✔
92

1✔
93
/**
1✔
94
 * Copy a view of an ArrayBuffer into new ArrayBuffer with byteOffset = 0
1✔
95
 * @param arrayBuffer
1✔
96
 * @param byteOffset
1✔
97
 * @param byteLength
1✔
98
 */
1✔
99
export function sliceArrayBuffer(
1✔
NEW
100
  arrayBuffer: ArrayBufferLike,
×
101
  byteOffset: number,
×
102
  byteLength?: number
×
103
): ArrayBuffer {
×
104
  const subArray =
×
105
    byteLength !== undefined
×
106
      ? new Uint8Array(arrayBuffer).subarray(byteOffset, byteOffset + byteLength)
×
107
      : new Uint8Array(arrayBuffer).subarray(byteOffset);
×
108
  const arrayCopy = new Uint8Array(subArray);
×
109
  return arrayCopy.buffer;
×
110
}
×
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