// WriteToBuffer provides a function to get bytes.Buffer from the saved file.
180088
func (f *File) WriteToBuffer() (*bytes.Buffer, error) {
	buf := new(bytes.Buffer)
	zw := zip.NewWriter(buf)
	f.calcChainWriter()
	f.commentsWriter()
	f.contentTypesWriter()
	f.drawingRelsWriter()
	f.drawingsWriter()
	f.vmlDrawingWriter()
	f.workBookWriter()
	f.workBookRelsWriter()
	f.workSheetWriter()
	f.workSheetRelsWriter()
	f.styleSheetWriter()

	for path, content := range f.XLSX {
		fi, err := zw.Create(path)
		if err != nil {
			return buf, err
		}
		_, err = fi.Write(content)
		if err != nil {
			return buf, err
		}
	}
	return buf, zw.Close()
}
285699
func (w *indentWriter) Write(b []byte) (int, error) {
	w.indent()
	return w.Buffer.Write(b)
}
324226
func (file *File) Write(buf []byte) (int, error) {
	n, err := file.WriteAt(buf, int64(file.offset))
	if err == nil {
		file.offset += uint64(n)
	}

	return n, err
}
831337
func (r *Reader) WriteTo(w io.Writer) (int64, error) {
	var (
		i   int64
		ii  int
		err error
	)
	// first, clear buffer
	if r.buffered() > 0 {
		ii, err = w.Write(r.data[r.n:])
		i += int64(ii)
		if err != nil {
			return i, err
		}
		r.data = r.data[0:0]
		r.n = 0
	}
	for r.state == nil {
		// here we just do
		// 1:1 reads and writes
		r.more()
		if r.buffered() > 0 {
			ii, err = w.Write(r.data)
			i += int64(ii)
			if err != nil {
				return i, err
			}
			r.data = r.data[0:0]
			r.n = 0
		}
	}
	if r.state != io.EOF {
		return i, r.err()
	}
	return i, nil
}
1305082
func (out *RAMOutputStream) WriteToBytes(bytes []byte) error {
	err := out.Flush()
	if err != nil {
		return err
	}
	end := out.file.length
	pos := int64(0)
	buffer := 0
	bytesUpto := 0
	for pos < end {
		length := BUFFER_SIZE
		nextPos := pos + int64(length)
		if nextPos > end {
			length = int(end - pos)
		}
		copy(bytes[bytesUpto:], out.file.Buffer(buffer)[:length])
		buffer++
		bytesUpto += length
		pos = nextPos
	}
	return nil
}
81736
func (r *reader) WriteTo(w io.Writer) (int64, error) {
	if r.err != nil {
		return 0, r.err
	}

	n, err := r.buf.WriteTo(w)
	if err != nil {
		// r.err doesn't need to be set because a write error occurred and the
		// stream hasn't been corrupted.
		return n, err
	}

	// pass a bufferFallbackWriter to nextFrame so that write errors may be
	// recovered from, allowing the unwritten stream to be read successfully.
	wfallback := &bufferFallbackWriter{
		w:   w,
		buf: &r.buf,
	}
	for {
		var m int
		m, err = r.nextFrame(wfallback)
		if wfallback.writerErr != nil && err == nil {
			// a partial write was made before an error occurred and not all m
			// bytes were writen to w.  but decoded bytes were successfully
			// buffered and reading can resume later.
			n += wfallback.n
			return n, wfallback.writerErr
		}
		n += int64(m)
		if err == io.EOF {
			return n, nil
		}
		if err != nil {
			r.err = err
			return n, err
		}
	}
	panic("unreachable")
}
655691
func writeLPBytes(buf []byte, b []byte, t Type) (int, error) {
	total, n := 0, len(b)

	if n > int(maxLPLength) {
		return 0, makeError(t, "length (%d) greater than %d bytes", n, maxLPLength)
	}

	if len(buf) < 2+n {
		return 0, makeError(t, "insufficient buffer size, expected %d, got %d", 2+n, len(buf))
	}

	binary.BigEndian.PutUint16(buf, uint16(n))
	total += 2

	copy(buf[total:], b)
	total += n

	return total, nil
}
886110
func (rb *ResponseBuffer) WriteTo(w http.ResponseWriter) error {
	for k, v := range rb.header {
		w.Header()[k] = v
	}
	if rb.buf.Len() > 0 {
		w.Header().Set("Content-Length", strconv.Itoa(rb.buf.Len()))
	}
	if rb.status != 0 {
		w.WriteHeader(rb.status)
	}
	if rb.buf.Len() > 0 {
		if _, err := w.Write(rb.buf.Bytes()); err != nil {
			return err
		}
	}
	return nil
}
957678
func (adp *BufferAdapter) Write(loc *Location, data []byte) {
	adp.bufs = append(adp.bufs, bytes.NewBuffer(data))
}
863051
func (w *Writer) buffer(b []byte) (int, error) {
	r := bufio.NewReader(bytes.NewReader(b))

	var (
		n   int
		eof bool
	)

	for !eof {
		b, err := r.ReadBytes('\n')
		if err != nil {
			if err == io.EOF {
				eof = true
			} else {
				break
			}
		}

		if len(b) == 0 {
			continue
		}

		w.events.add(&cloudwatchlogs.InputLogEvent{
			Message:   aws.String(string(b)),
			Timestamp: aws.Int64(now().UnixNano() / 1000000),
		})

		n += len(b)
	}

	return n, nil
}
856855
func (f *File) WriteTo(w io.Writer) (int64, error) {
	buf, err := f.WriteToBuffer()
	if err != nil {
		return 0, err
	}
	return buf.WriteTo(w)
}
687186
func (b *builderBuffer) WriteBytes(v byte, count uint) {
	if count == 0 {
		return
	}
	off := uint(len(*b))
	b.growCapacity(count)
	*b = (*b)[:off+count]
	for i := uint(0); i < count; i++ {
		(*b)[off+i] = v
	}
}
286203
func (b *ByteBuffer) WriteByte(c byte) error {
	b.Lock()
	defer b.Unlock()
	return b.b.WriteByte(c)
}
157084
func (i *Instructions) WriteTo(w io.Writer) (n int64, err error) {
	var buf bytes.Buffer

	for _, inst := range *i {
		_, err = inst.WriteTo(&buf)
		if err != nil {
			return
		}
	}

	return encoding.WriteTo(w, buf.Bytes())
}
679755
func (b *Buffer) Write(bs []byte) (int, error) {
	if b.size < 2 {
		return b.write(bs)
	}

	// 参数 bs 来源于 log.Logger.buf，该变量会被 log.Logger 不断
	// 重复使用，所以此处应该复制一份 bs 的内容再保存。
	cp := make([]byte, 0, len(bs))
	b.buffer = append(b.buffer, append(cp, bs...))

	if len(b.buffer) < b.size {
		return len(bs), nil
	}

	return b.Flush()
}
1304379
func NewWriteBuffer(gcInterval, expiryInterval time.Duration) *WriteBuffer {
	return &WriteBuffer{
		pool: NewRecycle(
			func() interface{} { return new(buffer.Write) },
			100, gcInterval, expiryInterval,
		),
	}
}
842770
func (l *Listener) SetWriteBuffer(bytes int) error {
	if nc, ok := l.conn.(setWriteBuffer); ok {
		return nc.SetWriteBuffer(bytes)
	}
	return errors.New(errInvalidOperation)
}