-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): check block hash consistency when listing blocks (#157)
- Loading branch information
Alan Shaw
authored
Dec 8, 2023
1 parent
0144a86
commit 273079f
Showing
2 changed files
with
17 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
} | ||
} |