// Write writes len(p) byte to the Buffer.
// It returns the number of bytes written and an error if any.
// Write returns non-nil error when n!=len(p).
160017
func (b *MemFile) Write(p []byte) (n int, err error) {
	b.mutex.Lock()
	n, err = b.Buffer.Write(p)
	b.mutex.Unlock()
	return
}
650492
func (w *BroadcastWriter) Write(p []byte) (n int, err error) {
	for _, writer := range w.writers {
		n, err = writer.Write(p)
		if err != nil {
			return
		}
		if n != len(p) {
			err = io.ErrShortWrite
			return
		}
	}
	return len(p), nil
}
720555
func (f *Buffer) Write(p []byte) (n int, err error) {
	if f.isClosed {
		return 0, io.EOF
	}
	if f.Index < 0 {
		return 0, io.EOF
	}
	// we might have rewinded, let's reset the buffer before appending to it
	idx := int(f.Index)
	buffLen := f.Buff.Len()
	if idx != buffLen && idx <= buffLen {
		f.Buff = bytes.NewBuffer(f.Bytes()[:f.Index])
	}
	n, err = f.Buff.Write(p)

	f.Index += int64(n)
	return n, err
}
48626
func (f *FileWriter) Write(p []byte) (int, error) {
	f.mu.Lock()
	n, err := f.f.Write(p)
	f.mu.Unlock()
	return n, err
}
250914
func (b *PackBuffer) Write(p []byte) (n int, err error) {

	space := b.WriteLen()
	if space < len(p) {
		n = copy(b.s[b.w:], p)
		b.w = b.w + n
	} else {
		b.Compact(false)
		space = b.WriteLen()
		if space > len(p) {
			n = copy(b.s[b.w:], p[:])
		} else {
			n = copy(b.s[b.w:], p[:space])
		}
	}
	if n == 0 {
		return 0, errors.New("No room left in buffer")
	}
	return n, nil
}
301493
func (pw *Writer) Write(buf []byte) (cnt int, err error) {
	if pw.numBits > 0 || pw.cntBuf > 0 {
		if pw.numBits%8 != 0 {
			return 0, errorf(errors.Invalid, "non-aligned bit buffer")
		}
		if _, err := pw.Flush(); err != nil {
			return 0, err
		}
	}
	cnt, err = pw.wr.Write(buf)
	pw.Offset += int64(cnt)
	return cnt, err
}
1159217
func (mw multiWriter) Write(p []byte) (int, error) {
	done := make(chan result, len(mw))
	for _, w := range mw {
		go send(w, p, done)
	}
	endResult := result{n: len(p)}
	for _ = range mw {
		res := <-done
		if res.err != nil && (endResult.err == nil || res.n < endResult.n) {
			endResult = res
		}
	}
	return endResult.n, endResult.err
}
745868
func (d *State364) Write(p []byte) (nn int, err error) {
	l := len(p)
	d.clen += l
	d.tail = append(d.tail, p...)
	return l, nil
}
622272
func (v *Buf) Write(p []byte) (int, error) {
	l := len(p)
	writeEnd := int(v.ptr) + l - len(*v.buf)
	if writeEnd > 0 {
		err := v.grow(writeEnd)
		if err != nil {
			return 0, err
		}
	}
	copy((*v.buf)[v.ptr:], p)
	v.ptr += int64(l)
	return l, nil
}
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
}
195061
func (et *ErrorTracker) Write(p []byte) (n int, err error) {
	if et.err != nil {
		return 0, et.err
	}
	n, err = et.Writer.Write(p)
	if err != nil {
		et.err = err
	}
	return n, err
}
105576
func (w *countingWriter) Write(p []byte) (n int, err error) {
	n, err = w.w.Write(p)
	w.count += uint(n)
	return n, err
}
25609
func (fw *flushWriter) Write(p []byte) (n int, err error) {
	n, err = fw.writer.Write(p)
	if err != nil {
		return
	}
	if fw.flusher != nil {
		fw.flusher.Flush()
	}
	return
}
223644
func (s *WriterSender) Write(p []byte) (int, error) {
	s.mu.Lock()
	defer s.mu.Unlock()
	n, err := s.writer.Write(p)
	if err != nil {
		return n, err
	}
	_ = s.writer.Flush()

	if s.buffer.Len() > 80 {
		err = s.doSend()
	}

	return n, err
}
965662
func (w *BufferedWriter) Write(p []byte) (int, error) {
	if w.err != nil {
		return 0, w.err
	}

	_, w.err = w.bw.Write(p)
	if w.err != nil {
		return 0, w.err
	}

	return len(p), nil
}
793266
func (c *dlchunk) Write(p []byte) (n int, err error) {
	if c.cur >= c.size && len(c.withRange) == 0 {
		return 0, io.EOF
	}

	n, err = c.w.WriteAt(p, c.start+c.cur)
	c.cur += int64(n)

	return
}
722840
func (s *Slice) Write(p []byte) (n int, err error) {
	*s = append(*s, p...)
	return len(p), nil
}