// Write writes the buffer filtering out ANSI escape codes and converting to
// the Windows functionality needed. ANSI escape codes may be found over multiple
// Writes.
771627
func (aw *AnsiWriter) Write(b []byte) (int, error) {
	needsProcessing := bytes.Contains(b, []byte(string(escKey)))
	if len(aw.buf) > 0 {
		needsProcessing = true
	}

	if !needsProcessing {
		return aw.file.Write(b)
	}
	var p []byte

	for _, char := range b {
		// Found the beginning of an escape.
		if char == escKey {
			aw.buf = append(aw.buf, char)
			continue
		}

		// Function identifiers.
		if len(aw.buf) == 1 && (char == '_' || char == 'P' || char == '[' ||
			char == ']' || char == '^' || char == ' ' || char == '#' ||
			char == '%' || char == '(' || char == ')' || char == '*' ||
			char == '+') {
			aw.buf = append(aw.buf, char)
			continue
		}

		// Cursor functions.
		if len(aw.buf) == 1 && (char == '7' || char == '8') {
			// Add another char before because finish skips 2 items.
			aw.buf = append(aw.buf, '_', char)

			err := aw.finish(nil)
			if err != nil {
				return 0, err
			}

			continue
		}

		// Keyboard functions.
		if len(aw.buf) == 1 && (char == '=' || char == '>') {
			aw.buf = append(aw.buf, char)

			err := aw.finish(nil)
			if err != nil {
				return 0, err
			}

			continue
		}

		// Bottom left function.
		if len(aw.buf) == 1 && char == 'F' {
			// Add extra char for finish.
			aw.buf = append(aw.buf, '_', char)

			err := aw.finish(nil)
			if err != nil {
				return 0, err
			}

			continue
		}

		// Reset function.
		if len(aw.buf) == 1 && char == 'c' {
			// Add extra char for finish.
			aw.buf = append(aw.buf, '_', char)

			err := aw.finish(nil)
			if err != nil {
				return 0, err
			}

			continue
		}

		// Space functions.
		if len(aw.buf) >= 2 && aw.buf[1] == ' ' && (char == 'F' || char == 'G' ||
			char == 'L' || char == 'M' || char == 'N') {
			aw.buf = append(aw.buf, char)

			err := aw.finish(nil)
			if err != nil {
				return 0, err
			}

			continue
		}

		// Number functions.
		if len(aw.buf) >= 2 && aw.buf[1] == '#' && (char >= '3' && char <= '6') ||
			char == '8' {
			aw.buf = append(aw.buf, char)

			err := aw.finish(nil)
			if err != nil {
				return 0, err
			}

			continue
		}

		// Percentage functions.
		if len(aw.buf) >= 2 && aw.buf[1] == '%' && (char == '@' || char == 'G') {
			aw.buf = append(aw.buf, char)

			err := aw.finish(nil)
			if err != nil {
				return 0, err
			}

			continue
		}

		// Character set functions.
		if len(aw.buf) >= 2 && (aw.buf[1] == '(' || aw.buf[1] == ')' ||
			aw.buf[1] == '*' || aw.buf[1] == '+') && (char == '0' ||
			(char >= '4' && char <= '7') || char == '=' || (char >= 'A' &&
			char <= 'C') || char == 'E' || char == 'H' || char == 'K' ||
			char == 'Q' || char == 'R' || char == 'Y') {
			aw.buf = append(aw.buf, char)

			err := aw.finish(nil)
			if err != nil {
				return 0, err
			}

			continue
		}

		// APC functions.
		if len(aw.buf) >= 2 && aw.buf[1] == '_' {
			aw.buf = append(aw.buf, char)

			// End of APC.
			if char == '\\' && aw.buf[len(aw.buf)-1] == escKey {
				err := aw.finish(nil)
				if err != nil {
					return 0, err
				}
			}

			continue
		}

		// DC functions.
		if len(aw.buf) >= 2 && aw.buf[1] == 'P' {
			aw.buf = append(aw.buf, char)

			// End of DC.
			if char == '\\' && aw.buf[len(aw.buf)-1] == escKey {
				err := aw.finish(nil)
				if err != nil {
					return 0, err
				}
			}

			continue
		}

		// CSI functions.
		if len(aw.buf) >= 2 && aw.buf[1] == '[' {
			aw.buf = append(aw.buf, char)

			// End of CSI.
			if char == '@' || (char >= 'A' && char <= 'M') || char == 'P' ||
				char == 'S' || char == 'T' || char == 'X' || char == 'Z' ||
				char == '`' || (char >= 'b' && char <= 'd') || (char >= 'f' &&
				char <= 'i') || (char >= 'l' && char <= 'n') || (char >= 'p' &&
				char <= 't') || char == 'w' || char == 'x' || char == 'z' ||
				char == '{' || char == '|' {
				err := aw.finish(nil)
				if err != nil {
					return 0, err
				}
			}

			continue
		}

		// OSC functions.
		if len(aw.buf) >= 2 && aw.buf[1] == ']' {
			aw.buf = append(aw.buf, char)

			// Capture incomplete code.
			if len(aw.buf) == 4 && aw.buf[2] == '0' && char == ';' {
				err := aw.finish(nil)
				if err != nil {
					return 0, err
				}

				continue
			}

			// End of OSC.
			if (char == '\\' && aw.buf[len(aw.buf)-1] == escKey) || char == ctrlG {
				err := aw.finish(nil)
				if err != nil {
					return 0, err
				}
			}

			continue
		}

		// PM functions.
		if len(aw.buf) >= 2 && aw.buf[1] == '^' {
			aw.buf = append(aw.buf, char)

			// End of PM.
			if char == '\\' && aw.buf[len(aw.buf)-1] == escKey {
				err := aw.finish(nil)
				if err != nil {
					return 0, err
				}
			}

			continue
		}

		// Normal character, resets escape buffer.
		if len(aw.buf) > 0 {
			aw.buf = nil
		}
		p = append(p, char)
	}

	_, err := aw.file.Write(p)
	return len(b), err
}
585771
func (s *serialWriteCloser) Write(data []byte) (int, error) {
	s.mu.Lock()
	defer s.mu.Unlock()
	return s.wc.Write(data)
}
350746
func (w *Writer) Write(i interface{}) {
	var s string
	switch i.(type) {
	case string:
		s = i.(string)
	case []byte:
		for _, b := range i.([]byte) {
			s += fmt.Sprintf("%.8b", b)
		}
	case bool:
		if i.(bool) {
			s = "1"
		} else {
			s = "0"
		}
	case uint8:
		s = fmt.Sprintf("%.8b", i)
	case uint16:
		s = fmt.Sprintf("%.16b", i)
	case uint32:
		s = fmt.Sprintf("%.32b", i)
	case uint64:
		s = fmt.Sprintf("%.64b", i)
	default:
		return
	}

	for _, c := range s {
		w.remainingBits = w.remainingBits + string(c)
		if len(w.remainingBits) == 8 {
			var nb byte
			var power float64
			for idx := len(w.remainingBits) - 1; idx >= 0; idx-- {
				if w.remainingBits[idx] == '1' {
					nb = nb + uint8(math.Pow(2, power))
				}
				power++
			}
			w.b = append(w.b, nb)
			w.remainingBits = ""
		}
	}
}
1356200
func (f *win32File) Write(b []byte) (int, error) {
	c, err := f.prepareIo()
	if err != nil {
		return 0, err
	}
	defer f.wg.Done()

	if f.writeDeadline.timedout.isSet() {
		return 0, ErrTimeout
	}

	var bytes uint32
	err = syscall.WriteFile(f.handle, b, &bytes, &c.o)
	n, err := f.asyncIo(c, &f.writeDeadline, bytes, err)
	runtime.KeepAlive(b)
	return n, err
}
683312
func (w *Writer) Write(buf []byte) (int, error) {
	if len(buf) > 0 {
		if w.start == -1 {
			// Find start of message index
			for i, c := range buf {
				if c == Delimiter && i > 0 {
					l := buf[i-1]
					level := Levels[l]
					if level > 0 {
						w.start = i - 1
						break
					}
				}
			}
			if w.start == -1 {
				buf = append(invalidMSG, buf...)
				return w.w.Write(buf)
			}
		}
		l := Levels[buf[w.start]]
		if l >= LogLevel() {
			return w.w.Write(buf)
		} else if l == 0 {
			buf = append(invalidMSG, buf...)
			return w.w.Write(buf)
		}
	}
	return 0, nil
}
830419
func (b *builderBuffer) Write(v []byte) {
	l := uint(len(v))
	if l > 0 {
		off := uint(len(*b))
		b.growCapacity(l)
		*b = (*b)[:off+l]
		copy((*b)[off:], v)
	}
}
309332
func (sbself *splitBufferedWriter) Write(data []byte) (int, error) {
	toCopy := len(sbself.userBuffer) - sbself.userBufferCount
	if toCopy > len(data) {
		toCopy = len(data)
	}
	copy(sbself.userBuffer[sbself.userBufferCount:sbself.userBufferCount+toCopy], data[:toCopy])
	sbself.userBufferCount += toCopy
	if toCopy < len(data) { // we need to overflow to remainder
		count, err := sbself.remainder.Write(data[toCopy:])
		return count + toCopy, err
	}
	return toCopy, nil
}
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
}
500714
func (w *Writer) Write(data []byte) (n int, err error) {
	if w.writer == nil {
		if w.filename == "" {
			w.writer = os.Stdout
			w.filename = os.Stdout.Name()
		} else {
			file, err := os.Create(w.filename)
			if err != nil {
				return 0, err
			}
			w.writer = file
		}
	}
	return w.writer.Write(data)
}
324034
func (b *basicWriter) Write(buf []byte) (int, error) {
	b.maybeWriteHeader()
	return b.ResponseWriter.Write(buf)
}
827772
func (c *rwConn) Write(p []byte) (int, error) {
	n, err := c.BufWriter.Write(p)
	if err := c.BufWriter.Flush(); err != nil {
		return 0, err
	}
	return n, err
}
609814
func (nw *NullIO) Write(v []byte) (int, error) {
	return len(v), nil
}
269954
func (enc *Encoder) Write() (int, error) {
	i, err := enc.w.Write(enc.buf)
	enc.buf = enc.buf[:0]
	return i, err
}
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()
}
6376
func (this *BufferedWriter) Write(p []byte) (n int, err error) {

	dst := make([]byte, len(p), len(p))
	copy(dst, p)

	select {
	case this.queue <- dst:
		return len(dst), nil
	default:
		return 0, BufferFull
	}
}
761178
func (w *writer) Write(b []byte) (int, error) {
	switch w.pri {
	case sInfo:
		return len(b), w.el.Info(1, string(b))
	case sWarning:
		return len(b), w.el.Warning(3, string(b))
	case sError:
		return len(b), w.el.Error(2, string(b))
	}
	return 0, fmt.Errorf("unrecognized severity: %v", w.pri)
}
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
}