Last active
May 1, 2019 21:04
-
-
Save pgaskin/3915cae00c889a07ac3f8a3f1d5ef386 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"archive/zip" | |
"crypto/sha1" | |
"fmt" | |
"os" | |
) | |
func main() { | |
for _, fn := range os.Args[1:] { | |
zh, err := ziphash(fn) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(zh, fn) | |
} | |
} | |
// ziphash is a fast hashing function for zip files based on the stored CRC32s. | |
func ziphash(filename string) (string, error) { | |
z, err := zip.OpenReader(filename) | |
if err != nil { | |
return "", err | |
} | |
defer z.Close() | |
sh := sha1.New() | |
for _, zf := range z.File { | |
sh.Write([]byte(fmt.Sprint(zf.CRC32, zf.UncompressedSize64))) | |
} | |
return fmt.Sprintf("%x", sh.Sum(nil)), nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"archive/zip" | |
"fmt" | |
"os" | |
) | |
func main() { | |
zr, err := zip.OpenReader(os.Args[1]) | |
if err != nil { | |
panic(err) | |
} | |
defer zr.Close() | |
for _, zf := range zr.File { | |
fmt.Printf("%+v\n", zf) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment