• 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

30.43
/modules/gis/src/lib/utils/binary-writer.ts
1
// loaders.gl
1✔
2
// SPDX-License-Identifier: MIT
1✔
3
// Copyright (c) vis.gl contributors
1✔
4
// Forked from https://github.com/cschwarz/wkx under MIT license, Copyright (c) 2013 Christian Schwarz
1✔
5

1✔
6
import {TypedArray} from '@math.gl/types';
1✔
7

1✔
8
const LE = true;
1✔
9
const BE = false;
1✔
10

1✔
11
export class BinaryWriter {
1✔
12
  arrayBuffer: ArrayBuffer;
1!
UNCOV
13
  dataView: DataView;
×
UNCOV
14
  byteOffset: number = 0;
×
UNCOV
15
  allowResize: boolean = false;
×
16

1✔
17
  constructor(size: number, allowResize?: boolean) {
1✔
UNCOV
18
    this.arrayBuffer = new ArrayBuffer(size);
×
UNCOV
19
    this.dataView = new DataView(this.arrayBuffer);
×
UNCOV
20
    this.byteOffset = 0;
×
UNCOV
21
    this.allowResize = allowResize || false;
×
UNCOV
22
  }
×
23

1✔
24
  writeUInt8(value: number): void {
1✔
25
    this._ensureSize(1);
×
26
    this.dataView.setUint8(this.byteOffset, value);
×
27
    this.byteOffset += 1;
×
28
  }
×
29
  writeUInt16LE(value: number): void {
1✔
30
    this._ensureSize(2);
×
31
    this.dataView.setUint16(this.byteOffset, value, LE);
×
32
    this.byteOffset += 2;
×
33
  }
×
34
  writeUInt16BE(value: number): void {
1✔
35
    this._ensureSize(2);
×
36
    this.dataView.setUint16(this.byteOffset, value, BE);
×
37
    this.byteOffset += 2;
×
38
  }
×
39
  writeUInt32LE(value: number): void {
1✔
UNCOV
40
    this._ensureSize(4);
×
UNCOV
41
    this.dataView.setUint32(this.byteOffset, value, LE);
×
UNCOV
42
    this.byteOffset += 4;
×
UNCOV
43
  }
×
44
  writeUInt32BE(value: number): void {
1✔
45
    this._ensureSize(4);
×
46
    this.dataView.setUint32(this.byteOffset, value, BE);
×
47
    this.byteOffset += 4;
×
48
  }
×
49
  writeInt8(value: number): void {
1✔
UNCOV
50
    this._ensureSize(1);
×
UNCOV
51
    this.dataView.setInt8(this.byteOffset, value);
×
UNCOV
52
    this.byteOffset += 1;
×
UNCOV
53
  }
×
54
  writeInt16LE(value: number): void {
1✔
55
    this._ensureSize(2);
×
56
    this.dataView.setInt16(this.byteOffset, value, LE);
×
57
    this.byteOffset += 2;
×
58
  }
×
59
  writeInt16BE(value: number): void {
1✔
60
    this._ensureSize(2);
×
61
    this.dataView.setInt16(this.byteOffset, value, BE);
×
62
    this.byteOffset += 2;
×
63
  }
×
64
  writeInt32LE(value: number): void {
1✔
65
    this._ensureSize(4);
×
66
    this.dataView.setInt32(this.byteOffset, value, LE);
×
67
    this.byteOffset += 4;
×
68
  }
×
69
  writeInt32BE(value: number): void {
1✔
70
    this._ensureSize(4);
×
71
    this.dataView.setInt32(this.byteOffset, value, BE);
×
72
    this.byteOffset += 4;
×
73
  }
×
74
  writeFloatLE(value: number): void {
1✔
75
    this._ensureSize(4);
×
76
    this.dataView.setFloat32(this.byteOffset, value, LE);
×
77
    this.byteOffset += 4;
×
78
  }
×
79
  writeFloatBE(value: number): void {
1✔
80
    this._ensureSize(4);
×
81
    this.dataView.setFloat32(this.byteOffset, value, BE);
×
82
    this.byteOffset += 4;
×
83
  }
×
84
  writeDoubleLE(value: number): void {
1✔
UNCOV
85
    this._ensureSize(8);
×
UNCOV
86
    this.dataView.setFloat64(this.byteOffset, value, LE);
×
UNCOV
87
    this.byteOffset += 8;
×
UNCOV
88
  }
×
89
  writeDoubleBE(value: number): void {
1✔
90
    this._ensureSize(8);
×
91
    this.dataView.setFloat64(this.byteOffset, value, BE);
×
92
    this.byteOffset += 8;
×
93
  }
×
94

1✔
95
  /** A varint uses a variable number of bytes */
1✔
96
  writeVarInt(value: number): number {
1✔
97
    // TODO - ensure size?
×
98
    let length = 1;
×
99
    while ((value & 0xffffff80) !== 0) {
×
100
      this.writeUInt8((value & 0x7f) | 0x80);
×
101
      value >>>= 7;
×
102
      length++;
×
103
    }
×
104
    this.writeUInt8(value & 0x7f);
×
105
    return length;
×
106
  }
×
107

1✔
108
  writeTypedArray(typedArray: TypedArray) {
1✔
109
    this._ensureSize(typedArray.byteLength);
×
110
    const tempArray = new Uint8Array(this.arrayBuffer);
×
111
    tempArray.set(typedArray, this.byteOffset);
×
112
    this.byteOffset += typedArray.byteLength;
×
113
  }
×
114

1✔
115
  /** Append another ArrayBuffer to this ArrayBuffer */
1✔
116
  writeBuffer(arrayBuffer: ArrayBuffer): void {
1✔
UNCOV
117
    this._ensureSize(arrayBuffer.byteLength);
×
UNCOV
118
    const tempArray = new Uint8Array(this.arrayBuffer);
×
UNCOV
119
    tempArray.set(new Uint8Array(arrayBuffer), this.byteOffset);
×
UNCOV
120
    this.byteOffset += arrayBuffer.byteLength;
×
UNCOV
121
  }
×
122

1✔
123
  /** Resizes this.arrayBuffer if not enough space */
1✔
124
  _ensureSize(size: number) {
1✔
UNCOV
125
    if (this.arrayBuffer.byteLength < this.byteOffset + size) {
×
126
      if (this.allowResize) {
×
127
        const newArrayBuffer = new ArrayBuffer(this.byteOffset + size);
×
128
        const tempArray = new Uint8Array(newArrayBuffer);
×
129
        tempArray.set(new Uint8Array(this.arrayBuffer));
×
130
        this.arrayBuffer = newArrayBuffer;
×
131
      } else {
×
132
        throw new Error('BinaryWriter overflow');
×
133
      }
×
134
    }
×
UNCOV
135
  }
×
136
}
1✔
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