Skip to content

Latest commit

ย 

History

History
117 lines (88 loc) ยท 2.68 KB

File metadata and controls

117 lines (88 loc) ยท 2.68 KB

BEHEMOTH

hashed blob storage. on opfs. in memory. on disk. in orbit.

  • ๐Ÿ—ฟ behemoth stores binary data, anywhere.
  • ๐Ÿ”’ content-addressable -- sha256 hashes for identity (never store a dupe)
  • ๐Ÿ”ฎ blob-oriented -- blobs provide random-access and are generally super cool
  • ๐Ÿž๏ธ stream-oriented -- streams allow you to upload/download big stuff smoothly
  • โ™ป๏ธ isomorphic -- runs in browsers or node
  • ๐Ÿ›ฐ๏ธ remote -- (coming soon) connect to a remote behemoth api service

๐Ÿ‰ abstract Behemoth

all behemoths have the same shape

Behemoth

  • .has(hash: Hash): Promise<boolean>
    const exists = await behemoth.has(hash)
  • .require(hash: Hash): Promise<Blob>
    const blob = await behemoth.require(hash)
  • .get(hash: Hash): Promise<Blob | undefined>
    const blob = await behemoth.get(hash)
  • .set(blob: Blob, options?: SetOptions): Promise<Hash>
    const hash = await behemoth.set(blob)
    const hash = await behemoth.set(blob, {
      onProgress: progress => {
        progress.total // number, total amount of work
        progress.done // number, amount of work completed
      },
    })
  • .delete(...hashes: Hash[]): Promise<void>
    await behemoth.delete(hash)

๐Ÿ‰ BehemothOpfs

store data in the browser's origin private file system

import {BehemothOpfs} from "@e280/behemoth"

const behemoth = await BehemothOpfs.mkdir("my-data")

๐Ÿ‰ BehemothDisk

store data to disk via node fs

import {BehemothDisk} from "@e280/behemoth/node"
 //                                         ๐Ÿ‘†

const behemoth = await BehemothDisk.mkdir("./my-data")

๐Ÿ‰ BehemothMemory

store data in memory

import {BehemothMemory} from "@e280/behemoth"

const behemoth = new BehemothMemory()

๐Ÿ‰ tools

handy tools you might wanna use

  • hashBlob(blob: Blob, onProgress: (hashed: number) => void): Promise<Hash>
    const hash = await hashBlob(blob)
    const hash = await hashBlob(blob, hashed => {
      console.log(`bytes hashed: ${hashed}`)
    })
  • readBlob(blob: Blob): AsyncGenerator<Uint8Array>
    for await (const chunk of readBlob(blob))
      chunk
  • readStream(stream: ReadableStream<Uint8Array>): AsyncGenerator<Uint8Array>
    for await (const chunk of readStream(stream))
      chunk



๐Ÿง‘โ€๐Ÿ’ป open source

e280.org, github stars plz