I'm new to golang, and can't figure out how to use golang's "compress/gzip" package to my advantage. Basically, I just want to write something to a file, gzip it and read it directly from the zipped format through another script. I would really appreciate if someone could give me an example on how to do this.
相关问题
- iOS (objective-c) compression_decode_buffer() retu
- Golang mongodb aggregation
- How to flatten out a nested json structure in go
- how to install private repo using glide golang
- How to convert a string to a byte array which is c
相关文章
- Can I run a single test in a suite?
- How to replace file-access references for a module
- How to check if a request was cancelled
- Is it possible to implement an interface with unex
- Why is file_get_contents faster than memcache_get?
- Transactionally writing files in Node.js
- How to access value of first index of array in Go
- Embedded Interface
I decided to combine ideas from others answers and just provide a full example program. Obviously there are many different ways to do the same thing. This is just one way:
Having a full example like this should be helpful for future reference.
For the Read part, something like the useful ioutil.ReadFile for .gz files could be :
All the compress packages implement the same interface. You would use something like this to compress:
And this to unpack:
Here the func for unpack gzip file to destination file:
Pretty much the same answer as Laurent, but with the file io: