Beispiel #1
0
// WriteFull writes len(data) bytes to the object with key oid.
// The object is filled with the provided data. If the object exists,
// it is atomically truncated and then written. It returns an error, if any.
func (ioctx *IOContext) WriteFull(oid string, data []byte) error {
	c_oid := C.CString(oid)
	defer C.free(unsafe.Pointer(c_oid))

	ret := C.rados_write_full(ioctx.ioctx, c_oid,
		(*C.char)(unsafe.Pointer(&data[0])),
		(C.size_t)(len(data)))
	return GetRadosError(ret)
}
Beispiel #2
0
func (r *RadosIoCtx) WriteFull(oid string, bin []byte) error {
	coid := C.CString(oid)
	defer func() {
		C.free(unsafe.Pointer(coid))
	}()
	cerr := C.rados_write_full(*r.ctx, coid, (*C.char)(unsafe.Pointer(&bin[0])), C.size_t(len(bin)))
	if cerr < 0 {
		return errors.New("write full data failed")
	}
	return nil
}
Beispiel #3
0
// WriteFull writes the entire data to the object replacing old data.
func (o *Object) WriteFull(data io.Reader) error {
	oid := C.CString(o.name)
	defer freeString(oid)
	bufAddr, length := readerToBuf(data)
	ret := C.rados_write_full(o.ioContext, oid, bufAddr, length)
	if err := toRadosError(ret); err != nil {
		err.Message = fmt.Sprintf("Unable to write full data to object %s", o.name)
		return err
	}
	return nil
}
Beispiel #4
0
// Put writes data to the named object in the pool referenced by the
// given context. If the object does not exist, it will be created.
// If the object exists, it will first be truncated to 0 then overwritten.
func (c *Context) Put(name string, data []byte) error {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	cdata, cdatalen := byteSliceToBuffer(data)

	if cerr := C.rados_write_full(c.ctx, cname, cdata, cdatalen); cerr < 0 {
		return fmt.Errorf("RADOS put %s: %s", name, strerror(cerr))
	}

	return nil
}
Beispiel #5
0
// Put writes data to the named object in the pool referenced by the
// given context. If the object does not exist, it will be created.
// If the object exists, it will first be truncated to 0 then overwritten.
func (c *Context) Put(name string, data []byte) error {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	cdata, cdatalen := byteSliceToBuffer(data)

	if cerr := C.rados_write_full(c.ctx, cname, cdata, cdatalen); cerr < 0 {
		return radosReturnCodeError(cerr)
	}

	return nil
}