Golang archive/zip.CreateHeader() function usage example
package archive/zip
CreateHeader adds a file to the zip file using the provided FileHeader for the file metadata. It returns a Writer to which the file contents should be written. The file's contents must be written to the io.Writer before the next call to Create, CreateHeader, or Close.
zip.CreateHeader() function usage example
zipWriter := zip.NewWriter(buffer)
fileInfo := file.Stat()
header := zip.FileInfoHeader(fileInfo)
writer : = zipWriter.CreateHeader(header)
NOTE : By the default the zip package will use algorithm 0 - which is Store, without any compression. Remember to add :
header.Method = zip.Deflate
if you want to create smaller size zip files
Advertisement
Something interesting
Tutorials
+13.6k Golang : Query string with space symbol %20 in between
+6.6k Golang : How to determine if request or crawl is from Google robots
+18.7k Golang : Implement getters and setters
+31.9k Golang : Convert an image file to []byte
+10.2k Golang : Text file editor (accept input from screen and save to file)
+7.7k Gogland : Where to put source code files in package directory for rookie
+7.5k Golang : Rename part of filename
+9.1k Golang : Serving HTTP and Websocket from different ports in a program example
+32.1k Golang : Validate email address with regular expression
+7.5k Golang : Create zip/ePub file without compression(use Store algorithm)
+32.2k Golang : Convert []string to []byte examples
+19.3k Golang : Get host name or domain name from IP address