我正在嘗試,只是為了好玩,將 gzip Writer 直接連接到 gzip Reader,這樣我就可以寫入 Writer 并從 Reader 動態讀取。我希望能準確地閱讀我寫的內容。我正在使用 gzip,但我也想將這種方法與加密/aes 一起使用,我想它的工作方式應該非常相似,并且可以與其他讀取器/寫入器一起使用,例如 jpeg、png ......這是我最好的選擇,這是行不通的,但我希望你能明白我的意思:http : //play.golang.org/p/7qdUi9wwG7package mainimport ( "bytes" "compress/gzip" "fmt")func main() { s := []byte("Hello world!") fmt.Printf("%s\n", s) var b bytes.Buffer gz := gzip.NewWriter(&b) ungz, err := gzip.NewReader(&b) fmt.Println("err: ", err) gz.Write(s) gz.Flush() uncomp := make([]byte, 100) n, err2 := ungz.Read(uncomp) fmt.Println("err2: ", err2) fmt.Println("n: ", n) uncomp = uncomp[:n] fmt.Printf("%s\n", uncomp)}似乎gzip.NewReader(&b)正在嘗試立即讀取并返回 EOF。
- 2 回答
- 0 關注
- 237 瀏覽
添加回答
舉報
0/150
提交
取消