cavaliergopher / rpm

A Go implementation of the RPM file format
BSD 3-Clause "New" or "Revised" License
169 stars 44 forks source link

Checksum and size for reading from stream #7

Closed bayrinat closed 7 years ago

bayrinat commented 7 years ago

I need to get package from remote repository. ReadPackageFile(r io.Reader) allows me to get all needed data instead of checksum and size. Now I fix it by using ioutil.ReadAll(). I simply calculate checksum and get size.

I think, method with reading stream should do it inside.

cavaliercoder commented 7 years ago

If you only need the checksum and size of a file, I would instead recommend using methods in the standard libraries as you would for any other file type. The file size should be available as a Content-Length HTTP header and you can use io.Copy to read a response body into a Hash.

The ReadPackageFile method deliberately does not compute any checksums for the following reasons:

bayrinat commented 7 years ago

I agree, rpm could be too large for processing in ReadPackageFile. Then separated methods for Checksum and Size from stream are expected. Now Checksum() returns error for pack from reader and this is confusing a little bit.

cavaliercoder commented 7 years ago

I'll update the documentation to make this clearer. PackageFile.Size specifies the disk space consumed by installation of the package, not the size of the package file. See PackageFile.FileSize instead.

That said, FileSize, Checksum, etc. all expect a local file and return zero-values for packages read from an io.Reader. I'll make sure the docs reflect this.

bayrinat commented 7 years ago

ok, thanks.