func (b *bufioW) CopyBulk(src io.Reader, n int64) error {
	b.mu.Lock()
	defer b.mu.Unlock()

	b.appendSize('$', n)
	if start := len(b.buf); int64(cap(b.buf)-start) >= n+2 {
		b.buf = b.buf[:start+int(n)]
		if _, err := io.ReadFull(src, b.buf[start:]); err != nil {
			return err
		}

		b.buf = append(b.buf, binCRLF...)
		return nil
	}

	if err := b.flush(); err != nil {
		return err
	}

	b.buf = b.buf[:cap(b.buf)]
	_, err := io.CopyBuffer(b, io.LimitReader(src, int64(n)), b.buf)
	b.buf = b.buf[:0]
	if err != nil {
		return err
	}

	// FIXED: Instead of append CRLF to buf, we flush it directly.
	// b.buf = append(b.buf, binCRLF...)
	_, err = b.Write(binCRLF)
	if err != nil {
		return err
	}

	return nil
}
// CopyBulk flushes the existing buffer and read n bytes from the reader directly to
// the client connection.
CopyBulk flushes the existing buffer and read n bytes from the reader directly to
the client connection.
// CopyBulk flushes the existing buffer and read n bytes from the reader directly to // the client connection .
func (b *bufioW) CopyBulk(src io.Reader, n int64) error {
	b.mu.Lock()
	defer b.mu.Unlock()
	b.appendSize('$', n)
	if start := len(b.buf); int64(cap(b.buf)-start) >= n+2 {
		b.buf = b.buf[:start+int(n)]
		if _, err := io.ReadFull(src, b.buf[start:]); err != nil {
			return err
		}
		b.buf = append(b.buf, binCRLF...)
		return nil
	}
	if err := b.flush(); err != nil {
		return err
	}
	b.buf = b.buf[:cap(b.buf)]
	_, err := io.CopyBuffer(b, io.LimitReader(src, int64(n)), b.buf)
	b.buf = b.buf[:0]
	if err != nil {
		return err
	}
	_, err = b.Write(binCRLF)
	if err != nil {
		return err
	}
	return nil
}
func ( b * bufioW ) CopyBulk ( src io . Reader , n int64 ) error { b . mu . Lock ( ) defer b . mu . Unlock ( ) b . appendSize ( '$' , n ) if start := len ( b . buf ) ; int64 ( cap ( b . buf ) - start ) >= n + 2 { b . buf = b . buf [ : start + int ( n ) ] if _ , err := io . ReadFull ( src , b . buf [ start : ] ) ; err != nil { return err } b . buf = append ( b . buf , binCRLF ... ) return nil } if err := b . flush ( ) ; err != nil { return err } b . buf = b . buf [ : cap ( b . buf ) ] _ , err := io . CopyBuffer ( b , io . LimitReader ( src , int64 ( n ) ) , b . buf ) b . buf = b . buf [ : 0 ] if err != nil { return err } _ , err = b . Write ( binCRLF ) if err != nil { return err } return nil }
CopyBulk flushes the existing buffer and read n bytes from the reader directly to
the client connection.
CopyBulk flushes the existing buffer and read n bytes from the reader directly to the client connection .
// FIXED: Instead of append CRLF to buf, we flush it directly. // b.buf = append(b.buf, binCRLF...)