hamano / pysmbc

libsmbclient binding for Python
http://pypi.python.org/pypi/pysmbc
GNU General Public License v2.0
28 stars 27 forks source link

read() without a parameter makes seek fail #46

Closed frafra closed 4 years ago

frafra commented 4 years ago
(Pdb) obj.read()
read ()
b'PK\x05\x06\x00\x00\x00\x00*\x00*\x00\xae\x0f\x00\x00\x067\xa5\x00\x00\x00'
(Pdb) obj.seek(0, 2)
seek (0, 2)
*** ValueError: (22, 'Invalid argument')

To avoid that, I always pass a number of bytes, avoiding reading more than needed.

frafra commented 4 years ago

Workaround:

class SmbcFileWrapper(object):
    def __init__(self, obj):
        self.obj = obj
    def __getattr__(self, name):
        return getattr(self.obj, name)
    def flush(self):
        pass
    def tell(self):
        return self.obj.seek(0, os.SEEK_CUR)
    def read(self, length=0):
        if length == 0:
            length = self.obj.fstat()[6]-self.tell()
        return self.obj.read(length)