Skip to content

Instantly share code, notes, and snippets.

@alanshaw
Created May 13, 2022 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanshaw/86f674f3b6dd36c64ff5b42ab1bb400e to your computer and use it in GitHub Desktop.
Save alanshaw/86f674f3b6dd36c64ff5b42ab1bb400e to your computer and use it in GitHub Desktop.
// Lambda index CAR ////////////////////////////////////////////////////////////
const blocks = Set<CID>()
const links = Set<CID>()
const car = readCar(path)
for (const block in car) {
blocks.add(block.cid)
getLinks(block).forEach(cid => links.add(cid))
}
const structure = 'complete'
for (const [cid] of links.entries()) {
if (!blocks.has(cid)) {
structure = 'incomplete'
break
}
}
// mark structure in metadata
// write <rootCID>.cids
// Lambda determine complete ///////////////////////////////////////////////////
// fired when *.cids is written
const dir = dirname(event.triggerPath)
const cidsPaths = listDirectoryCids(dir)
const blocks = Set<CID>()
const links = Set<CID>()
for (const path of cidsPaths) {
readAndExtract(path, blocks, links)
}
for (const [cid] of links.entries()) {
if (!blocks.has(cid)) {
process.exit()
}
}
// IT COMPLETE!
// fire event
// const index = Map<CID, CID[]>()
// const dir = dirname(event.triggerPath)
// const carPaths = listDirectoryCars(dir)
// while (carPaths.length) {
// const path = carPaths.shift()
// const car = readCar(path)
// for (const block in car) {
// index.set(block.cid, getLinks(block))
// }
// let found = true
// for (const [cid, links] of index) {
// for (const l of links) {}
// if !index.has(l.cid) {
// found = false
// break
// }
// }
// if (!found) break
// }
// if (!found) {
// }
// if (listDirectoryCars(dir).lenght != carPaths.lenght){
// process.exit()
// }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment