nim-dagger/ipfs/repo.nim

23 lines
411 B
Nim
Raw Normal View History

import std/tables
import std/hashes
2021-01-14 12:41:54 +00:00
import pkg/libp2p
import ./ipfsobject
export ipfsobject
type
Repo* = ref object
storage: Table[Cid, IpfsObject]
2021-01-14 12:41:54 +00:00
proc hash(id: Cid): Hash =
hash($id)
proc store*(repo: Repo, obj: IpfsObject) =
repo.storage[obj.cid] = obj
2021-01-14 12:41:54 +00:00
proc contains*(repo: Repo, id: Cid): bool =
repo.storage.hasKey(id)
proc retrieve*(repo: Repo, id: Cid): IpfsObject =
2021-01-14 12:41:54 +00:00
repo.storage[id]