Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface API<OptionExtension>

Type parameters

  • OptionExtension = {}

Hierarchy

  • API

Index

Methods

  • get(cid: CID, options?: AbortOptions & PreloadOptions & OptionExtension): Promise<Uint8Array>
  • Get a raw IPFS block

    example
    const block = await ipfs.block.get(cid)
    console.log(block)

    Parameters

    • cid: CID
    • Optional options: AbortOptions & PreloadOptions & OptionExtension

    Returns Promise<Uint8Array>

  • put(block: Uint8Array, options?: PutOptions & OptionExtension): Promise<CID>
  • Stores a Uint8Array as a block in the underlying blockstore

    example
    import * as dagPB from '@ipld/dag-pb'
    // Defaults
    const encoder = new TextEncoder()
    const decoder = new TextDecoder()

    const bytes = encoder.encode('a serialized object')
    const cid = await ipfs.block.put(bytes)

    console.log(decoder.decode(block.data))
    // Logs:
    // a serialized object
    console.log(block.cid.toString())
    // Logs:
    // the CID of the object

    // With custom format and hashtype through CID
    import { CID } from 'multiformats/cid'
    const another = encoder.encode('another serialized object')
    const cid = CID.createV1(dagPB.code, multihash)
    const block = await ipfs.block.put(another, cid)
    console.log(decoder.decode(block.data))

    // Logs:
    // a serialized object
    console.log(block.cid.toString())
    // Logs:
    // the CID of the object

    Parameters

    • block: Uint8Array
    • Optional options: PutOptions & OptionExtension

    Returns Promise<CID>

  • Remove one or more IPFS block(s) from the underlying block store

    example
    for await (const result of ipfs.block.rm(cid)) {
    if (result.error) {
    console.error(`Failed to remove block ${result.cid} due to ${result.error.message}`)
    } else {
    console.log(`Removed block ${result.cid}`)
    }
    }

    Parameters

    • cid: CID | CID[]
    • Optional options: RmOptions & OptionExtension

    Returns AsyncIterable<RmResult>

  • Print information of a raw IPFS block

    example
    const cid = CID.parse('QmQULBtTjNcMwMr4VMNknnVv3RpytrLSdgpvMcTnfNhrBJ')
    const stats = await ipfs.block.stat(cid)
    console.log(stats.cid.toString())
    // Logs: QmQULBtTjNcMwMr4VMNknnVv3RpytrLSdgpvMcTnfNhrBJ
    console.log(stat.size)
    // Logs: 3739

    Parameters

    • cid: CID
    • Optional options: AbortOptions & PreloadOptions & OptionExtension

    Returns Promise<StatResult>

Generated using TypeDoc