Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API to regenerate index from CARv1 or CARv2 #309

Merged
merged 1 commit into from
Jun 30, 2022

Conversation

masih
Copy link
Member

@masih masih commented Jun 29, 2022

The index generation APIs either allowed reading an existing index from
a CARv2 or explicitly required a CARv1 to generate index.

Introduce APIs to make it easier for users that want to regenerate the
index regardless of whether it exists in a CAR file or not. The index
generation APIs are changed to accept either of the formats and
re-generate the index from the data payload unless ReadOrGenerate is
called.

Adjust the tests to run for all flavours of index generation with both
CARv1 and CARv2 payload.

The index generation APIs either allowed reading an existing index from
a CARv2 or explicitly required a CARv1 to generate index.

Introduce APIs to make it easier for users that want to regenerate the
index regardless of whether it exists in a CAR file or not. The index
generation APIs are changed to accept either of the formats and
re-generate the index from the data payload unless `ReadOrGenerate` is
called.

Adjust the tests to run for all flavours of index generation with both
CARv1 and CARv2 payload.
@masih masih marked this pull request as ready for review June 29, 2022 15:29
@masih masih requested review from dirkmc, rvagg and willscott June 29, 2022 15:29
Copy link

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

if v2h.DataOffset < HeaderSize {
return fmt.Errorf("malformed CARv2; data offset too small: %d", v2h.DataOffset)
}
if v2h.DataSize < 1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a zero-length payload is still valid isn't it? it would just produce an empty index. not a big deal, zero payload probably means an error but strictly speaking I think 0 should be acceptable.

Copy link
Member Author

@masih masih Jun 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this when writing this statement. I actually think 1 might be too small. The rationale is that according to CARv2 spec the data size refers to the inner data payload size which should be a valid CARv1; as in the entire thing including the CARv1 header. At the danger of sounding pedantic (apologies if I do 🙂) accepting zero as DataSize would then mean an empty file is technically a valid CARv1?

That's why I think that value should be the minimum possible size for a CARv1, which is a CARv1 header with version value 1 and no roots which I think would come to 18 bytes.

WDYT?

Copy link
Member Author

@masih masih Jun 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the CARv1 should have at least one root CID, which increases the minimum acceptable CARv1 size.

The smallest CID I can think of is one with multihash code IDENTITY and empty data, which brings the total minimum CARv1 size to 26 bytes if my math is right.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the discussion out to a separate issue: #310

@masih masih merged commit 7ba9372 into master Jun 30, 2022
@masih masih deleted the masih/idx-gen-ver-agnostic branch June 30, 2022 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants