go - limitation on bytes.Buffer? -


i trying gzip slice of bytes using package "compress/gzip". writing bytes.buffer , writing 45976 bytes, when trying uncompress content using gzip.reader , reader function - find not of content recovered. there limitations bytes.buffer? , way pass or alter this? here code (edit):

func compress_and_uncompress() {     var buf bytes.buffer     w := gzip.newwriter(&buf)     i,err := w.write([]byte(long_string))     if(err!=nil){             log.fatal(err)     }     w.close()      b2 := make([]byte, 80000)     r, _ := gzip.newreader(&buf)     j, err := r.read(b2)     if(err!=nil){             log.fatal(err)     }     r.close()      fmt.println("wrote:", i, "read:", j) } 

output testing (with chosen string long_string) give wrote: 45976, read 32768

use ioutil.readall. contract io.reader says doesn't have return data , there reason not to sizes of internal buffers. ioutil.readall works io.reader read until eof.

eg (untested)

import "io/ioutil"  func compress_and_uncompress() {     var buf bytes.buffer     w := gzip.newwriter(&buf)     i,err := w.write([]byte(long_string))     if err!=nil {             log.fatal(err)     }     w.close()      r, _ := gzip.newreader(&buf)     b2, err := ioutil.readall(r)     if err!=nil {             log.fatal(err)     }     r.close()      fmt.println("wrote:", i, "read:", len(b2)) } 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -