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

visgl / loaders.gl / 24153816851

08 Apr 2026 07:17PM UTC coverage: 53.247% (-12.1%) from 65.319%
24153816851

push

github

web-flow
chore: Move from tape to vitest (#3351)

8651 of 17291 branches covered (50.03%)

Branch coverage included in aggregate %.

7 of 7 new or added lines in 1 file covered. (100.0%)

2031 existing lines in 296 files now uncovered.

17563 of 31940 relevant lines covered (54.99%)

5279.54 hits per line

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

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

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

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

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

44
  return new Response(progressStream);
1✔
45
}
46

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