• 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

44.74
/modules/core/src/lib/api/encode-table.ts
1
// loaders.gl
2
// SPDX-License-Identifier: MIT
3
// Copyright (c) vis.gl contributors
4
// Copyright 2022 Foursquare Labs, Inc
5

6
/* global TextEncoder, TextDecoder */
7
import {
8
  concatenateArrayBuffers,
9
  ensureArrayBuffer,
10
  WriterOptionsType,
11
  WriterWithEncoder
12
} from '@loaders.gl/loader-utils';
13
import type {Table} from '@loaders.gl/schema';
14

15
export async function encodeTable<WriterT extends WriterWithEncoder = WriterWithEncoder>(
16
  data: Table,
17
  writer: WriterT,
18
  options?: WriterOptionsType<WriterT>
19
): Promise<ArrayBuffer> {
20
  if (writer.encode) {
27!
21
    return await writer.encode(data, options);
27✔
22
  }
23

24
  if (writer.encodeText) {
×
25
    const text = await writer.encodeText(data, options);
×
26
    return ensureArrayBuffer(new TextEncoder().encode(text));
×
27
  }
28

29
  if (writer.encodeInBatches) {
×
30
    // Create an iterator representing the data
31
    // TODO - Assumes this is a table
32
    const batches = encodeTableInBatches(data, writer, options);
×
33

34
    // Concatenate the output
UNCOV
35
    const chunks: ArrayBuffer[] = [];
×
UNCOV
36
    for await (const batch of batches) {
×
UNCOV
37
      chunks.push(batch);
×
38
    }
UNCOV
39
    return concatenateArrayBuffers(...chunks);
×
40
  }
41

UNCOV
42
  throw new Error('Writer could not encode data');
×
43
}
44

45
export async function encodeTableAsText<WriterT extends WriterWithEncoder = WriterWithEncoder>(
46
  data: Table,
47
  writer: WriterT,
48
  options?: WriterOptionsType<WriterT>
49
): Promise<string> {
50
  if (writer.text && writer.encodeText) {
27!
UNCOV
51
    return await writer.encodeText(data, options);
×
52
  }
53

54
  if (writer.text) {
27!
55
    const arrayBuffer = await encodeTable(data, writer, options);
27✔
56
    return new TextDecoder().decode(arrayBuffer);
27✔
57
  }
UNCOV
58
  throw new Error(`Writer ${writer.name} could not encode data as text`);
×
59
}
60

61
export function encodeTableInBatches<WriterT extends WriterWithEncoder = WriterWithEncoder>(
62
  data: Table,
63
  writer: WriterT,
64
  options?: WriterOptionsType<WriterT>
65
): AsyncIterable<ArrayBuffer> {
66
  if (writer.encodeInBatches) {
1!
67
    const dataIterator = getIterator(data);
1✔
68
    // @ts-expect-error
69
    return writer.encodeInBatches(dataIterator, options);
1✔
70
  }
71
  // TODO -fall back to atomic encode?
72
  throw new Error('Writer could not encode data in batches');
×
73
}
74

75
function getIterator(data: any): Iterable<{start: number; end: number}> {
76
  const dataIterator = [{...data, start: 0, end: data.length}];
1✔
77
  return dataIterator;
1✔
78
}
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