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

New SumStream function reads from io.Reader #138

Merged
merged 2 commits into from
Apr 6, 2021
Merged

New SumStream function reads from io.Reader #138

merged 2 commits into from
Apr 6, 2021

Conversation

gammazero
Copy link
Contributor

This provides a way to read from a stream instead of having to load a potentially large file into memory first.

Addresses issue #15

This provides a way to read from a stream instead of having to load a potentially large file into memory first.
Copy link
Contributor

@warpfork warpfork left a comment

Choose a reason for hiding this comment

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

Unfortunately I find myself asking for slightly less DRY code. But otherwise this LGTM!

sum.go Outdated
func Sum(data []byte, code uint64, length int) (Multihash, error) {
return SumStream(bytes.NewReader(data), code, length)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm afraid we should take the hit of some duplicated code here, in exchange for keeping this a single []byte handoff without reader indirections. We'd rather not add one or more allocations to all code which currently uses this function with smallish byte slices.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored to write []byte directly without wrapping in bytes.Reader, with minimal code dup.

@warpfork warpfork merged commit 75ae368 into multiformats:master Apr 6, 2021
@warpfork
Copy link
Contributor

warpfork commented Apr 6, 2021

Thanks for adding this! It really connects the dots well.

@gammazero gammazero deleted the read-from-stream branch April 6, 2021 19:14
@aschmahmann aschmahmann mentioned this pull request Dec 1, 2021
80 tasks
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.

2 participants