Blockstore implementation using LevelDB for storing the actual messages (in the case of MessageStore) or the data associated with messages (in the case of a DataStore).

Implements

  • Blockstore

Constructors

Properties

db: LevelWrapper<Uint8Array>

Methods

  • Remove the record for the passed key

    Parameters

    • key: string | CID<unknown, number, number, Version>
    • Optionaloptions: AbortOptions

    Returns Promise<void>

    await store.delete(new Key('awesome'))
    console.log('deleted awesome content :(')
  • Remove values for the passed keys

    Parameters

    • source: AwaitIterable<CID<unknown, number, number, Version>>
    • Optionaloptions: AbortOptions

    Returns AsyncIterable<CID<unknown, number, number, Version>, any, any>

    const source = [new Key('awesome')]

    for await (const key of store.deleteMany(source)) {
    console.log(`deleted content with key ${key}`)
    }
  • Retrieve the value stored under the given key

    Parameters

    • key: string | CID<unknown, number, number, Version>
    • Optionaloptions: AbortOptions

    Returns Promise<Uint8Array>

    const value = await store.get(new Key('awesome'))
    console.log('got content: %s', value.toString('utf8'))
    // => got content: datastore
  • Retrieve all cid/block pairs from the blockstore as an unordered iterable

    Parameters

    • Optionaloptions: AbortOptions

    Returns AsyncIterable<Pair, any, any>

    for await (const { multihash, block } of store.getAll()) {
    console.log('got:', multihash, block)
    // => got MultihashDigest('Qmfoo') Uint8Array[...]
    }
  • Retrieve values for the passed keys

    Parameters

    • source: AwaitIterable<CID<unknown, number, number, Version>>
    • Optionaloptions: AbortOptions

    Returns AsyncIterable<Pair, any, any>

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

    Parameters

    • key: string | CID<unknown, number, number, Version>
    • Optionaloptions: AbortOptions

    Returns Promise<boolean>

    const exists = await store.has(new Key('awesome'))

    if (exists) {
    console.log('it is there')
    } else {
    console.log('it is not there')
    }
  • Store the passed value under the passed key

    Parameters

    • key: string | CID<unknown, number, number, Version>
    • val: Uint8Array
    • Optionaloptions: AbortOptions

    Returns Promise<CID<unknown, number, number, Version>>

    await store.put([{ key: new Key('awesome'), value: new Uint8Array([0, 1, 2, 3]) }])
    
  • Store the given key/value pairs

    Parameters

    • source: AwaitIterable<Pair>
    • Optionaloptions: AbortOptions

    Returns AsyncIterable<CID<unknown, number, number, Version>, any, any>

    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}`)
    }