O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The built-in package zip contains the NewWriter and NewReader functions to create the zip.Writer to compress, and the zip.Reader to decompress the zipped content.

Each record of the ZIP file is created with the Create method of the created zip.Writer . The returned Writer is then used to write the content body.

To decompress the files, the OpenReader function is used to create the ReadCloser of the records in the zipped file. The File field of the created ReaderCloser is the slice of zip.File pointers. The content of the file is obtained by calling the Open method and by reading the returned ReadCloser.

The folders could be created by only adding slashes to the name of the file in the Create method. An example could be  

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required