Add rados_write_full function

Signed-off-by: Ye Yin <eyniy@qq.com>
This commit is contained in:
Ye Yin 2015-07-20 20:37:32 +08:00
parent 8f882afdc3
commit f39179553f
2 changed files with 28 additions and 0 deletions

View File

@ -68,6 +68,24 @@ func (ioctx *IOContext) Write(oid string, data []byte, offset uint64) error {
}
}
// 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)))
if ret == 0 {
return nil
} else {
return RadosError(int(ret))
}
}
// Read reads up to len(data) bytes from the object with key oid starting at byte
// offset offset. It returns the number of bytes read and an error, if any.
func (ioctx *IOContext) Read(oid string, data []byte, offset uint64) (int, error) {

View File

@ -307,6 +307,16 @@ func TestReadWrite(t *testing.T) {
assert.Equal(t, n_out, len(bytes_in))
assert.Equal(t, bytes_in, bytes_out)
bytes_in = []byte("input another data")
err = pool.WriteFull("obj", bytes_in)
assert.NoError(t, err)
bytes_out = make([]byte, len(bytes_in))
n_out, err = pool.Read("obj", bytes_out, 0)
assert.Equal(t, n_out, len(bytes_in))
assert.Equal(t, bytes_in, bytes_out)
pool.Destroy()
}