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

visgl / loaders.gl / 20352515932

18 Dec 2025 09:56PM UTC coverage: 35.115% (-28.4%) from 63.485%
20352515932

push

github

web-flow
feat(loader-utils): Export is-type helpers (#3258)

1188 of 1998 branches covered (59.46%)

Branch coverage included in aggregate %.

147 of 211 new or added lines in 13 files covered. (69.67%)

30011 existing lines in 424 files now uncovered.

37457 of 108056 relevant lines covered (34.66%)

0.79 hits per line

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

50.75
/modules/loader-utils/src/lib/binary-utils/memory-copy-utils.ts
1
import {assert} from '../env-utils/assert';
1✔
2

1✔
3
/**
1✔
4
 * Calculate new size of an arrayBuffer to be aligned to an n-byte boundary
1✔
5
 * This function increases `byteLength` by the minimum delta,
1✔
6
 * allowing the total length to be divided by `padding`
1✔
7
 * @param byteLength
1✔
8
 * @param padding
1✔
9
 */
1✔
10
export function padToNBytes(byteLength: number, padding: number): number {
1✔
11
  assert(byteLength >= 0); // `Incorrect 'byteLength' value: ${byteLength}`
11✔
12
  assert(padding > 0); // `Incorrect 'padding' value: ${padding}`
11✔
13
  return (byteLength + (padding - 1)) & ~(padding - 1);
11✔
14
}
11✔
15

1✔
16
/**
1✔
17
 * Creates a new Uint8Array based on two different ArrayBuffers
1✔
18
 * @param targetBuffer The first buffer.
1✔
19
 * @param sourceBuffer The second buffer.
1✔
20
 * @return The new ArrayBuffer created out of the two.
1✔
21
 */
1✔
22
export function copyArrayBuffer(
1✔
23
  targetBuffer: ArrayBuffer,
×
24
  sourceBuffer: ArrayBuffer,
×
25
  byteOffset: number,
×
26
  byteLength: number = sourceBuffer.byteLength
×
27
): ArrayBuffer {
×
28
  const targetArray = new Uint8Array(targetBuffer, byteOffset, byteLength);
×
29
  const sourceArray = new Uint8Array(sourceBuffer);
×
30
  targetArray.set(sourceArray);
×
31
  return targetBuffer;
×
32
}
×
33

1✔
34
/**
1✔
35
 * Copy from source to target at the targetOffset
1✔
36
 *
1✔
37
 * @param source - The data to copy
1✔
38
 * @param target - The destination to copy data into
1✔
39
 * @param targetOffset - The start offset into target to place the copied data
1✔
40
 * @returns the new offset taking into account proper padding
1✔
41
 */
1✔
42
export function copyToArray(source: ArrayBuffer | any, target: any, targetOffset: number): number {
1✔
UNCOV
43
  let sourceArray;
×
UNCOV
44

×
UNCOV
45
  if (source instanceof ArrayBuffer) {
×
UNCOV
46
    sourceArray = new Uint8Array(source);
×
UNCOV
47
  } else {
×
UNCOV
48
    // Pack buffer onto the big target array
×
UNCOV
49
    //
×
UNCOV
50
    // 'source.data.buffer' could be a view onto a larger buffer.
×
UNCOV
51
    // We MUST use this constructor to ensure the byteOffset and byteLength is
×
UNCOV
52
    // set to correct values from 'source.data' and not the underlying
×
UNCOV
53
    // buffer for target.set() to work properly.
×
UNCOV
54
    const srcByteOffset = source.byteOffset;
×
UNCOV
55
    const srcByteLength = source.byteLength;
×
UNCOV
56
    // In gltf parser it is set as "arrayBuffer" instead of "buffer"
×
UNCOV
57
    // https://github.com/visgl/loaders.gl/blob/1e3a82a0a65d7b6a67b1e60633453e5edda2960a/modules/gltf/src/lib/parse-gltf.js#L85
×
UNCOV
58
    sourceArray = new Uint8Array(source.buffer || source.arrayBuffer, srcByteOffset, srcByteLength);
×
UNCOV
59
  }
×
UNCOV
60

×
UNCOV
61
  // Pack buffer onto the big target array
×
UNCOV
62
  target.set(sourceArray, targetOffset);
×
UNCOV
63

×
UNCOV
64
  return targetOffset + padToNBytes(sourceArray.byteLength, 4);
×
UNCOV
65
}
×
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