// WriteToPNG encodes a Surface to an io.Writer as a PNG file.
181670
func (surface *Surface) WriteToPNG(w io.Writer) error {
	data := writeClosure{w: w}
	key := goPointers.put(data)
	status := C.cairo_surface_write_to_png_stream((*C.cairo_surface_t)(surface.Ptr),
		(C.cairo_write_func_t)(unsafe.Pointer(C.gocairo_write_func)),
		unsafe.Pointer(&key))
	goPointers.clear(key)
	// TODO: which should we prefer between writeClosure.err and status?
	// Perhaps test against CAIRO_STATUS_WRITE_ERROR?  Needs a test case.
	return Status(status).toError()
}
101347
func (w *NonColorable) Write(data []byte) (n int, err error) {
	er := bytes.NewReader(data)
	var bw [1]byte
loop:
	for {
		c1, err := er.ReadByte()
		if err != nil {
			break loop
		}
		if c1 != 0x1b {
			bw[0] = c1
			w.out.Write(bw[:])
			continue
		}
		c2, err := er.ReadByte()
		if err != nil {
			break loop
		}
		if c2 != 0x5b {
			continue
		}

		var buf bytes.Buffer
		for {
			c, err := er.ReadByte()
			if err != nil {
				break loop
			}
			if ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '@' {
				break
			}
			buf.Write([]byte(string(c)))
		}
	}

	return len(data), nil
}
295158
func Write(w io.Writer, data ...interface{}) error {
	for _, v := range data {
		if err := binary.Write(w, binary.BigEndian, v); err != nil {
			return err
		}
	}

	return nil
}
1226083
func writePrettyString(writer io.Writer, input string) {
	colorWriter := tview.ANSIWriter(writer)
	var jsonData map[string]interface{}
	jsonErr := json.Unmarshal([]byte(input), &jsonData)
	if jsonErr == nil {
		// pretty print it to colors...
		prettyString, prettyStringErr := prettyjson.Marshal(jsonData)
		if prettyStringErr == nil {
			/* #nosec */
			io.WriteString(colorWriter, string(prettyString))
		} else {
			/* #nosec */
			io.WriteString(colorWriter, input)
		}
	} else {
		/* #nosec */

		io.WriteString(colorWriter, strings.TrimSpace(input))
	}
	/* #nosec */
	io.WriteString(writer, "\n")
}
1373145
func Write(w io.Writer, byteOrder binary.ByteOrder, g geom.T) error {
	var ewkbByteOrder byte
	switch byteOrder {
	case XDR:
		ewkbByteOrder = wkbcommon.XDRID
	case NDR:
		ewkbByteOrder = wkbcommon.NDRID
	default:
		return wkbcommon.ErrUnsupportedByteOrder{}
	}
	if err := binary.Write(w, byteOrder, ewkbByteOrder); err != nil {
		return err
	}

	var ewkbGeometryType uint32
	switch g.(type) {
	case *geom.Point:
		ewkbGeometryType = wkbcommon.PointID
	case *geom.LineString:
		ewkbGeometryType = wkbcommon.LineStringID
	case *geom.Polygon:
		ewkbGeometryType = wkbcommon.PolygonID
	case *geom.MultiPoint:
		ewkbGeometryType = wkbcommon.MultiPointID
	case *geom.MultiLineString:
		ewkbGeometryType = wkbcommon.MultiLineStringID
	case *geom.MultiPolygon:
		ewkbGeometryType = wkbcommon.MultiPolygonID
	case *geom.GeometryCollection:
		ewkbGeometryType = wkbcommon.GeometryCollectionID
	default:
		return geom.ErrUnsupportedType{Value: g}
	}
	switch g.Layout() {
	case geom.XY:
	case geom.XYZ:
		ewkbGeometryType |= ewkbZ
	case geom.XYM:
		ewkbGeometryType |= ewkbM
	case geom.XYZM:
		ewkbGeometryType |= ewkbZ | ewkbM
	default:
		return geom.ErrUnsupportedLayout(g.Layout())
	}
	srid := g.SRID()
	if srid != 0 {
		ewkbGeometryType |= ewkbSRID
	}
	if err := binary.Write(w, byteOrder, ewkbGeometryType); err != nil {
		return err
	}
	if ewkbGeometryType&ewkbSRID != 0 {
		if err := binary.Write(w, byteOrder, uint32(srid)); err != nil {
			return err
		}
	}

	switch g := g.(type) {
	case *geom.Point:
		return wkbcommon.WriteFlatCoords0(w, byteOrder, g.FlatCoords())
	case *geom.LineString:
		return wkbcommon.WriteFlatCoords1(w, byteOrder, g.FlatCoords(), g.Stride())
	case *geom.Polygon:
		return wkbcommon.WriteFlatCoords2(w, byteOrder, g.FlatCoords(), g.Ends(), g.Stride())
	case *geom.MultiPoint:
		n := g.NumPoints()
		if err := binary.Write(w, byteOrder, uint32(n)); err != nil {
			return err
		}
		for i := 0; i < n; i++ {
			if err := Write(w, byteOrder, g.Point(i)); err != nil {
				return err
			}
		}
		return nil
	case *geom.MultiLineString:
		n := g.NumLineStrings()
		if err := binary.Write(w, byteOrder, uint32(n)); err != nil {
			return err
		}
		for i := 0; i < n; i++ {
			if err := Write(w, byteOrder, g.LineString(i)); err != nil {
				return err
			}
		}
		return nil
	case *geom.MultiPolygon:
		n := g.NumPolygons()
		if err := binary.Write(w, byteOrder, uint32(n)); err != nil {
			return err
		}
		for i := 0; i < n; i++ {
			if err := Write(w, byteOrder, g.Polygon(i)); err != nil {
				return err
			}
		}
		return nil
	case *geom.GeometryCollection:
		n := g.NumGeoms()
		if err := binary.Write(w, byteOrder, uint32(n)); err != nil {
			return err
		}
		for i := 0; i < n; i++ {
			if err := Write(w, byteOrder, g.Geom(i)); err != nil {
				return err
			}
		}
		return nil
	default:
		return geom.ErrUnsupportedType{Value: g}
	}
}
1056710
func (txPvtRwSet *TxPvtRwSet) toProtoMsg() (*rwset.TxPvtReadWriteSet, error) {
	protoMsg := &rwset.TxPvtReadWriteSet{DataModel: rwset.TxReadWriteSet_KV}
	var nsProtoMsg *rwset.NsPvtReadWriteSet
	var err error
	for _, nsPvtRwSet := range txPvtRwSet.NsPvtRwSet {
		if nsProtoMsg, err = nsPvtRwSet.toProtoMsg(); err != nil {
			return nil, err
		}
		protoMsg.NsPvtRwset = append(protoMsg.NsPvtRwset, nsProtoMsg)
	}
	return protoMsg, nil
}
610171
func ImageWrite(ctx ImageContext, images []types.ImageSummary) error {
	render := func(format func(subContext SubContext) error) error {
		return imageFormat(ctx, images, format)
	}
	return ctx.Write(newImageContext(), render)
}
818115
func (e *Exportable) WriteTo(w io.Writer) (int64, error) {
	return e.buffer.WriteTo(w)
}
19446
func (w *Writer) Write(data []byte) (n int, err error) {
	// Do not print indentation if there is no data.
	indentBuf := indentationTabs
	if w.UseSpaces {
		indentBuf = indentationSpaces
	}

	for len(data) > 0 {
		var printUntil int
		endsWithNewLine := false

		lineBeginning := !w.insideLine
		if data[0] == '\n' && lineBeginning {
			// This is a blank line. Do not indent it, just print as is.
			printUntil = 1
		} else {
			if lineBeginning {
				// Print indentation.
				w.Writer.Write(indentBuf[:w.Level])
				w.insideLine = true
			}

			lineEnd := bytes.IndexRune(data, '\n')
			if lineEnd < 0 {
				// Print the whole thing.
				printUntil = len(data)
			} else {
				// Print until the newline inclusive.
				printUntil = lineEnd + 1
				endsWithNewLine = true
			}
		}
		toPrint := data[:printUntil]
		data = data[printUntil:]

		// Assertion: none of the runes in toPrint
		// can be newline except the last rune.
		// The last rune is newline iff endsWithNewLine==true.

		m, err := w.Writer.Write(toPrint)
		n += m

		if m == len(toPrint) && endsWithNewLine {
			// We've printed the newline, so we are the line beginning again.
			w.insideLine = false
		}
		if err != nil {
			return n, err
		}
	}
	return n, nil
}
267967
func SaveToPNG(path string, img image.Image) {
	f, err := os.Create(path)
	if err != nil {
		log.Println(err)
	}
	defer f.Close()

	png.Encode(f, img)
}
60063
func (aw *AnsiWriter) Write(b []byte) (int, error) {
	return aw.file.Write(b)
}
1088076
func (w *Writer) Write(p []byte) (int, error) {
	nWritten := 0
	ss := strings.Split(string(p), "\n")
	for i, s := range ss {
		// TODO: strip out pre-existing ANSI codes and expand tabs. Would be
		// great to expand tabs in a context aware way (line linux expand
		// command).

		n, err := w.writeRaw(s)
		if err != nil {
			return nWritten, err
		}
		nWritten += n

		// Increment the origin (line count) for each newline.  There is a
		// newline for every item in this array except the last one.
		if i != len(ss)-1 {
			n, err := w.Output.Write([]byte("\n"))
			if err != nil {
				return nWritten, err
			}
			nWritten += n
			w.origin++
			w.lineIdx = 0
		}
	}
	return nWritten, nil
}
1047229
func (rb *Bitmap) WriteTo(stream io.Writer) (int64, error) {
	return rb.highlowcontainer.writeTo(stream)
}
614629
func (w *Writer) WriteTuple(tuple ...interface{}) {
	setWriterRef(w, nil, nil)
	count := len(tuple)
	if count == 0 {
		writeEmptyList(w)
		return
	}
	writeListHeader(w, count)
	for _, v := range tuple {
		w.Serialize(v)
	}
	writeListFooter(w)
}
617000
func Write(
	w io.Writer,
	header *Header,
	tocs []*Toc,
	metrics map[uint64]Metric,
	values map[uint64]*Value,
	instances map[uint64]Instance,
	indoms map[uint64]*InstanceDomain,
	strings map[uint64]*String,
) error {
	if _, err := fmt.Fprintf(w, `Version   = %v
Generated = %v
Toc Count = %v
Cluster   = %v
Process   = %v
Flags     = 0x%x

`, header.Version, header.G1, header.Toc, header.Cluster, header.Process, int(header.Flag)); err != nil {
		return err
	}

	return writeComponents(w, header, tocs, metrics, values, instances, indoms, strings)
}
778820
func (w *Writer) WriteBulk(s string) {
	fmt.Fprintf(w.w, "$%d\r\n%s\r\n", len(s), s)
}
777428
func (aw *Writer) Write(b []byte) (n int, err error) {
	if int64(len(b)) > aw.nb {
		b = b[0:aw.nb]
		err = ErrWriteTooLong
	}
	n, werr := aw.w.Write(b)
	aw.nb -= int64(n)
	if werr != nil {
		return n, werr
	}

	if len(b)%2 == 1 { // data size must be aligned to an even byte
		n2, _ := aw.w.Write([]byte{'\n'})
		return n+n2, err
	}

	return
}