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

http retrieve entire piece (not just CAR file) #640

Merged
merged 1 commit into from
Jul 7, 2022
Merged

Conversation

dirkmc
Copy link
Contributor

@dirkmc dirkmc commented Jul 7, 2022

To retrieve a piece:
http://localhost:7777/piece/<piece cid>
To retrieve a CAR:
http://localhost:7777/piece/<piece cid>.car

Comment on lines 200 to +203
content, err := s.getPieceContent(ctx, pieceCid)
if err == nil && isCar {
content, err = s.getCarContent(pieceCid, content)
}
Copy link
Member

Choose a reason for hiding this comment

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

Aren't getPieceContent and getCarContent expensive operations? Shouldn't we do one or the other, but not override content when isCar == true ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case content is an io.ReadSeeker
getPieceContent gets a reader over the unsealed piece.
if isCar == true then getCarContent figures out the size of the CAR file by asking the DAG store for the max offset of the CAR index. If the DAG store doesn't have the index, getCarContent creates the index on the fly. Once it has the max offset, it just wraps the piece reader with a limit reader so that it only serves the CAR file.

@dirkmc dirkmc merged commit 3b542c3 into main Jul 7, 2022
@dirkmc dirkmc deleted the feat/retrieve-piece branch July 7, 2022 08:51
@mikeal
Copy link

mikeal commented Aug 3, 2022

🤩

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.

3 participants