Or use https://godoc.org/io/ioutil#ReadFile

By really you don't need to buffer all the data in memory, io.Copy will do 
that for you

in, err := os.Open(input)
check(err)
defer in.Close()
out, err := os.Create(output)
gz := gzip.New.Writer(out)
_, err = io.Copy(gz, in)
check(err)
err = gz.Close()
check(err)
err = out.Close()
check(err)

On Thursday, 16 February 2017 06:05:51 UTC+11, howar...@gmail.com wrote:
>
> While it is not clear from the Buffer documentation, the Reader 
> *interface* documentation (which Buffer.Read implements implicitly) does 
> state "up to len(p) bytes." You are ignoring how many bytes it read and 
> assuming that the one read is reading the whole file. I am not sure that 
> this is guaranteed with Buffer.Read. 
>
> I would suggest you try to adhere to the Reader interface's documented 
> behavior, and continue to call Read until you get EOF, and process the n 
> returned bytes each time. Doing this would also make it easier to then move 
> a step further and drop your buffer size to something sensible, instead of 
> attempting to read the entire 2.5G file into memory before compressing.
>
> Howard
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to