Archive (ZIP) files

The following example demonstrates how to create an archive with multiple files inside. The files in the example are hard-coded with only a few bytes, but should be easily adapted to suit other needs:

// This example uses zip but standard library // also supports tar archives package main import ( "archive/zip" "log" "os" ) func main() { // Create a file to write the archive buffer to // Could also use an in memory buffer. outFile, err := os.Create("test.zip") if err != nil { log.Fatal(err) } defer outFile.Close() // Create a zip writer on top of the file writer zipWriter := zip.NewWriter(outFile) // Add files to archive // We use some hard coded data to demonstrate, // but you could iterate through all the files // in ...

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.