douliu3831 2016-08-07 21:52
浏览 181

使用python解压缩php zlib或bz2

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类