Skip to content

Commit

Permalink
test: add test for range request on multi block CAR
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzo committed Jan 19, 2024
1 parent 17abad7 commit 85ca49f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/car.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.car')
const carStream = fs.createReadStream(filepath)

const contentItr = await extractVerifiedContent(cidPath, carStream, { rangeStart: 25, rangeEnd: 49 })
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=25 count=25 | base64
const expectedContent = '6uhWxdSJTdQ9PilKs14dZUrANtlx/+rqIw=='

assert.strictEqual(actualContent, expectedContent)
})

it('should verify intermediate path segments', async () => {
const cidPath =
'bafybeigeqgfwhivuuxgmuvcrrwvs4j3yfzgljssvnuqzokm6uby4fpmwsa/subdir/hello.txt'
Expand Down
Binary file added test/fixtures/multi_block.car
Binary file not shown.

0 comments on commit 85ca49f

Please sign in to comment.