func (b *AtomicFixedSizeRingBuf) WriteTo(w io.Writer) (n int64, err error) {
	b.tex.Lock()
	defer b.tex.Unlock()

	if b.readable == 0 {
		return 0, io.EOF
	}

	extent := b.Beg + b.readable
	firstWriteLen := intMin2(extent, b.N) - b.Beg
	secondWriteLen := b.readable - firstWriteLen
	if firstWriteLen > 0 {
		m, e := w.Write(b.A[b.Use][b.Beg:(b.Beg + firstWriteLen)])
		n += int64(m)
		b.unatomic_advance(m)

		if e != nil {
			return n, e
		}
		// all bytes should have been written, by definition of
		// Write method in io.Writer
		if m != firstWriteLen {
			return n, io.ErrShortWrite
		}
	}
	if secondWriteLen > 0 {
		m, e := w.Write(b.A[b.Use][0:secondWriteLen])
		n += int64(m)
		b.unatomic_advance(m)

		if e != nil {
			return n, e
		}
		// all bytes should have been written, by definition of
		// Write method in io.Writer
		if m != secondWriteLen {
			return n, io.ErrShortWrite
		}
	}

	return n, nil
}
func (b *AtomicFixedSizeRingBuf) WriteTo(w io.Writer) (n int64, err error) {
	b.tex.Lock()
	defer b.tex.Unlock()

	if b.readable == 0 {
		return 0, io.EOF
	}

	extent := b.Beg + b.readable
	firstWriteLen := intMin2(extent, b.N) - b.Beg
	secondWriteLen := b.readable - firstWriteLen
	if firstWriteLen > 0 {
		m, e := w.Write(b.A[b.Use][b.Beg:(b.Beg + firstWriteLen)])
		n += int64(m)
		b.unatomic_advance(m)

		if e != nil {
			return n, e
		}
		
		
		if m != firstWriteLen {
			return n, io.ErrShortWrite
		}
	}
	if secondWriteLen > 0 {
		m, e := w.Write(b.A[b.Use][0:secondWriteLen])
		n += int64(m)
		b.unatomic_advance(m)

		if e != nil {
			return n, e
		}
		
		
		if m != secondWriteLen {
			return n, io.ErrShortWrite
		}
	}

	return n, nil
}
func ( b * AtomicFixedSizeRingBuf ) WriteTo ( w io . Writer ) ( n int64 , err error ) { b . tex . Lock ( ) defer b . tex . Unlock ( ) if b . readable == 0 { return 0 , io . EOF } extent := b . Beg + b . readable firstWriteLen := intMin2 ( extent , b . N ) - b . Beg secondWriteLen := b . readable - firstWriteLen if firstWriteLen > 0 { m , e := w . Write ( b . A [ b . Use ] [ b . Beg : ( b . Beg + firstWriteLen ) ] ) n += int64 ( m ) b . unatomic_advance ( m ) if e != nil { return n , e } // all bytes should have been written, by definition of // Write method in io.Writer if m != firstWriteLen { return n , io . ErrShortWrite } } if secondWriteLen > 0 { m , e := w . Write ( b . A [ b . Use ] [ 0 : secondWriteLen ] ) n += int64 ( m ) b . unatomic_advance ( m ) if e != nil { return n , e } // all bytes should have been written, by definition of // Write method in io.Writer if m != secondWriteLen { return n , io . ErrShortWrite } } return n , nil }
// WriteTo and ReadFrom avoid intermediate allocation and copies.
// WriteTo avoids intermediate allocation and copies.
// WriteTo writes data to w until there's no more data to write
// or when an error occurs. The return value n is the number of
// bytes written. Any error encountered during the write is also returned.
WriteTo and ReadFrom avoid intermediate allocation and copies . WriteTo avoids intermediate allocation and copies . WriteTo writes data to w until there s no more data to write or when an error occurs . The return value n is the number of bytes written . Any error encountered during the write is also returned .