// WriteV1Header writes a tar header to a writer in V1 tarsum format.
775720
func WriteV1Header(h *tar.Header, w io.Writer) {
	for _, elem := range v1TarHeaderSelect(h) {
		w.Write([]byte(elem[0] + elem[1]))
	}
}
1319817
func (f *FilterHeaderStore) WriteHeaders(hdrs ...FilterHeader) error {
	// Lock store for write.
	f.mtx.Lock()
	defer f.mtx.Unlock()

	// If there are 0 headers to be written, return immediately. This
	// prevents the newTip assignment from panicking because of an index
	// of -1.
	if len(hdrs) == 0 {
		return nil
	}

	// First, we'll grab a buffer from the write buffer pool so we an
	// reduce our total number of allocations, and also write the headers
	// in a single swoop.
	headerBuf := headerBufPool.Get().(*bytes.Buffer)
	headerBuf.Reset()
	defer headerBufPool.Put(headerBuf)

	// Next, we'll write out all the passed headers in series into the
	// buffer we just extracted from the pool.
	for _, header := range hdrs {
		if _, err := headerBuf.Write(header.FilterHash[:]); err != nil {
			return err
		}
	}

	// With all the headers written to the buffer, we'll now write out the
	// entire batch in a single write call.
	if err := f.appendRaw(headerBuf.Bytes()); err != nil {
		return err
	}

	// As the block headers should already be written, we only need to
	// update the tip pointer for this particular header type.
	newTip := hdrs[len(hdrs)-1].toIndexEntry().hash
	return f.truncateIndex(&newTip, false)
}
901214
func (lw *logWriter) WriteHeader(status int) {

	if lw.committed {
		log.Println("response already committed")
		return
	}

	lw.status = status
	lw.ResponseWriter.WriteHeader(status)
	lw.committed = true
}
345855
func (w *Writer) WriteHeader(src, dst Object) error {
	var srcPath, dstPath string
	if src == EmptyObject && dst == EmptyObject {
		return ErrEmptyComparsion
	}
	if src != EmptyObject {
		srcPath = filepath.Join(w.SrcPrefix, src.Path)
		dstPath = srcPath
	}
	if dst != EmptyObject {
		dstPath = filepath.Join(w.DstPrefix, dst.Path)
		if srcPath == "" {
			srcPath = dstPath
		}
	}
	// TODO: Detect renames?

	fmt.Fprintf(w, "diff --git %s %s\n", srcPath, dstPath)
	if src == EmptyObject {
		fmt.Fprintf(w, "new file mode %06d\n", dst.Mode)
		fmt.Fprintf(w, "index %x..%x\n", src.ID, dst.ID)
		fmt.Fprintf(w, "--- /dev/null\n")
		fmt.Fprintf(w, "+++ %s\n", dstPath)
	} else if dst == EmptyObject {
		fmt.Fprintf(w, "deleted file mode %06d\n", src.Mode)
		fmt.Fprintf(w, "index %x..%x\n", src.ID, dst.ID)
		fmt.Fprintf(w, "--- %s\n", srcPath)
		fmt.Fprintf(w, "+++ /dev/null\n")
	} else {
		fmt.Fprintf(w, "index %x..%x %06d\n", src.ID, dst.ID, dst.Mode)
		fmt.Fprintf(w, "--- %s\n", srcPath)
		fmt.Fprintf(w, "+++ %s\n", dstPath)
	}
	return nil
}
887526
func (c *cacheControlResponseWriter) WriteHeader(statusCode int) {
	c.statusCode = statusCode
	c.ResponseWriter.WriteHeader(statusCode)
}
1245767
func (t *http2Server) WriteHeader(s *Stream, md metadata.MD) error {
	if s.updateHeaderSent() || s.getState() == streamDone {
		return ErrIllegalHeaderWrite
	}
	s.hdrMu.Lock()
	if md.Len() > 0 {
		if s.header.Len() > 0 {
			s.header = metadata.Join(s.header, md)
		} else {
			s.header = md
		}
	}
	if err := t.writeHeaderLocked(s); err != nil {
		s.hdrMu.Unlock()
		return err
	}
	s.hdrMu.Unlock()
	return nil
}
1143229
func (r *RPCHeaderHandler) WriteHeader(w io.Writer, req []byte, writeAuth bool) error {
	var (
		token string
		err   error
		err2  error
	)
	binary.Write(w, byteOrder, RPCMagicNumber)
	if writeAuth {
		binary.Write(w, byteOrder, uint8(1))
		// get current host token
		var signer Signer = &delegateKeys
		token, err = AuthTokenNonBlocking()
		if err != nil {
			log.WithError(err).Debug("Unable to retrieve delegate token")
			// We may be an un-added master
			token, err2 = MasterToken()
			if err2 != nil {
				log.WithError(err2).Debug("Unable to retrieve master token")
				// Return the original error message
				return err
			}
			signer = &masterKeys
		}
		h := NewAuthHeaderWriterTo([]byte(token), req, signer)
		_, err = h.WriteTo(w)
	} else {
		binary.Write(w, byteOrder, uint8(0))
		WriteLengthAndBytes(req, w)
	}
	return err
}
301212
func writeHeader(b *bytes.Buffer, header map[string][]string) {
	if len(header) == 0 {
		b.WriteString("   (no headers)\n")
		return
	}
	keys := make([]string, 0, len(header))
	// Alphabetize the headers
	for k := range header {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	for _, k := range keys {
		// Redact the value of any Authorization header to prevent security information from persisting in logs
		value := interface{}("REDACTED")
		if !strings.EqualFold(k, "Authorization") {
			value = header[k]
		}
		fmt.Fprintf(b, "   %s: %+v\n", k, value)
	}
}
1111038
func (c chunk) WriteToVST1_1(w io.Writer) (int64, error) {
	le := binary.LittleEndian
	hdr := [maxChunkHeaderSize]byte{}

	le.PutUint32(hdr[0:], uint32(len(c.Data)+len(hdr))) // length
	le.PutUint32(hdr[4:], c.chunkX)                     // chunkX
	le.PutUint64(hdr[8:], c.MessageID)                  // message ID
	le.PutUint64(hdr[16:], c.MessageLength)             // message length

	// Write header
	//fmt.Printf("Writing hdr: %s\n", hex.EncodeToString(hdr))
	if n, err := w.Write(hdr[:]); err != nil {
		return int64(n), driver.WithStack(err)
	}

	// Write data
	//fmt.Printf("Writing data: %s\n", hex.EncodeToString(c.Data))
	n, err := w.Write(c.Data)
	result := int64(n) + int64(len(hdr))
	if err != nil {
		return result, driver.WithStack(err)
	}
	return result, nil
}
572840
func (c *CompressResponseWriter) WriteHeader(status int) {
	if c.closed {
		return
	}
	c.headersWritten = true
	c.prepareHeaders()
	c.Header.SetStatus(status)
}
74184
func (r *responseWriterWithStatus) WriteHeader(code int) {
	r.code = code
	r.ResponseWriter.WriteHeader(code)
}
735578
func (s *SvcProvider) Write() error {
	key := fmt.Sprintf(svcProviderPath, s.ID)
	err := s.StateDriver.WriteState(key, s, json.Marshal)
	return err
}
189549
func (rw *responseWriter) WriteHeader(c int) {
	if rw.Written() {
		return
	}
	rw.status = c
	rw.w.WriteHeader(c)
}
1049122
func WriteHeader(w io.Writer, h Header) error {
	// TODO: wrap lines when necessary

	for i := len(h.l) - 1; i >= 0; i-- {
		f := h.l[i]

		if f.b == nil {
			f.b = []byte(formatHeaderField(f.k, f.v))
		}

		if _, err := w.Write(f.b); err != nil {
			return err
		}
	}

	_, err := w.Write([]byte{'\r', '\n'})
	return err
}
1322941
func (w *wrapper) WriteHeader(code int) {
	w.status = code
	w.ResponseWriter.WriteHeader(code)
}
237973
func (w *Writer) WriteHeader(t plumbing.ObjectType, size int64) error {
	if !t.Valid() {
		return plumbing.ErrInvalidType
	}
	if size < 0 {
		return ErrNegativeSize
	}

	b := t.Bytes()
	b = append(b, ' ')
	b = append(b, []byte(strconv.FormatInt(size, 10))...)
	b = append(b, 0)

	defer w.prepareForWrite(t, size)
	_, err := w.zlib.Write(b)

	return err
}
405623
func (builder *MultipartBuilder) WriteFileHeader(partName string, fileHeader *multipart.FileHeader) error {
	file, err := fileHeader.Open()
	if err != nil {
		return err
	}
	defer file.Close()
	return builder.WriteFileReader(partName, fileHeader.Filename, file)
}