Hi I would like to append a downloaded file raw response to a file. Supposed that I'm trying to download a 1GB file and download process will be done in multiple request. Let say 100mb per request. Now this all the 10 parts should be put into one single file to be read. I don't know how to achieve this. I'm using GOREQ to request this resource and the raw data is in Goreq.body format. Below is my sample code
newFile := "./newfile.gz"
out, err := os.Create(newFile)
defer out.close()
if err != nil {
fmt.Println("Failed to download file")
return
}
for i := 0; i < 10; i++ {
// This will return the items in part of 100mb/part.
// GetRawDataFromEbay returns a goreq.body(raw) as its response
response, _ = GetRawDataFromEbay(10485760)
out.Write(response) // This does not work
}
I know Write accept []byte as parameter. But how can I append the retrieve goreq.body raw data to a file?
Ok found the answer it seems that I don't need to do anything fancy. I just have to use io.copy and that's it. Just for reference for others having the same issue below is my code
So basically if the Goreq.body response is in by part when you copy the different response (in part) in the same file it will append it automatically