Esempio n. 1
0
func (this *ServiceContext) SendReadWriter(w io.ReadWriter) (n int, err os.Error) {
	if this.Compressed {
		var cmp *gzip.Compressor
		if cmp, err = gzip.NewWriterLevel(this.Conn, gzip.DefaultCompression); err != nil {
			return
		}

		io.Copy(cmp, w)
		cmp.Close()
	} else {
		io.Copy(this.Conn, w)
	}

	return
}
Esempio n. 2
0
// Signature satisfies io.Writer
func (this *ServiceContext) Write(data []byte) (n int, err os.Error) {
	if this.Compressed {
		var cmp *gzip.Compressor
		if cmp, err = gzip.NewWriterLevel(this.Conn, gzip.DefaultCompression); err != nil {
			return
		}

		n, err = cmp.Write(data)
		cmp.Close()
	} else {
		n, err = this.Conn.Write(data)
	}

	return
}