Creating a ZIP archive

This program will create a ZIP archive, so we have an archive to use with our steganography experiments. The Go standard library has a zip package, but it also supports TAR archives with the tar package. This example generates a ZIP file with two files: test.txt and test2.txt. To keep it simple, the contents of each file is hard-coded as a string in this source code:

package mainimport (   "crypto/md5"   "crypto/sha1"   "crypto/sha256"   "crypto/sha512"   "fmt"   "io/ioutil"   "log"   "os")func printUsage() {   fmt.Println("Usage: " + os.Args[0] + " <filepath>")   fmt.Println("Example: " + os.Args[0] + " document.txt")}func checkArgs() string {   if len(os.Args) < 2 {      printUsage()      os.Exit(1)   }   return os.Args[1]}func main() { filename := ...

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.