I am new to Golang, so maybe this is something quite evident but I did not find anything that is working on Stackoverflow or on the Gzip documentation.
I download a .gz through Http and write the content of the response body in a file. However, when I try to read it from the file and uncompress it, I got the "invalid header" error.
Here is my code :
reader, err := os.Open(completeName)
if err != nil {
panic(err)
}
defer reader.Close()
archive, err := gzip.NewReader(reader)
if err != nil {
panic(err)
}
defer archive.Close()
target := destDirectory()
writer, err := os.Create(target + completeName)
if err != nil {
panic(err)
}
defer writer.Close()
_, err = io.Copy(writer, archive)
return err
I though it would be that the content I receive is invalid but I tried to uncompress it via "tar -xjf file.gz" and it worked perfecly.
Any ideas ?