バッファリングされたリーダーからファイルを圧縮し、圧縮されたバイトをバイトチャネルを介して渡そうとしていますが、結果は良くありません:)、これが私が今まで思いついたことです。明らかにこれは機能しません...
func Compress(r io.Reader) (<-chan byte) {
c := make(chan byte)
go func(){
var wBuff bytes.Buffer
rBuff := make([]byte, 1024)
writer := zlib.NewWriter(*wBuff)
for {
n, err := r.Read(rBuff)
if err != nil && err != io.EOF { panic(err) }
if n == 0 { break }
writer.Write(rBuff) // Compress and write compressed data
// How to send written compressed bytes through channel?
// as fas as I understand wBuff will eventually contain
// whole compressed data?
}
writer.Close()
close(c) // Indicate that no more data follows
}()
return c
}
私はGoに非常に慣れていないので、ご容赦ください