// CreateWriter writes a mail header to w and creates a new Writer.
435951
func CreateWriter(w io.Writer, header Header) (*Writer, error) {
	header.Set("Content-Type", "multipart/mixed")

	mw, err := message.CreateWriter(w, header.Header)
	if err != nil {
		return nil, err
	}

	return &Writer{mw}, nil
}
38604
func writeHeaders(w io.Writer, statusCode int, headers http.Header) {
	fmt.Fprintf(w, "%d %s\n", statusCode, http.StatusText(statusCode))
	for k, v := range headers {
		fmt.Fprintf(w, "%s: %s\n", k, v[0])
	}
}
640273
func NewWriter(w io.Writer) *Writer {
	f, _ := w.(flusher)

	var o int64
	if s, ok := w.(io.Seeker); ok {
		var err error
		if o, err = s.Seek(0, io.SeekCurrent); err != nil {
			o = 0
		}
	}
	return &Writer{
		w:                w,
		f:                f,
		baseOffset:       o,
		lastRecordOffset: -1,
	}
}
1063108
func NewWriter(w io.Writer, limiter Limiter) io.Writer {
	return &writer{w, limiter}
}
1240593
func NewWriter(w io.Writer) *Writer {
	return &Writer{
		raw:  w,
		zlib: zlib.NewWriter(w),
	}
}
1146069
func (e Encoder) NewWriter(wr io.Writer) *Writer {
	w := new(Writer)
	w.wr = wr
	w.encode = e
	return w
}
1187231
func (rw *GCS) NewWriter(id string) (io.WriteCloser, error) {
	ctx := context.Background()
	obj := rw.bucket.Object(rw.Prefixed.Name(id))
	return obj.NewWriter(ctx), nil
}
1192304
func NewIndentWriter(w io.Writer, pre ...[]byte) io.Writer {
	return &indentWriter{
		w:   w,
		pre: pre,
		bol: true,
	}
}
1013953
func (w *bufferedWriter) createNewWriter(file *os.File) io.Writer {
	w.buf = bufio.NewWriterSize(file, w.bufSize)
	return w.buf
}
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
}
253869
func NewOCFWriter(config OCFConfig) (*OCFWriter, error) {
	var err error
	ocf := &OCFWriter{iow: config.W}

	switch config.W.(type) {
	case nil:
		return nil, errors.New("cannot create OCFWriter when W is nil")
	case *os.File:
		file := config.W.(*os.File)
		stat, err := file.Stat()
		if err != nil {
			return nil, fmt.Errorf("cannot create OCFWriter: %s", err)
		}
		// NOTE: When upstream provides a new file, it will already exist but
		// have a size of 0 bytes.
		if stat.Size() > 0 {
			// attempt to read existing OCF header
			if ocf.header, err = readOCFHeader(file); err != nil {
				return nil, fmt.Errorf("cannot create OCFWriter: %s", err)
			}
			// prepare for appending data to existing OCF
			if err = ocf.quickScanToTail(file); err != nil {
				return nil, fmt.Errorf("cannot create OCFWriter: %s", err)
			}
			return ocf, nil // happy case for appending to existing OCF
		}
	}

	// create new OCF header based on configuration parameters
	if ocf.header, err = newOCFHeader(config); err != nil {
		return nil, fmt.Errorf("cannot create OCFWriter: %s", err)
	}
	if err = writeOCFHeader(ocf.header, config.W); err != nil {
		return nil, fmt.Errorf("cannot create OCFWriter: %s", err)
	}
	return ocf, nil // another happy case for creation of new OCF
}
803353
func (c *CSV) NewWriter(res *exchange.Resource, context *qor.Context) (exchange.Writer, error) {
	writer := &Writer{CSV: c, Resource: res, context: context}

	var metas []*exchange.Meta
	for _, meta := range res.Metas {
		if meta.HasPermission(roles.Read, context) {
			metas = append(metas, meta)
		}
	}
	writer.metas = metas

	csvWriter, err := c.getWriter()

	if err == nil {
		writer.Writer = csv.NewWriter(csvWriter)
	}

	return writer, err
}
1056646
func New(w io.Writer, n int64) io.Writer {
	return &limitWriter{
		w: w,
		n: n,
	}
}
145031
func (rww *httpResponseRecorder) WriteHeader(httpCode int) {
	rww.respStatusCode = httpCode
	rww.ResponseWriter.WriteHeader(httpCode)
}
1280235
func NewWriter(w io.Writer, bo binary.ByteOrder) Writer {
	return &writer{
		w:  w,
		bo: bo,
	}
}
166346
func NewWriter(dir string) (*Writer, error) {
	if err := os.MkdirAll(dir, 0777); err != nil {
		return nil, err
	}
	dirFile, err := fileutil.OpenDir(dir)
	if err != nil {
		return nil, err
	}
	cw := &Writer{
		dirFile:     dirFile,
		n:           0,
		crc32:       newCRC32(),
		segmentSize: defaultChunkSegmentSize,
	}
	return cw, nil
}
857078
func NewResponseWriter(w http.ResponseWriter) ResponseWriter {
	rw := responseWriter{w: w}
	return &rw
}