-
Notifications
You must be signed in to change notification settings - Fork 47
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 CidFromReader #126
Comments
I think we should just expose the |
True, although the increasing use of It only needs the first few bytes, a maximum of maybe 10. So it's a nice combo that could be used to safely deal with the flexibility challenges. A maximal implementation could look like this and could also be used internally by a
That's probably too many return values and probably should be a |
Thanks to @ribasushi for reminding me of a relevant thread on identity lengths just now! multiformats/multihash#130 |
What you say makes sense; an "inspect" API for the cases where one wants to support potentially huge CIDs, and a "read" API for the cases where one doesn't need to support them - so erroring with e.g.
Returning a non-pointer struct shouldn't allocate; it should be practically equivalent to returning the list of parameters. It's more of a question of which is nicer in terms of API. You could also deduplicate the types in the return parameters, like:
|
We already have |
mm, you're right, I thought that was just for a strictly correct length number of bytes but that seems to do mostly what's needed here. We should try and use it in go-car to see what the limits are and what else we need to add. |
Confirming that CidFromBytes works for the cases where we're decoding from a buffer: ipld/go-car#131 That said, I think a CidFromReader would still be very useful. We need that for stream-like reading of CARv1 files, for example: https://ipld.io/specs/transport/car/carv1/#cid Right now we implement that in an internal package inside go-car, which is not ideal. Plus, we didn't implement CIDv0 decoding in that copy, so that's biting @raulk when he tries to use our carv2 module 🤦 I'll send a PR for CidFromReader shortly. |
I'm also not discarding having an "inspect" API in the future, but it's not useful for go-car right now, and it doesn't consume a fixed number of bytes, so... It's not clear to me that it's a clear win and needed right now. I'd put it off until someone actually needs it. |
And reuse a CidFromBytes test for it, which includes both CIDv0 and CIDv1 cases as inputs. Fixes #126.
Now at #127. |
And reuse a CidFromBytes test for it, which includes both CIDv0 and CIDv1 cases as inputs. Fixes #126.
And reuse a CidFromBytes test for it, which includes both CIDv0 and CIDv1 cases as inputs. Fixes #126.
And reuse a CidFromBytes test for it, which includes both CIDv0 and CIDv1 cases as inputs. Fixes #126.
And reuse two CidFromBytes tests for it, which includes both CIDv0 and CIDv1 cases as inputs, as well as some inputs that should error. Fixes #126.
And reuse two CidFromBytes tests for it, which includes both CIDv0 and CIDv1 cases as inputs, as well as some inputs that should error. Fixes #126.
We now have 2 CID decoder functions in go-car that really belong here and we should move (and properly test) them. The basic functionality is that I have either an
io.Reader
or just a[]byte
but I don't know how big the CID is but I'm pretty sure I know where the start of it is. I should be able to extract the CID and get an offset to the end of the parsed CID bytes.ReadCid(buf []byte) (cid.Cid, int, error)
- read aCid
frombuf
and tell me the offset after read: https://github.com/ipld/go-car/blob/71cfa2fc2a619d646606373c5946282934270bd4/util/util.go#L22ReadCid(store io.ReaderAt, at int64) (cid.Cid, int, error)
- read aCid
fromstore
and tell me the offset after read: https://github.com/ipld/go-car/blob/wip/v2/v2/internal/io/cid.go (wip/v2 branch, not yet in master).We have
decodeFirst(bytes)
in js-multiformats to serve a very similar purpose. Having it in the core library has uncovered some other uses outside of CAR decoding too.Suggestions for more explicit naming of these functions welcome!
The text was updated successfully, but these errors were encountered: