diff --git a/package.json b/package.json index ee20e1f..ce2c58a 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "src/index.js", "type": "module", "scripts": { - "test": "NODE_ENV=development TESTING=true node --test test/", + "test": "NODE_ENV=development TESTING=true node --test test/*", "build": "webpack --mode production", "prepack": "npm run build" }, diff --git a/test/car.spec.js b/test/car.spec.js index b1305c9..36217c8 100644 --- a/test/car.spec.js +++ b/test/car.spec.js @@ -79,6 +79,23 @@ describe('CAR Verification', () => { assert.strictEqual(actualContent, expectedContent) }) + it('should extract content from a valid multi block CAR with a range', async () => { + const cidPath = 'QmStvUMCtXxEb8wRjNSUqWwqHBEDhmnEd5nHp5siV7bm1Z' + const filepath = getFixturePath('multi_block_filtered.car') + const carStream = fs.createReadStream(filepath) + + const contentItr = await extractVerifiedContent(cidPath, carStream, { rangeStart: 300, rangeEnd: 349 }) + const buffer = await concatChunks(contentItr) + const actualContent = Buffer.from(buffer).toString('base64') + + // To get this value: + // $ mkdir -p outdir && car x -f multi_block.car outdir + // $ dd status=none if=outdir/unknown of=/dev/stdout bs=1 skip=300 count=50 | base64 + const expectedContent = 'Dubn28NGm5/ycJu4PqXEFrgvN0ys0yAwhuYjl2TV23ruEcDazo4LAzZSKF3JeNfCNgg=' + + assert.strictEqual(actualContent, expectedContent) + }) + it('should verify intermediate path segments', async () => { const cidPath = 'bafybeigeqgfwhivuuxgmuvcrrwvs4j3yfzgljssvnuqzokm6uby4fpmwsa/subdir/hello.txt' diff --git a/test/fixtures/multi_block.car b/test/fixtures/multi_block.car new file mode 100644 index 0000000..b3e5d0c Binary files /dev/null and b/test/fixtures/multi_block.car differ diff --git a/test/fixtures/multi_block_filtered.car b/test/fixtures/multi_block_filtered.car new file mode 100644 index 0000000..1e4e946 Binary files /dev/null and b/test/fixtures/multi_block_filtered.car differ