// ssize_t rbd_write(rbd_image_t image, uint64_t ofs, size_t len, const char *buf);
335167
func (image *Image) Write(data []byte) (n int, err error) {
	ret := int(C.rbd_write(image.image, C.uint64_t(image.offset),
		C.size_t(len(data)), (*C.char)(unsafe.Pointer(&data[0]))))

	if ret >= 0 {
		image.offset += int64(ret)
	}

	if ret != len(data) {
		err = RBDError(-C.EPERM)
	}

	return ret, err
}
632996
func (co *Context) GetRNNParamsSize(rnnDesc *RNN, xDesc *TensorDescriptor, dataType DataType) (sizeInBytes uintptr, err error) {
	var sizeInBytesC C.size_t
	// call cudnnGetRNNParamsSize
	err = result(C.cudnnGetRNNParamsSize(co.internal, rnnDesc.internal, xDesc.internal, &sizeInBytesC, dataType.C()))
	sizeInBytes = uintptr(sizeInBytesC)
	return
}
344852
func writeBlob(data []byte, buf *bytes.Buffer) (int, error) {
	// Add the size of the blob
	dlen := int32(len(data))
	if err := binary.Write(buf, binary.BigEndian, dlen); err != nil {
		return 0, err
	}

	// Write the data
	if _, err := buf.Write(data); err != nil {
		return 0, nil
	}

	// Add padding bytes if necessary
	numPadBytes := padBytesNeeded(len(data))
	if numPadBytes > 0 {
		padBytes := make([]byte, numPadBytes)
		n, err := buf.Write(padBytes)
		if err != nil {
			return 0, err
		}
		numPadBytes = n
	}

	return 4 + len(data) + numPadBytes, nil
}
526723
func (o *LargeObject) Write(p []byte) (int, error) {
	n, err := fpInt32(o.lo.fp.CallFn("lowrite", []fpArg{fpIntArg(o.fd), p}))
	return int(n), err
}
880796
func resizer(buf []byte, o Options) ([]byte, error) {
	defer C.vips_thread_shutdown()

	image, imageType, err := loadImage(buf)
	if err != nil {
		return nil, err
	}

	// Clone and define default options
	o = applyDefaults(o, imageType)

	if !IsTypeSupported(o.Type) {
		return nil, errors.New("Unsupported image output type")
	}

	// Auto rotate image based on EXIF orientation header
	image, rotated, err := rotateAndFlipImage(image, o)
	if err != nil {
		return nil, err
	}

	// If JPEG image, retrieve the buffer
	if rotated && imageType == JPEG && !o.NoAutoRotate {
		buf, err = getImageBuffer(image)
		if err != nil {
			return nil, err
		}
	}

	inWidth := int(image.Xsize)
	inHeight := int(image.Ysize)

	// Infer the required operation based on the in/out image sizes for a coherent transformation
	normalizeOperation(&o, inWidth, inHeight)

	// image calculations
	factor := imageCalculations(&o, inWidth, inHeight)
	shrink := calculateShrink(factor, o.Interpolator)
	residual := calculateResidual(factor, shrink)

	// Do not enlarge the output if the input width or height
	// are already less than the required dimensions
	if !o.Enlarge && !o.Force {
		if inWidth < o.Width && inHeight < o.Height {
			factor = 1.0
			shrink = 1
			residual = 0
			o.Width = inWidth
			o.Height = inHeight
		}
	}

	// Try to use libjpeg/libwebp shrink-on-load
	supportsShrinkOnLoad := imageType == WEBP && VipsMajorVersion >= 8 && VipsMinorVersion >= 3
	supportsShrinkOnLoad = supportsShrinkOnLoad || imageType == JPEG
	if supportsShrinkOnLoad && shrink >= 2 {
		tmpImage, factor, err := shrinkOnLoad(buf, image, imageType, factor, shrink)
		if err != nil {
			return nil, err
		}

		image = tmpImage
		factor = math.Max(factor, 1.0)
		shrink = int(math.Floor(factor))
		residual = float64(shrink) / factor
	}

	// Zoom image, if necessary
	image, err = zoomImage(image, o.Zoom)
	if err != nil {
		return nil, err
	}

	// Transform image, if necessary
	if shouldTransformImage(o, inWidth, inHeight) {
		image, err = transformImage(image, o, shrink, residual)
		if err != nil {
			return nil, err
		}
	}

	// Apply effects, if necessary
	if shouldApplyEffects(o) {
		image, err = applyEffects(image, o)
		if err != nil {
			return nil, err
		}
	}

	// Add watermark, if necessary
	image, err = watermarkImageWithText(image, o.Watermark)
	if err != nil {
		return nil, err
	}

	// Add watermark, if necessary
	image, err = watermarkImageWithAnotherImage(image, o.WatermarkImage)
	if err != nil {
		return nil, err
	}

	// Flatten image on a background, if necessary
	image, err = imageFlatten(image, imageType, o)
	if err != nil {
		return nil, err
	}

	return saveImage(image, o)
}
1188764
func RBDCreate(
	ctx types.Context,
	pool *string,
	image *string,
	sizeGB *int64,
	objectSize *string,
	features []*string) error {

	cmd := exec.Command(
		rbdCmd, "create", poolOpt, *pool,
		"--object-size", *objectSize,
		"--size", strconv.FormatInt(*sizeGB, 10)+"G",
	)

	for _, feature := range features {
		cmd.Args = append(cmd.Args, "--image-feature")
		cmd.Args = append(cmd.Args, *feature)
	}

	cmd.Args = append(cmd.Args, *image)
	_, _, err := RunCommand(ctx, cmd)
	if err != nil {
		return goof.WithError("unable to create rbd", err)
	}

	return nil
}
795946
func FormatSize(size uint64) string {
	ord := []string{"K", "M", "G", "T", "P", "E"}
	o := 0
	buf := new(bytes.Buffer)
	w := bufio.NewWriter(buf)

	if size < 973 {
		fmt.Fprintf(w, "%3d ", size)
		w.Flush()
		return buf.String()
	}

	for {
		remain := size & 1023
		size >>= 10

		if size >= 973 {
			o++
			continue
		}

		if size < 9 || (size == 9 && remain < 973) {
			remain = ((remain * 5) + 256) / 512
			if remain >= 10 {
				size++
				remain = 0
			}

			fmt.Fprintf(w, "%d.%d%s", size, remain, ord[o])
			break
		}

		if remain >= 512 {
			size++
		}

		fmt.Fprintf(w, "%3d%s", size, ord[o])
		break
	}

	w.Flush()
	return buf.String()
}
946729
func SetDDLReorgBatchSize(cnt int32) {
	if cnt > MaxDDLReorgBatchSize {
		cnt = MaxDDLReorgBatchSize
	}
	if cnt < MinDDLReorgBatchSize {
		cnt = MinDDLReorgBatchSize
	}
	atomic.StoreInt32(&ddlReorgBatchSize, cnt)
}
734529
func (out *RAMOutputStream) WriteByte(b byte) error {
	if out.bufferPosition == out.bufferLength {
		out.currentBufferIndex++
		out.switchCurrentBuffer()
	}
	if out.crc != nil {
		out.crc.Write([]byte{b})
	}
	out.currentBuffer[out.bufferPosition] = b
	out.bufferPosition++
	return nil
}
1067108
func (rm *responseModifier) Write(b []byte) (int, error) {
	if rm.hijacked {
		return rm.rw.Write(b)
	}

	if len(rm.body)+len(b) > maxBufferSize {
		rm.Flush()
	}
	rm.body = append(rm.body, b...)
	return len(b), nil
}
1036951
func (rwops *RWops) Write2(buf []byte, size, num uint) (n int, err error) {
	if rwops == nil || buf == nil {
		return 0, ErrInvalidParameters
	}

	header := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
	_data := unsafe.Pointer(header.Data)

	n = int(C.RWwrite(rwops.cptr(), _data, C.size_t(size), C.size_t(num)))
	if n < int(num) {
		err = GetError()
	}
	return
}
1049416
func (c *SCSICmd) Write(b []byte) (n int, err error) {
	toWrite := len(b)
	boff := 0
	for toWrite != 0 {
		if c.vecoffset == len(c.vecs) {
			return boff, errors.New("out of buffer scsi cmd buffer space")
		}
		wrote := copy(c.vecs[c.vecoffset][c.offset:], b[boff:])
		boff += wrote
		toWrite -= wrote
		c.offset += wrote
		if c.offset == len(c.vecs[c.vecoffset]) {
			c.vecoffset++
			c.offset = 0
		}
	}
	return boff, nil
}
680791
func (dd *dictDecoder) WriteByte(c byte) {
	dd.hist[dd.wrPos] = c
	dd.wrPos++
}
996988
func (c *HyperClient) TTYResize(containerID, execID string, height, width int32) error {
	_, err := c.client.TTYResize(c.ctx, &types.TTYResizeRequest{
		ContainerID: containerID,
		ExecID:      execID,
		Height:      height,
		Width:       width,
	})

	return err
}
819055
func newBufferWriter(minShrinkSize, maxSize int) *bufferedWriter {
	w := &bufferedWriter{minShrinkSize: minShrinkSize, maxSize: maxSize}
	w.bufSize = minShrinkSize
	// The minSize is the minimum size the buffer can shrink to.
	// However, if the given max size is smaller than the min
	// shrink size, use that instead.
	if maxSize < minShrinkSize {
		w.bufSize = maxSize
	}
	return w
}
377848
func (buf *Buffer) WriteByte(c byte) error {
	r := len(buf.buf) + 1
	if cap(buf.buf) < r {
		l := r * 2
		buf.grow(l - cap(buf.buf))
	}
	buf.buf = append(buf.buf, c)
	return nil
}
403554
func (be *BinaryEncoder) WriteBytes(value []byte) {
	be.WriteInt32(int32(len(value)))
	copy(be.buffer[be.pos:], value)
	be.pos += len(value)
}