0

I've already tried zlib_encode($data,15);, zlib_encode($data,31); and bzcompress($data,9); writing result into file. Everything looks good but I'm not able to decompress any of them with python. Bz2 gives me OSError: Invalid data stream, gzip gives me CRC check failed, zlib gives me Error -3: invalid literal/length. But when I'm trying bzopen() and bzwrite() I'm able to decompress file in python. The only problem that I have to open file to add new data at the end of file, but bzopen fully rewrites file. So am I able to decompress data compressed with php using python? My python version is 3.5

Some python code

import bz2
f=open('filename', 'rb') 
data = f.read()  # data now contains bytes
print(bz2.decompress(data)) 

That's all because I've tried to decompress file from python console

And some php code

<?php $data=$_POST['data'];
$fp = fopen('filename', 'a');
fwrite($fp, bzcompress($data, 9));
fclose($fp); ?>

Php code is running on the Linux system and I'm getting the file via ftp on my windows machine with python

desu
  • 455
  • 2
  • 18
  • .gz and .bz2 files have additionals magic bytes at the beginning of them. Have a look here: http://unix.stackexchange.com/questions/22834/how-to-uncompress-zlib-data-in-unix Also, do you have any sample code? The Python code you're using would be helpful as a starting point. – Carsten Aug 07 '16 at 22:08
  • @Carsten my python code just opens file like f = open('file', 'rb'), then data=f.read() and finally I'm trying to decompress data with zlib or gzip or bz2. Bz-magick bytes looks normal in bz2 coding, so I don't know what should I fix – desu Aug 07 '16 at 23:10
  • Please, give us a ([short, self-contained](http://sscce.org/)) example so I and others can reproduce the problem. This will make it 100x easier to find out what's wrong. – Carsten Aug 07 '16 at 23:17

0 Answers0