-
Notifications
You must be signed in to change notification settings - Fork 26
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
More flexible fs.ChecksumCalculator #167
More flexible fs.ChecksumCalculator #167
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to understand the intention of an API like this. How would it be used? What use-cases is it solving for?
028a7ba
to
e80baa4
Compare
n, err := c.hash.Write(p) | ||
if err != nil { | ||
return n, err | ||
} | ||
return n, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n, err := c.hash.Write(p) | |
if err != nil { | |
return n, err | |
} | |
return n, err | |
return c.hash.Write(p) |
Unless you intend to do something different in the error case, these are logically equivalent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'm debating if it makes sense to hide n entirely from the return is all.
Introduces the following methods: - WriteFiles(files ...string) (error) - Write(p []byte) (int, error) - SumAsHexString() Sum(files ...string) (string, error) remains for backward compatability.
e80baa4
to
50f4366
Compare
If or when we decide something like this API is OK I should backfill tests for the public methods. Right now the new additions are tested indirectly because |
I think it could make sense to expose some of these lower-level APIs to the buildpack author, but I think it may make more sense as a new type that is distinct from the type Checksum struct {
hash hash.Hash
}
func (c Checksum) WritePaths(paths ...string) error {
// recursively hashes a filepath, keeping state in c.hash
}
func (c Checksum) Write(b []byte) (int, error) {
// writes b into c.hash
}
func (c Checksum) EncodeToString() string {
// returns a hex string encoding of the hash value
} |
Sounds good. I’ll take a crack at it.
…On Wed, Jun 9, 2021 at 10:18 AM Ryan Moran ***@***.***> wrote:
I think it could make sense to expose some of these lower-level APIs to
the buildpack author, but I think it may make more sense as a new type that
is distinct from the fs.ChecksumCalculator. Specifically, I think the
proposed changes break an implicit contract which is that the
fs.ChecksumCalculator is stateless. The new API moves state into the
calculator and thus makes it difficult to reuse or use in cases of parallel
operation. I'd like to propose a different API that would create a new
stateful type that can be reused by the fs.ChecksumCalculator and
therefore keep this implicit stateless contract in-place.
type Checksum struct {
hash hash.Hash
}
func (c Checksum) WritePaths(paths ...string) error {
// recursively hashes a filepath, keeping state in c.hash
}
func (c Checksum) Write(b []byte) (int, error) {
// writes b into c.hash
}
func (c Checksum) EncodeToString() string {
// returns a hex string encoding of the hash value
}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#167 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACTA3LPQ4NOYXUO5JIWULTR6O4XANCNFSM434SNUMA>
.
|
Shall I close this PR in favor of a separate one or reuse this one?
…On Wed, Jun 9, 2021 at 10:27 AM Andy Brown ***@***.***> wrote:
Sounds good. I’ll take a crack at it.
On Wed, Jun 9, 2021 at 10:18 AM Ryan Moran ***@***.***>
wrote:
> I think it could make sense to expose some of these lower-level APIs to
> the buildpack author, but I think it may make more sense as a new type that
> is distinct from the fs.ChecksumCalculator. Specifically, I think the
> proposed changes break an implicit contract which is that the
> fs.ChecksumCalculator is stateless. The new API moves state into the
> calculator and thus makes it difficult to reuse or use in cases of parallel
> operation. I'd like to propose a different API that would create a new
> stateful type that can be reused by the fs.ChecksumCalculator and
> therefore keep this implicit stateless contract in-place.
>
> type Checksum struct {
> hash hash.Hash
> }
> func (c Checksum) WritePaths(paths ...string) error {
> // recursively hashes a filepath, keeping state in c.hash
> }
> func (c Checksum) Write(b []byte) (int, error) {
> // writes b into c.hash
> }
> func (c Checksum) EncodeToString() string {
> // returns a hex string encoding of the hash value
> }
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#167 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAACTA3LPQ4NOYXUO5JIWULTR6O4XANCNFSM434SNUMA>
> .
>
|
@andymoe feels like six of one, half a dozen of the other to me. If you feel that a new PR is necessary I would not be offended. |
@andymoe bump |
Drafting for now due to inactivity |
Closing this for now since it's been inactive for a few months. Feel free to reopen if you still want to contribute this work @andymoe |
😭 I’m sorry.
…On Wed, Dec 1, 2021 at 10:39 AM Frankie G-J ***@***.***> wrote:
Closing this for now since it's been inactive for a few months. Feel free
to reopen if you still want to contribute this work @andymoe
<https://github.com/andymoe>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#167 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACTA2RTM5263U53ROTECTUOZTXDANCNFSM434SNUMA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
My goal was to review and pick this up next. I'll try and do that later this week! |
Summary
Made the following additions to the API in order to allow for adding additional data to the hash after a set of files or directories have been processes. The new API is similar to the Hash interface however other function names may be more clear.
The old API is still around for backwards compatibility:
Use Case
With no API changes (still viable option I guess)
Potential alternative method names