// CanWrite returns true if segment has space to write entry data.
422341
func (s *SeriesSegment) CanWrite(data []byte) bool {
	return s.w != nil && s.size+uint32(len(data)) <= SeriesSegmentSize(s.id)
}
792838
func (c *Splitter) Write(p []byte) (n int, err error) {
	if c.done {
		return 0, ErrClosedWriter
	}

	c.lock.Lock()
	defer c.lock.Unlock()

	c.buffer = append(c.buffer, p...)
	return len(p), nil
}
1332037
func (w *LimitWriter) Write(p []byte) (n int, err error) {
	n = len(p)
	var n1 int
	if w.skipBytes > 0 {
		if w.skipBytes >= int64(len(p)) {
			w.skipBytes = w.skipBytes - int64(len(p))
			return n, nil
		}
		p = p[w.skipBytes:]
		w.skipBytes = 0
	}
	if w.wLimit == 0 {
		return n, nil
	}
	if w.wLimit < int64(len(p)) {
		n1, err = w.Writer.Write(p[:w.wLimit])
		w.wLimit = w.wLimit - int64(n1)
		return n, err
	}
	n1, err = w.Writer.Write(p)
	w.wLimit = w.wLimit - int64(n1)
	return n, err
}
196051
func (c *chunkedContentCoder) Write() (int, error) {
	var tw int

	if c.final != nil {
		// write out the data section first
		nw, err := c.w.Write(c.final)
		tw += nw
		if err != nil {
			return tw, err
		}
	}

	chunkOffsetsStart := uint64(tw)

	if cap(c.final) < binary.MaxVarintLen64 {
		c.final = make([]byte, binary.MaxVarintLen64)
	} else {
		c.final = c.final[0:binary.MaxVarintLen64]
	}
	chunkOffsets := modifyLengthsToEndOffsets(c.chunkLens)
	// write out the chunk offsets
	for _, chunkOffset := range chunkOffsets {
		n := binary.PutUvarint(c.final, chunkOffset)
		nw, err := c.w.Write(c.final[:n])
		tw += nw
		if err != nil {
			return tw, err
		}
	}

	chunkOffsetsLen := uint64(tw) - chunkOffsetsStart

	c.final = c.final[0:8]
	// write out the length of chunk offsets
	binary.BigEndian.PutUint64(c.final, chunkOffsetsLen)
	nw, err := c.w.Write(c.final)
	tw += nw
	if err != nil {
		return tw, err
	}

	// write out the number of chunks
	binary.BigEndian.PutUint64(c.final, uint64(len(c.chunkLens)))
	nw, err = c.w.Write(c.final)
	tw += nw
	if err != nil {
		return tw, err
	}

	c.final = c.final[:0]

	return tw, nil
}
909751
func (w *WrapWriter) Write(p []byte) (n int, err error) {
	n, err = Wrap(w, p, w.off, w.wrapAt)
	w.off = (w.off + int64(n)) % w.wrapAt
	return n, err
}
276279
func (w *syncFileWriter) Write(buf []byte) (n int, err error) {
	written := 0

	// If buf > 64k we'll have to send multiple chunks.
	// TODO Refactor this into something that can coalesce smaller writes into a single chukn.
	for len(buf) > 0 {
		// Writes < 64k have a one-to-one mapping to chunks.
		// If buffer is larger than the max, we'll return the max size and leave it up to the
		// caller to handle correctly.
		partialBuf := buf
		if len(partialBuf) > wire.SyncMaxChunkSize {
			partialBuf = partialBuf[:wire.SyncMaxChunkSize]
		}

		if err := w.sender.SendOctetString(wire.StatusSyncData); err != nil {
			return written, err
		}
		if err := w.sender.SendBytes(partialBuf); err != nil {
			return written, err
		}

		written += len(partialBuf)
		buf = buf[len(partialBuf):]
	}

	return written, 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
}
389481
func (c *C2) Write(b []byte) {
	c.a.Write(b)
	c.b.Write(b)
	c.lastWritten = len(b)
	c.totalWritten += c.lastWritten
}
1363015
func LimitedWriter(w io.Writer, skipBytes int64, limit int64) *LimitWriter {
	return &LimitWriter{w, skipBytes, limit}
}
996444
func (w *Writer) Write(p []byte) (n int, err error) {
	var linelen int
	var lastWasColon bool
	for i, c := range p {
		w.buf = append(w.buf, c)
		linelen++
		if c == '\t' {
			w.buf[len(w.buf)-1] = ' '
			for linelen%tab != 0 {
				w.buf = append(w.buf, ' ')
				linelen++
			}
		}
		if w.flag&BreakOnColon != 0 && c == ':' {
			lastWasColon = true
		} else if lastWasColon {
			if c == '\n' {
				pos := bytes.LastIndex(w.buf[:len(w.buf)-1], []byte{'\n'})
				if pos < 0 {
					pos = 0
				}
				line := w.buf[pos:]
				w.buf = w.buf[:pos]
				if err = w.columnate(); err != nil {
					if len(line) < i {
						return i - len(line), err
					}
					return 0, err
				}
				if n, err := w.w.Write(line); err != nil {
					if r := len(line) - n; r < i {
						return i - r, err
					}
					return 0, err
				}
			}
			lastWasColon = false
		}
		if c == '\n' {
			linelen = 0
		}
	}
	return len(p), nil
}
1122751
func (d *RabinKarp64) Write(data []byte) (int, error) {
	l := len(data)
	if l == 0 {
		return 0, nil
	}
	// Re-arrange the window so that the leftmost element is at index 0
	n := len(d.window)
	if d.oldest != 0 {
		tmp := make([]byte, d.oldest)
		copy(tmp, d.window[:d.oldest])
		copy(d.window, d.window[d.oldest:])
		copy(d.window[n-d.oldest:], tmp)
		d.oldest = 0
	}
	d.window = append(d.window, data...)

	d.value = 0
	for _, b := range d.window {
		d.value <<= 8
		d.value |= Pol(b)
		d.value = d.value.Mod(d.pol)
	}

	d.updateTables()

	return len(data), nil
}
624109
func (w *Writer) Write(b []byte) (int, error) {
	n := len(b)
	end := len(w.buf)
	if end+n > cap(w.buf) {
		buf := make([]byte, end, 2*cap(w.buf)+n)
		copy(buf, w.buf)
		w.buf = buf
	}
	w.buf = w.buf[:end+n]
	return copy(w.buf[end:], b), nil
}
1303079
func (w *Writer) Write(p []byte) (int, error) {
	w.Lock()
	defer w.Unlock()
	return w.w.Write(p)
}
496352
func (w *writeCloseInformer) Write(p []byte) (int, error) {
	return w.wc.Write(p)
}
854668
func (w *CountWriter) Write(b []byte) (n int, err error) {
	if n, err = w.W.Write(b); n > 0 {
		w.N += n
	}
	return
}
1311191
func (tw *Writer) Write(b []byte) (n int, err error) {
	if tw.closed {
		err = ErrWriteAfterClose
		return
	}
	overwrite := false
	if int64(len(b)) > tw.nb {
		b = b[0:tw.nb]
		overwrite = true
	}
	n, err = tw.w.Write(b)
	tw.nb -= int64(n)
	if err == nil && overwrite {
		err = ErrWriteTooLong
		return
	}
	tw.err = err
	return
}
792454
func (lw *LeveledWriter) Write(p []byte) (int, error) {
	return lw.standard.Write(p)
}