From 42404434efe47d3d44e5e3c4c19c7c0034d2b844 Mon Sep 17 00:00:00 2001 From: Dawn K. Isabel Date: Thu, 30 May 2013 23:28:40 -0400 Subject: cython: Add read() method to AfcFile --- cython/afc.pxi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cython/afc.pxi b/cython/afc.pxi index 2608ee6..1ca4378 100644 --- a/cython/afc.pxi +++ b/cython/afc.pxi @@ -133,6 +133,20 @@ cdef class AfcFile(Base): cpdef truncate(self, uint64_t newsize): self.handle_error(afc_file_truncate(self._client._c_client, self._c_handle, newsize)) + cpdef bytes read(self, uint32_t size): + cdef: + uint32_t bytes_read + char* c_data = malloc(size) + bytes result + try: + self.handle_error(afc_file_read(self._client._c_client, self._c_handle, c_data, size, &bytes_read)) + result = c_data[:bytes_read] + return result + except BaseError, e: + raise + finally: + free(c_data) + cpdef uint32_t write(self, bytes data): cdef: uint32_t bytes_written -- cgit v1.1-32-gdbae