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

visgl / loaders.gl / 20382848403

19 Dec 2025 09:20PM UTC coverage: 35.219% (+0.1%) from 35.095%
20382848403

push

github

web-flow
feat: Upgrade to handle ArrayBufferLike (#3271)

1190 of 2002 branches covered (59.44%)

Branch coverage included in aggregate %.

157 of 269 new or added lines in 41 files covered. (58.36%)

3 existing lines in 3 files now uncovered.

37536 of 107957 relevant lines covered (34.77%)

0.79 hits per line

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

40.35
/modules/polyfills/src/images/parse-image-node.ts
1
// loaders.gl
1✔
2
// SPDX-License-Identifier: MIT
1✔
3
// Copyright (c) vis.gl contributors
1✔
4

1✔
5
import getPixels from 'get-pixels';
1!
6

1✔
7
/** Declares which image format mime types this loader polyfill supports */
1✔
8
export const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
1✔
9

1✔
10
// Note: These types are also defined in @loaders.gl/images and need to be kept in sync
1✔
11
type NDArray = {
1✔
12
  shape: number[];
1✔
13
  data: Uint8Array;
1✔
14
  width: number;
1✔
15
  height: number;
1✔
16
  components: number;
1✔
17
  layers: number[];
1✔
18
};
1✔
19

1✔
20
export async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {
×
21
  if (!mimeType) {
×
22
    throw new Error('MIMEType is required to parse image under Node.js');
×
23
  }
×
24

×
25
  const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
×
26
  const ndarray = await getPixelsAsync(buffer, mimeType);
×
27
  return ndarray;
×
28
}
×
29

1✔
30
// TODO - check if getPixels callback is asynchronous if provided with buffer input
1✔
31
// if not, parseImage can be a sync function
1✔
32
function getPixelsAsync(buffer: Buffer, mimeType: string): Promise<NDArray> {
×
33
  return new Promise<NDArray>((resolve) =>
×
NEW
34
    getPixels(buffer as any, mimeType, (err, ndarray) => {
×
35
      if (err) {
×
36
        throw err;
×
37
      }
×
38

×
39
      const shape = [...ndarray.shape];
×
40
      const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
×
41
      const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
×
42

×
43
      // extract width/height etc
×
44
      resolve({
×
45
        shape,
×
46
        data,
×
47
        width: ndarray.shape[0],
×
48
        height: ndarray.shape[1],
×
49
        components: ndarray.shape[2],
×
50
        // TODO - error
×
51
        layers: layers ? [layers] : []
×
52
      });
×
53
    })
×
54
  );
×
55
}
×
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