New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maybe use the same Blockstore interface as @ipld/car #3
Comments
for fun, here is dagular using a CAR instead of the bit swap. Might be rad to be able to just pass in a CarReader and have it just work. import { Dagula } from 'dagula'
import { CarIndexedReader } from '@ipld/car/indexed-reader'
export async function carWalk (input) {
const carReader = await CarIndexedReader.fromFile(input)
const blockstore = new CarBlockStore(carReader)
const roots = await carReader.getRoots()
const dagula = new Dagula(blockstore)
try {
for await (const block of dagula.get(roots[0])) {
console.log(block.cid.toString())
}
} finally {
await carReader.close()
}
}
class CarBlockStore {
#carReader
constructor (carReader) {
this.#carReader = carReader
}
async get (cid) {
const block = await this.#carReader.get(cid)
if (!block) {
throw new Error('no such block')
}
return block.bytes
}
}
console.log(`dang ${process.argv[2]}`)
carWalk(process.argv[2]) |
👍 yes this is a good idea! |
alanshaw
added a commit
that referenced
this issue
Oct 11, 2022
BREAKING CHANGE: The blockstore interface used by this library has been updated. If passing a blockstore to the constructor it should return `undefined` if the block is not present in the blockstore. If it is present, it should return a `{ bytes: Uint8Array, cid: CID }` object (a "Block"). Secondly the `getBlock` method now returns a `Block` instead of a `Uint8Array`. resolves #3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was noodling around and wondered if I could re-use the dagula decode'n'walk logic on a CAR file. It was a success, but made slightly rougher by the different expectations of what a
Block{store|Reader}
'sget
method signature should be.dagular Blockstore
return a promise of the bytes or throw
source
@ipld/car BlockReader
return a promise of
{cid: CID, bytes: Uint8Array}
orundefined
source
The text was updated successfully, but these errors were encountered: