diff options
author | Prashanth Pai <ppai@redhat.com> | 2015-06-17 12:46:58 +0530 |
---|---|---|
committer | Thiago da Silva <thiago@redhat.com> | 2015-06-18 05:53:54 -0700 |
commit | 2c468ae0d5a1e25998373abb72d87b1ee7693816 (patch) | |
tree | 3befca1e0e8ae2dfd6fac36e876ca06948724840 /gluster | |
parent | ddbd7b570d0a9f599b417a499c912c5b13a003c9 (diff) |
Fix reading of binary data in read()
As per the current code, this is the behavior:
>>> with v.fopen("/abc", 'r') as f:
... data = f.read(5)
>>> print data
<ctypes.c_char_Array_2 object at 0x7fda7d6bbb90>
>>> print data.value
hello
>>>
It's incorrect to return a ctypes internal object back to the user.
In Python 2.x, read() always returns a string. It's really upto
the consumer to decode this string into whatever encoding it was
written with.
This patch reverts parts of this old change:
Ia2bb47343880cbf7121fed9510e4cfa085fe23bd
Change-Id: Ia1d3e5834be2b856776bd3cf8382a17ffd61d5df
Signed-off-by: Prashanth Pai <ppai@redhat.com>
Diffstat (limited to 'gluster')
-rwxr-xr-x | gluster/gfapi.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/gluster/gfapi.py b/gluster/gfapi.py index 96088ff..bd6f240 100755 --- a/gluster/gfapi.py +++ b/gluster/gfapi.py @@ -319,7 +319,10 @@ class File(object): rbuf = ctypes.create_string_buffer(size) ret = api.glfs_read(self.fd, rbuf, size, 0) if ret > 0: - return rbuf + # In python 2.x, read() always returns a string. It's really upto + # the consumer to decode this string into whatever encoding it was + # written with. + return rbuf.value[:ret] elif ret < 0: err = ctypes.get_errno() raise OSError(err, os.strerror(err)) |