UNPKG

s2-tools

Version:

A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.

82 lines 2.71 kB
export * from './csv'; export * from './gbfs'; export * from './geotiff'; export * from './grib2'; export * from './gtfs'; export * from './image'; export * from './json'; export * from './netcdf'; export * from './osm'; export * from './pmtiles'; export * from './protobuf'; export * from './shapefile'; export * from './wkt'; export * from './xml'; export * from './fetch'; export * from './nadgrid'; export * from './tile'; /** * Convenience function that ensures the input is a usable reader * @param input - the input data * @returns - a BufferReader */ export function toReader(input) { if (input instanceof BufferReader) return input; else if ('buffer' in input) return new BufferReader(input.buffer); else if (input instanceof ArrayBuffer || input instanceof SharedArrayBuffer) return new BufferReader(input); else return input; } /** A buffer reader is an extension of a DataView with some extra methods */ export class BufferReader extends DataView { textDecoder = new TextDecoder('utf-8'); /** * @param buffer - the input buffer * @param byteOffset - offset in the buffer * @param byteLength - length of the buffer */ constructor(buffer, byteOffset, byteLength) { super(buffer, byteOffset, byteLength); } /** * Get a slice of the buffer * @param begin - beginning of the slice * @param end - end of the slice. If not provided, the end of the data is used * @returns - a DataView of the slice */ slice(begin, end) { return new DataView(this.buffer.slice(this.byteOffset + (begin ?? 0), this.byteOffset + (end ?? this.byteLength))); } /** * Set the text decoder's encoding * @param encoding - update the text decoder's encoding */ setStringEncoding(encoding) { this.textDecoder = new TextDecoder(encoding); } /** * Reads a string from the buffer * @param byteOffset - Start of the string * @param byteLength - Length of the string * @returns - The string */ parseString(byteOffset, byteLength) { const { textDecoder } = this; const data = this.slice(byteOffset, byteOffset + byteLength).buffer; const out = textDecoder.decode(data, { stream: true }) + textDecoder.decode(); return out.replace(/\0/g, '').trim(); } /** * Reads a range from the buffer * @param offset - the offset of the range * @param length - the length of the range * @returns - the ranged buffer */ async getRange(offset, length) { return await new Uint8Array(this.buffer).slice(offset, offset + length); } } //# sourceMappingURL=index.js.map