UNPKG

s2-tools

Version:

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

55 lines 1.42 kB
import { S2FileStore } from '../file'; /** File based multimap store */ export class FileKV { #store; /** * Builds a new MultiMap file store * @param fileName - the path + file name without the extension */ constructor(fileName) { this.#store = new S2FileStore(fileName); } /** @returns - the length of the map */ get length() { return this.#store.length; } /** * Adds a value to the list of values associated with a key * @param key - the key * @param value - the value to store */ set(key, value) { this.#store.set(key, value); } /** * Gets the list of values associated with a key * @param key - the key * @returns the list of values if the map contains values for the key */ async get(key) { const value = await this.#store.get(key, 0); if (value === undefined) return undefined; return value[0]; } /** * iterate through the values * @yields an iterator */ async *values() { for await (const { value } of this.#store.entries()) yield value; } /** * iterate through the values * @returns an iterator */ [Symbol.asyncIterator]() { return this.values(); } /** Closes the store */ close() { this.#store.close(true); } } //# sourceMappingURL=file.js.map