• 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

24.05
/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
  ensureArrayBuffer,
1✔
10
  WriterOptionsType,
1✔
11
  WriterWithEncoder
1✔
12
} from '@loaders.gl/loader-utils';
1✔
13
import type {Table} from '@loaders.gl/schema';
1✔
14

1✔
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) {
×
21
    return await writer.encode(data, options);
×
22
  }
×
23

×
24
  if (writer.encodeText) {
×
25
    const text = await writer.encodeText(data, options);
×
NEW
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
×
35
    const chunks: ArrayBuffer[] = [];
×
36
    for await (const batch of batches) {
×
37
      chunks.push(batch);
×
38
    }
×
39
    return concatenateArrayBuffers(...chunks);
×
40
  }
×
41

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

1✔
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) {
×
51
    return await writer.encodeText(data, options);
×
52
  }
×
53

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

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

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