• 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

18.42
/modules/core/src/lib/progress/fetch-progress.ts
1
// loaders.gl
1✔
2
// SPDX-License-Identifier: MIT
1✔
3
// Copyright (c) vis.gl contributors
1✔
4

1✔
5
// Forked from github AnthumChris/fetch-progress-indicators under MIT license
1✔
6

1✔
7
/**
1✔
8
 * Intercepts the Response stream and creates a new Response
1✔
9
 */
1✔
UNCOV
10
export async function fetchProgress(
✔
UNCOV
11
  response: Response | Promise<Response>,
×
UNCOV
12
  onProgress: any, // TODO better callback types
×
UNCOV
13
  onDone = () => {},
×
UNCOV
14
  onError = () => {}
×
UNCOV
15
) {
×
UNCOV
16
  response = await response;
×
UNCOV
17
  if (!response.ok) {
×
18
    // ERROR checking needs to be done separately
×
19
    return response;
×
20
  }
×
UNCOV
21
  const body = response.body;
×
UNCOV
22
  if (!body) {
×
23
    // 'ReadableStream not yet supported in this browser.
×
24
    return response;
×
25
  }
×
UNCOV
26
  const contentLength = response.headers.get('content-length') || 0;
×
UNCOV
27
  const totalBytes = contentLength ? parseInt(contentLength) : 0;
×
UNCOV
28
  if (!(totalBytes > 0)) {
×
29
    return response;
×
30
  }
×
UNCOV
31
  // Currently override only implemented in browser
×
UNCOV
32
  if (typeof ReadableStream === 'undefined' || !body.getReader) {
×
33
    return response;
×
34
  }
×
UNCOV
35

×
UNCOV
36
  // Create a new stream that invisbly wraps original stream
×
UNCOV
37
  const progressStream = new ReadableStream({
×
UNCOV
38
    async start(controller) {
×
UNCOV
39
      const reader = body.getReader();
×
UNCOV
40
      await read(controller, reader, 0, totalBytes, onProgress, onDone, onError);
×
UNCOV
41
    }
×
UNCOV
42
  });
×
UNCOV
43

×
UNCOV
44
  return new Response(progressStream);
×
UNCOV
45
}
×
46

1✔
47
// Forward to original streams controller
1✔
48
// TODO - this causes a crazy deep "async stack"... rewrite as async iterator?
1✔
49
// eslint-disable-next-line max-params
1✔
UNCOV
50
async function read(
×
UNCOV
51
  controller: any,
×
UNCOV
52
  reader: any,
×
UNCOV
53
  loadedBytes: number,
×
UNCOV
54
  totalBytes: number,
×
UNCOV
55
  onProgress: Function,
×
UNCOV
56
  onDone: Function,
×
UNCOV
57
  onError: Function
×
UNCOV
58
): Promise<void> {
×
UNCOV
59
  try {
×
UNCOV
60
    const {done, value} = await reader.read();
×
UNCOV
61
    if (done) {
×
UNCOV
62
      onDone();
×
UNCOV
63
      controller.close();
×
UNCOV
64
      return;
×
UNCOV
65
    }
×
UNCOV
66
    loadedBytes += value.byteLength;
×
UNCOV
67
    const percent = Math.round((loadedBytes / totalBytes) * 100);
×
UNCOV
68
    onProgress(percent, {loadedBytes, totalBytes});
×
UNCOV
69
    controller.enqueue(value);
×
UNCOV
70
    await read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError);
×
UNCOV
71
  } catch (error) {
×
72
    controller.error(error);
×
73
    onError(error);
×
74
  }
×
UNCOV
75
}
×
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