@loaders.gl/json
Version:
Framework-independent loader for JSON and streaming JSON formats
32 lines • 900 B
JavaScript
// loaders.gl
// SPDX-License-Identifier: MIT
import { ensureArrayBuffer } from '@loaders.gl/loader-utils';
/* global TextEncoder */
export class Utf8ArrayBufferEncoder {
chunkSize;
strings = [];
totalLength = 0;
textEncoder = new TextEncoder();
constructor(chunkSize) {
this.chunkSize = chunkSize;
}
push(...strings) {
for (const string of strings) {
this.strings.push(string);
this.totalLength += string.length;
}
}
isFull() {
return this.totalLength >= this.chunkSize;
}
getArrayBufferBatch() {
return ensureArrayBuffer(this.textEncoder.encode(this.getStringBatch()).buffer);
}
getStringBatch() {
const stringChunk = this.strings.join('');
this.strings = [];
this.totalLength = 0;
return stringChunk;
}
}
//# sourceMappingURL=utf8-encoder.js.map