func (bp *BytesPipe) Read(p []byte) (n int, err error) {
	for {
		read := copy(p, bp.buf[0][bp.lastRead:])
		n += read
		bp.lastRead += read
		if bp.len() == 0 {
			bp.lastRead = 0
			bp.bufLen -= len(bp.buf[0])
			bp.buf[0] = bp.buf[0][:0]
			break
		}
		if len(p) == read {
			break
		}
		p = p[read:]
		bp.lastRead = 0
		bp.bufLen -= len(bp.buf[0])
		bp.buf[0] = nil      
		bp.buf = bp.buf[1:]  
	}
	return
}
Read reads bytes from BytesPipe.
Data could be read only once.
package ioutils
const maxCap = 1e6
type BytesPipe struct {
	buf      [][]byte  
	lastRead int       
	bufLen   int       
}
func NewBytesPipe(buf []byte) *BytesPipe {
	if cap(buf) == 0 {
		buf = make([]byte, 0, 64)
	}
	return &BytesPipe{
		buf: [][]byte{buf[:0]},
	}
}
func (bp *BytesPipe) Write(p []byte) (n int, err error) {
	for {
		b := bp.buf[len(bp.buf)-1]
		n := copy(b[len(b):cap(b)], p)
		bp.bufLen += n
		bp.buf[len(bp.buf)-1] = b[:len(b)+n]
		if len(p) == n {
			break
		}
		p = p[n:]
		nextCap := 2 * cap(bp.buf[len(bp.buf)-1])
		if maxCap < nextCap {
			nextCap = maxCap
		}
		bp.buf = append(bp.buf, make([]byte, 0, nextCap))
	}
	return
}
func (bp *BytesPipe) len() int {
	return bp.bufLen - bp.lastRead
}