-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CRC check failed when reading after seeking #73
Comments
I took a quick look at the source and documentation and it seems that backward seeking is supposed to be implemented by reopening the file. Somehow that reopen isn't effective enough. My workaround, which also simply reopens the file, works without problems: class RawFileInsideRar(io.RawIOBase):
def __init__(self, reopen, file_size):
self.reopen = reopen
self.fileobj = reopen()
self.file_size = file_size
def __enter__(self):
return self
def __exit__(self, exception_type, exception_value, exception_traceback):
self.close()
def close(self) -> None:
self.fileobj.close()
def fileno(self) -> int:
# This is a virtual Python level file object and therefore does not have a valid OS file descriptor!
raise io.UnsupportedOperation()
def seekable(self) -> bool:
return self.fileobj.seekable()
def readable(self) -> bool:
return self.fileobj.readable()
def writable(self) -> bool:
return False
def read(self, size: int = -1) -> bytes:
return self.fileobj.read(size)
def seek(self, offset: int, whence: int = io.SEEK_SET) -> int:
if whence == io.SEEK_CUR:
offset += self.tell()
elif whence == io.SEEK_END:
offset += self.file_size
if offset >= self.tell():
return self.fileobj.seek(offset, io.SEEK_SET)
self.fileobj = self.reopen()
return self.fileobj.seek(offset, io.SEEK_SET)
def tell(self) -> int:
return self.fileobj.tell() Replacing the info = rar.getinfo("bar")
file = RawFileInsideRar(lambda: rar.open(info), info.file_size) |
Thanks for the report! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
System Information:
Both, unar and unrar are in my
PATH
, so I don't know which is used. I think I don't have bsdtar installed.Steps to reproduce:
echo foo > bar && rar a bar.rar bar
Forward seeking does not seem to be a problem. This works:
However, as soon as I am seeking backwards, the problem arises even when using
crc_check=False
, which makes it even weirder!The text was updated successfully, but these errors were encountered: