A datastore backed by the file system.

Keys need to be sanitized before use, as they are written to the file system as is.

Hierarchy (view full)

Constructors

Properties

createIfMissing: boolean
deleteManyConcurrency: number
errorIfExists: boolean
extension: string
getManyConcurrency: number
path: string
putManyConcurrency: number

Methods

  • Calculate the directory and file name for a given key.

    Parameters

    Returns {
        dir: string;
        file: string;
    }

    • dir: string
    • file: string
  • This will return an object with which you can chain multiple operations together, with them only being executed on calling commit.

    Returns Batch<{}>

    Example

    const b = store.batch()

    for (let i = 0; i < 100; i++) {
    b.put(new Key(`hello${i}`), new TextEncoder('utf8').encode(`hello world ${i}`))
    }

    await b.commit()
    console.log('put 100 values')
  • Retrieve values for the passed keys

    Parameters

    Returns AsyncIterable<Pair>

    Example

    for await (const { key, value } of store.getMany([new Key('awesome')])) {
    console.log(`got "${key}" = "${new TextDecoder('utf8').decode(value)}"`')
    // => got "/awesome" = "datastore"
    }
  • Store the given key/value pairs

    Parameters

    Returns AsyncIterable<Key>

    Example

    const source = [{ key: new Key('awesome'), value: new Uint8Array([0, 1, 2, 3]) }]

    for await (const { key, value } of store.putMany(source)) {
    console.info(`put content for key ${key}`)
    }
  • Query the datastore.

    Parameters

    Returns AwaitIterable<Pair>

    Example

    // retrieve __all__ key/value pairs from the store
    let list = []
    for await (const { key, value } of store.query({})) {
    list.push(value)
    }
    console.log('ALL THE VALUES', list)
  • Query the datastore.

    Parameters

    Returns AwaitIterable<Key>

    Example

    // retrieve __all__ keys from the store
    let list = []
    for await (const key of store.queryKeys({})) {
    list.push(key)
    }
    console.log('ALL THE KEYS', key)