Skip to content

proposal: x/mod/sumdb/dirhash: HashZipReader to read from an io.Reader #76021

@cam72cam

Description

@cam72cam

Proposal Details

In the OpenTofu project, we maintain a registry of providers (zipped binaries) that are run through dirhash.HashZip(). In our pipeline, we would like to skip writing the file to disk, just to re-read it into memory again.

I propose that the core of the existing HashZip function is factored out into HashZipReader(*zip.Reader, Hash) (string,error) and the existing HashZip function is modified to call it.

func HashZip(zipfile string, hash Hash) (string, error) {
    z, err := zip.OpenReader(zipfile)
    if err != nil { return "", err }
    defer z.Close()
    return ZipHashReader(z)
}

It could then be consumed by end users as:

z, err := zip.NewReader(bytes.NewReader(zipdata), int64(len(zipdata)))
if err != nil { ... }
hash, err := dirhash.HashZipReader(z)
...

In practice, this is a very small addition to the API and minimal code change. It would give consumers of this package more flexible access to the existing utility function within.

I'm happy to submit this change via gerrit, but understand that this proposal needs review before I could start work on it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions