Created
May 13, 2022 14:58
-
-
Save alanshaw/86f674f3b6dd36c64ff5b42ab1bb400e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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