• 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

34.43
/modules/zip/src/parse-zip/readable-file-utils.ts
1
// loaders.gl
1✔
2
// SPDX-License-Identifier: MIT
1✔
3
// Copyright (c) vis.gl contributors
1✔
4

1✔
5
import type {ReadableFile, Stat} from '@loaders.gl/loader-utils';
1✔
6

1✔
UNCOV
7
function toBigInt(value: number | bigint): bigint {
✔
UNCOV
8
  return typeof value === 'bigint' ? value : BigInt(value);
×
UNCOV
9
}
×
10

1✔
UNCOV
11
function toNumber(value: number | bigint): number {
×
UNCOV
12
  const numberValue = Number(value);
×
UNCOV
13
  if (!Number.isFinite(numberValue)) {
×
14
    throw new Error('Offset is out of bounds');
×
15
  }
×
UNCOV
16
  return numberValue;
×
UNCOV
17
}
×
18

1✔
19
/**
1✔
20
 * Read a byte range from a readable file.
1✔
21
 * @param file readable file handle
1✔
22
 * @param start inclusive start offset
1✔
23
 * @param end exclusive end offset
1✔
24
 * @returns requested slice
1✔
25
 */
1✔
UNCOV
26
export async function readRange(
×
UNCOV
27
  file: ReadableFile,
×
UNCOV
28
  start: number | bigint,
×
UNCOV
29
  end: number | bigint
×
UNCOV
30
): Promise<ArrayBuffer> {
×
UNCOV
31
  const startOffset = toBigInt(start);
×
UNCOV
32
  const endOffset = toBigInt(end);
×
UNCOV
33
  const length = endOffset - startOffset;
×
UNCOV
34
  if (length < 0) {
×
35
    throw new Error('Invalid range requested');
×
36
  }
×
UNCOV
37
  return await file.read(startOffset, toNumber(length));
×
UNCOV
38
}
×
39

1✔
UNCOV
40
export async function readDataView(
×
UNCOV
41
  file: ReadableFile,
×
UNCOV
42
  start: number | bigint,
×
UNCOV
43
  end: number | bigint
×
UNCOV
44
): Promise<DataView> {
×
UNCOV
45
  const arrayBuffer = await readRange(file, start, end);
×
UNCOV
46
  return new DataView(arrayBuffer);
×
UNCOV
47
}
×
48

1✔
49
export async function readUint8(file: ReadableFile, offset: number | bigint): Promise<number> {
×
50
  const dataView = await readDataView(file, offset, toBigInt(offset) + 1n);
×
51
  return dataView.getUint8(0);
×
52
}
×
53

1✔
UNCOV
54
export async function readUint16(file: ReadableFile, offset: number | bigint): Promise<number> {
×
UNCOV
55
  const dataView = await readDataView(file, offset, toBigInt(offset) + 2n);
×
UNCOV
56
  return dataView.getUint16(0, true);
×
UNCOV
57
}
×
58

1✔
UNCOV
59
export async function readUint32(file: ReadableFile, offset: number | bigint): Promise<number> {
×
UNCOV
60
  const dataView = await readDataView(file, offset, toBigInt(offset) + 4n);
×
UNCOV
61
  return dataView.getUint32(0, true);
×
UNCOV
62
}
×
63

1✔
64
export async function readBigUint64(file: ReadableFile, offset: number | bigint): Promise<bigint> {
×
65
  const dataView = await readDataView(file, offset, toBigInt(offset) + 8n);
×
66
  return dataView.getBigUint64(0, true);
×
67
}
×
68

1✔
69
/**
1✔
70
 * Resolve the size of a readable file.
1✔
71
 * @param file readable file handle
1✔
72
 * @returns file size as bigint
1✔
73
 */
1✔
UNCOV
74
export async function getReadableFileSize(file: ReadableFile): Promise<bigint> {
×
UNCOV
75
  if (file.bigsize > 0n) {
×
UNCOV
76
    return file.bigsize;
×
UNCOV
77
  }
×
78
  if (file.size > 0) {
×
79
    return BigInt(file.size);
×
80
  }
×
81
  if (file.stat) {
×
82
    const stats: Stat = await file.stat();
×
83
    if (stats?.bigsize !== undefined) {
×
84
      return stats.bigsize;
×
85
    }
×
86
    if (stats?.size !== undefined) {
×
87
      return BigInt(stats.size);
×
88
    }
×
89
  }
×
90
  return 0n;
×
91
}
×
92

1✔
93
/**
1✔
94
 * Minimal readable file backed by a DataView.
1✔
95
 */
1✔
96
export class DataViewReadableFile implements ReadableFile {
1✔
97
  readonly handle: DataView;
1!
UNCOV
98
  readonly size: number;
×
UNCOV
99
  readonly bigsize: bigint;
×
UNCOV
100
  readonly url: string;
×
101

1✔
102
  constructor(dataView: DataView, url: string = '') {
1✔
UNCOV
103
    this.handle = dataView;
×
UNCOV
104
    this.size = dataView.byteLength;
×
UNCOV
105
    this.bigsize = BigInt(dataView.byteLength);
×
UNCOV
106
    this.url = url;
×
UNCOV
107
  }
×
108

1✔
109
  async close(): Promise<void> {}
1✔
110

1✔
111
  async stat(): Promise<Stat> {
1✔
112
    return {size: this.size, bigsize: this.bigsize, isDirectory: false};
×
113
  }
×
114

1✔
115
  async read(start: number | bigint = 0, length?: number): Promise<ArrayBuffer> {
1✔
UNCOV
116
    const offset = toNumber(start);
×
UNCOV
117
    const end = length ? offset + length : this.size;
×
UNCOV
118
    return this.handle.buffer.slice(offset, end);
×
UNCOV
119
  }
×
120
}
1✔
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