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

visgl / loaders.gl / 20352515932

18 Dec 2025 09:56PM UTC coverage: 35.115% (-28.4%) from 63.485%
20352515932

push

github

web-flow
feat(loader-utils): Export is-type helpers (#3258)

1188 of 1998 branches covered (59.46%)

Branch coverage included in aggregate %.

147 of 211 new or added lines in 13 files covered. (69.67%)

30011 existing lines in 424 files now uncovered.

37457 of 108056 relevant lines covered (34.66%)

0.79 hits per line

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

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

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

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

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

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

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

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

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

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

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

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