nearfs
Version:
NEARFS is a distributed file system compatible with IPFS that uses the NEAR blockchain as a backend.
26 lines (22 loc) • 670 B
JavaScript
const fs = require('fs').promises;
const { readCID, readCAR, readBlock } = require('fast-ipfs');
const meow = require('meow');
const storage = require('../src/storage');
const cli = meow(`
Usage
write-car <car-file>
`, {
flags: {
},
});
// TODO: Check number of arguments given and give usage info
const [srcFile, accountId] = cli.input;
(async () => {
const carBuffer = await fs.readFile(srcFile);
const blocks = readCAR(carBuffer).slice(1).map(b => readBlock(b.data));
for (const block of blocks) {
const { data, cid } = block;
const { hash } = readCID(cid);
await storage.writeBlock(hash, data);
}
})();