Skip to content

Commit da05e4d

Browse files
authored
Merge pull request #17 from dlech/rwbytes
use bytes objects for read and write data
2 parents a2c925d + f81a45e commit da05e4d

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

example/fioc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class FiocFS(Fuse):
9696

9797
def __init__(self, *args, **kw):
9898
Fuse.__init__(self, *args, **kw)
99-
self.buf = ""
99+
self.buf = b""
100100

101101
def resize(self, new_size):
102102
old_size = len(self.buf)
@@ -106,7 +106,7 @@ def resize(self, new_size):
106106
if new_size < old_size:
107107
self.buf = self.buf[0:new_size]
108108
else:
109-
self.buf = self.buf + "\x00" * (new_size - old_size)
109+
self.buf = self.buf + b"\x00" * (new_size - old_size)
110110

111111
return 0
112112

example/hello.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
fuse.fuse_python_api = (0, 2)
2323

2424
hello_path = '/hello'
25-
hello_str = 'Hello World!\n'
25+
hello_str = b'Hello World!\n'
2626

2727
class MyStat(fuse.Stat):
2828
def __init__(self):
@@ -72,7 +72,7 @@ def read(self, path, size, offset):
7272
size = slen - offset
7373
buf = hello_str[offset:offset+size]
7474
else:
75-
buf = ''
75+
buf = b''
7676
return buf
7777

7878
def main():

example/xmp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030

3131
def flag2mode(flags):
32-
md = {os.O_RDONLY: 'r', os.O_WRONLY: 'w', os.O_RDWR: 'w+'}
32+
md = {os.O_RDONLY: 'rb', os.O_WRONLY: 'wb', os.O_RDWR: 'wb+'}
3333
m = md[flags & (os.O_RDONLY | os.O_WRONLY | os.O_RDWR)]
3434

3535
if flags | os.O_APPEND:

fuseparts/_fusemodule.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,22 @@ read_func(const char *path, char *buf, size_t s, off_t off)
518518
PROLOGUE( PYO_CALLWITHFI(fi, read_cb, snK, path, s, off) )
519519
#endif
520520

521+
522+
#if PY_MAJOR_VERSION >= 3
523+
if(PyBytes_Check(v)) {
524+
if(PyBytes_Size(v) > s)
525+
goto OUT_DECREF;
526+
memcpy(buf, PyBytes_AsString(v), PyBytes_Size(v));
527+
ret = PyBytes_Size(v);
528+
}
529+
#else
521530
if(PyString_Check(v)) {
522531
if(PyString_Size(v) > s)
523532
goto OUT_DECREF;
524533
memcpy(buf, PyString_AsString(v), PyString_Size(v));
525534
ret = PyString_Size(v);
526535
}
536+
#endif
527537

528538
EPILOGUE
529539
}
@@ -537,7 +547,11 @@ static int
537547
write_func(const char *path, const char *buf, size_t t, off_t off)
538548
#endif
539549
{
550+
#if PY_MAJOR_VERSION >= 3
551+
PROLOGUE( PYO_CALLWITHFI(fi, write_cb, sy#K, path, buf, t, off) )
552+
#else
540553
PROLOGUE( PYO_CALLWITHFI(fi, write_cb, ss#K, path, buf, t, off) )
554+
#endif
541555
EPILOGUE
542556
}
543557

0 commit comments

Comments
 (0)