Найти - Пользователи
Полная версия: Помощь по zlib
Начало » Python для новичков » Помощь по zlib
1
editkukum
Есть файл с расширением .res и он упакован zlib'ом. Вопрос: как его распаковать?
Slow
https://docs.python.org/3/library/zlib.html
Что ж за идиотские вопросы то?..
editkukum
Slow
https://docs.python.org/3/library/zlib.htmlЧто ж за идиотские вопросы то?..
Я пытаюсь это использовать, но выдаёт исключение:
 Traceback (most recent call last):
  File "C:/Users/Аня/AppData/Local/Programs/Python/Python36-32/Script1.py", line 5, in <module>
    file = zlib.decompress(file)
zlib.error: Error -3 while decompressing data: incorrect header check 
Slow
потому что, судя по ошибке, у вас не zlib, а deflate или gzip

вообще, ответ гуглится довольно быстро -
https://stackoverflow.com/questions/3122145/zlib-error-error-3-while-decompressing-incorrect-header-check
и там английским по белому написано, как с этой ошибкой бороться:

You have this error:

zlib.error: Error -3 while decompressing: incorrect header check
Which is most likely because you are trying to check headers that are not there, e.g. your data follows RFC 1951 (deflate compressed format) rather than RFC 1950 (zlib compressed format) or RFC 1952 (gzip compressed format).

choosing windowBits

But zlib can decompress all those formats:

to (de-)compress deflate format, use wbits = -zlib.MAX_WBITS
to (de-)compress zlib format, use wbits = zlib.MAX_WBITS
to (de-)compress gzip format, use wbits = zlib.MAX_WBITS | 16
See documentation in http://www.zlib.net/manual.html#Advanced (section inflateInit2)
automatic header detection (zlib or gzip)

adding 32 to windowBits will trigger header detection

>>> zlib.decompress(gzip_data, zlib.MAX_WBITS|32)
'test'
>>> zlib.decompress(zlib_data, zlib.MAX_WBITS|32)
'test'
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB