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

visgl / loaders.gl / 24907303489

24 Apr 2026 07:12PM UTC coverage: 59.423% (+0.09%) from 59.334%
24907303489

push

github

web-flow
feat: Dynamic import loaders (#3405)

11252 of 20783 branches covered (54.14%)

Branch coverage included in aggregate %.

1164 of 1518 new or added lines in 244 files covered. (76.68%)

41 existing lines in 18 files now uncovered.

23432 of 37585 relevant lines covered (62.34%)

16317.58 hits per line

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

86.67
/modules/zip/src/zip-loader-with-parser.ts
1
// loaders.gl
2
// SPDX-License-Identifier: MIT
3
// Copyright (c) vis.gl contributors
4

5
import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
6
import JSZip from 'jszip';
1✔
7
import {ZipLoader as ZipLoaderMetadata} from './zip-loader';
8

9
const {preload: _ZipLoaderPreload, ...ZipLoaderMetadataWithoutPreload} = ZipLoaderMetadata;
2✔
10

11
type FileMap = Record<string, ArrayBuffer>;
12

13
export const ZipLoaderWithParser = {
2✔
14
  ...ZipLoaderMetadataWithoutPreload,
15
  parse: parseZipAsync
16
} as const satisfies LoaderWithParser<FileMap, never, LoaderOptions>;
17

18
// TODO - Could return a map of promises, perhaps as an option...
19
async function parseZipAsync(data: any, options = {}): Promise<FileMap> {
8✔
20
  const promises: Promise<any>[] = [];
8✔
21
  const fileMap: Record<string, ArrayBuffer> = {};
8✔
22

23
  try {
8✔
24
    const jsZip = new JSZip();
8✔
25

26
    const zip = await jsZip.loadAsync(data, options);
8✔
27

28
    // start to load each file in this zip
29
    zip.forEach((relativePath, zipEntry) => {
8✔
30
      if (zipEntry.dir) {
28✔
31
        return;
10✔
32
      }
33

34
      const subFilename = zipEntry.name;
18✔
35

36
      const promise = loadZipEntry(jsZip, subFilename, options).then(arrayBufferOrError => {
18✔
37
        fileMap[relativePath] = arrayBufferOrError;
18✔
38
      });
39

40
      // Ensure Promise.all doesn't ignore rejected promises.
41
      promises.push(promise);
18✔
42
    });
43

44
    await Promise.all(promises);
8✔
45
    return fileMap;
8✔
46
  } catch (error) {
47
    // @ts-ignore
NEW
48
    options.log.error(`Unable to read zip archive: ${error}`);
×
NEW
49
    throw error;
×
50
  }
51
}
52

53
async function loadZipEntry(jsZip: any, subFilename: string, options: any = {}) {
18✔
54
  // jszip supports both arraybuffer and text, the main loaders.gl types
55
  // https://stuk.github.io/jszip/documentation/api_zipobject/async.html
56
  try {
18✔
57
    const arrayBuffer = await jsZip.file(subFilename).async(options.dataType || 'arraybuffer');
18✔
58
    return arrayBuffer;
18✔
59
  } catch (error) {
NEW
60
    options.log.error(`Unable to read ${subFilename} from zip archive: ${error}`);
×
61
    // Store error in place of data in map
NEW
62
    return error;
×
63
  }
64
}
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