diff --git a/bin.js b/bin.js index ed29ea0..bca2547 100755 --- a/bin.js +++ b/bin.js @@ -47,6 +47,7 @@ cli cli .command('blocks [car]') .describe('List block CIDs from a CAR.') + .option('--verify', 'Verify block hash consistency.', true) .action(createAction('./cmd/blocks.js')) cli diff --git a/cmd/blocks.js b/cmd/blocks.js index 83240a5..422fe71 100644 --- a/cmd/blocks.js +++ b/cmd/blocks.js @@ -1,10 +1,20 @@ import fs from 'fs' -import { CarCIDIterator } from '@ipld/car/iterator' +import { validateBlock } from '@web3-storage/car-block-validator' +import { CarBlockIterator } from '@ipld/car/iterator' -/** @param {string} carPath */ -export default async function blocksList (carPath) { - const cids = await CarCIDIterator.fromIterable(carPath ? fs.createReadStream(carPath) : process.stdin) - for await (const cid of cids) { - console.log(cid.toString()) +/** + * @param {string} carPath + * @param {object} [opts] + * @param {boolean} [opts.verify] + */ +export default async function blocksList (carPath, opts) { + const blocks = await CarBlockIterator.fromIterable(carPath ? fs.createReadStream(carPath) : process.stdin) + for await (const block of blocks) { + /* c8 ignore next */ + if (opts?.verify || opts?.verify == null) { + // @ts-expect-error + await validateBlock(block) + } + console.log(block.cid.toString()) } }