UNPKG

mc-anvil

Version:

A Typescript library for reading Minecraft Anvil format files and Minecraft NBT format files in the browser.

46 lines 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ResizableBinaryWriter = void 0; const binary_1 = require("./binary"); class ResizableBinaryWriter extends binary_1.BinaryParser { constructor() { super(...arguments); this.setByte = (value) => this.setValue(value, 1, super.setByte.bind(this)); this.setShort = (value) => this.setValue(value, 2, super.setShort.bind(this)); this.setUShort = (value) => this.setValue(value, 2, super.setUShort.bind(this)); this.setInt = (value) => this.setValue(value, 4, super.setInt.bind(this)); this.setUInt = (value) => this.setValue(value, 4, super.setUInt.bind(this)); this.setFloat = (value) => this.setValue(value, 4, super.setFloat.bind(this)); this.setDouble = (value) => this.setValue(value, 8, super.setDouble.bind(this)); this.setInt64 = (value) => this.setValue(value, 8, super.setInt64.bind(this)); this.setUInt64 = (value) => this.setValue(value, 8, super.setUInt64.bind(this)); this.setInt64LE = (value) => this.setValue(value, 8, super.setInt64LE.bind(this)); this.setUInt64LE = (value) => this.setValue(value, 8, super.setUInt64LE.bind(this)); this.setString = (value) => this.setValue(value, value.length + 1, super.setString.bind(this)); this.setFixedLengthString = (value) => this.setValue(value, value.length, super.setFixedLengthString.bind(this)); } resize() { const newBuffer = new ArrayBuffer(this.view.byteLength * 2); new Uint8Array(newBuffer).set(new Uint8Array(this.view.buffer)); this.view = new DataView(newBuffer); this.bindReaders(); } setValue(value, size, setValueF) { while (size > this.remainingLength()) this.resize(); setValueF(value); } setArrayBuffer(value) { while (value.byteLength > this.remainingLength()) this.resize(); new Uint8Array(this.view.buffer).set(new Uint8Array(value), this.currentPosition()); this.position += value.byteLength; } setNByteInteger(value, size) { while (size > this.remainingLength()) this.resize(); super.setNByteInteger(value, size); } } exports.ResizableBinaryWriter = ResizableBinaryWriter; //# sourceMappingURL=writer.js.map