• 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

0.0
/modules/polyfills/src/images/encode-image-node.ts
1
// Use stackgl modules for DOM-less reading and writing of images
2

3
import savePixels from 'save-pixels';
4
import ndarray from 'ndarray';
5
import {bufferToArrayBuffer} from '../buffer/to-array-buffer.node';
6

7
/**
8
 * Returns data bytes representing a compressed image in PNG or JPG format,
9
 * This data can be saved using file system (f) methods or
10
 * used in a request.
11
 * @param image to save
12
 * @param options
13
 * @param options.type='png' - png, jpg or image/png, image/jpg are valid
14
 * @param options.dataURI - Whether to include a data URI header
15
 * @return {*} bytes
16
 */
17
export function encodeImageToStreamNode(
18
  image: {data: any; width: number; height: number},
19
  options: {type?: string; dataURI?: string}
20
) {
21
  // Support MIME type strings
UNCOV
22
  const type = options.type ? options.type.replace('image/', '') : 'jpeg';
×
UNCOV
23
  const pixels = ndarray(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);
×
24

25
  // Note: savePixels returns a stream
UNCOV
26
  return savePixels(pixels, type, options);
×
27
}
28

29
export function encodeImageNode(image, options) {
UNCOV
30
  const imageStream = encodeImageToStreamNode(image, options);
×
31

UNCOV
32
  return new Promise(resolve => {
×
UNCOV
33
    const buffers: any[] = [];
×
UNCOV
34
    imageStream.on('data', buffer => buffers.push(buffer));
×
35
    // TODO - convert to arraybuffer?
UNCOV
36
    imageStream.on('end', () => {
×
UNCOV
37
      const buffer = Buffer.concat(buffers);
×
UNCOV
38
      resolve(bufferToArrayBuffer(buffer));
×
39
    });
40
  });
41
}
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