UNPKG

well-known-parser

Version:

A WKT/WKB/EWKT/EWKB/TWKB/GeoJSON parser and serializer

69 lines (68 loc) 2.35 kB
class e { constructor(i, t = !1) { this.buffer = Buffer.alloc(i), this.position = 0, this.allowResize = t; } ensureSize(i) { if (this.buffer.length < this.position + i) if (this.allowResize) { const t = Buffer.alloc(this.position + i); this.buffer.copy(t, 0, 0, this.buffer.length), this.buffer = t; } else throw new RangeError("index out of range"); } writeUInt8(i) { this.ensureSize(1), this.buffer.writeUInt8(i, this.position), this.position += 1; } writeUInt16LE(i) { this.ensureSize(2), this.buffer.writeUInt16LE(i, this.position), this.position += 2; } writeUInt16BE(i) { this.ensureSize(2), this.buffer.writeUInt16BE(i, this.position), this.position += 2; } writeUInt32LE(i) { this.ensureSize(4), this.buffer.writeUInt32LE(i, this.position), this.position += 4; } writeUInt32BE(i) { this.ensureSize(4), this.buffer.writeUInt32BE(i, this.position), this.position += 4; } writeInt8(i) { this.ensureSize(1), this.buffer.writeInt8(i, this.position), this.position += 1; } writeInt16LE(i) { this.ensureSize(2), this.buffer.writeInt16LE(i, this.position), this.position += 2; } writeInt16BE(i) { this.ensureSize(2), this.buffer.writeInt16BE(i, this.position), this.position += 2; } writeInt32LE(i) { this.ensureSize(4), this.buffer.writeInt32LE(i, this.position), this.position += 4; } writeInt32BE(i) { this.ensureSize(4), this.buffer.writeInt32BE(i, this.position), this.position += 4; } writeFloatLE(i) { this.ensureSize(4), this.buffer.writeFloatLE(i, this.position), this.position += 4; } writeFloatBE(i) { this.ensureSize(4), this.buffer.writeFloatBE(i, this.position), this.position += 4; } writeDoubleLE(i) { this.ensureSize(8), this.buffer.writeDoubleLE(i, this.position), this.position += 8; } writeDoubleBE(i) { this.ensureSize(8), this.buffer.writeDoubleBE(i, this.position), this.position += 8; } writeBuffer(i) { this.ensureSize(i.length), i.copy(this.buffer, this.position, 0, i.length), this.position += i.length; } writeVarInt(i) { let t = 1; for (; (i & 4294967168) !== 0; ) this.writeUInt8(i & 127 | 128), i >>>= 7, t++; return this.writeUInt8(i & 127), t; } } export { e as BinaryWriter }; //# sourceMappingURL=well-known-parser12.js.map