如何以plist或zip格式读取和写入二进制数据?

问题描述 投票:0回答:1

f.pk基本上是base64 + zip的容器,我需要将其导入Python并提取。压缩文件是p.plist,因此f.pk = path + name + datap.plist

我找不到open()codecs.open()的任何有效编码,无法将其作为str打开并保存输出。我总是生成一个与原始文件不同的output.plist

我已经使用的编码包括ASCII; UTF-x;拉丁语_1; ISO-x;

import codecs, os

with open('f.pk', 'r', encoding='Latin_1') as f:
    f_open = f.read()

with codecs.open('f.pk', 'r', encoding='zip') as f:
    f_open = f.read()

f2=f_open[3:] #SKIP DUMMY PART
f3=f2.split('-DATA-')
f4=f3[1].split('-COMMENT-')

with open('output.plist', 'w') as f:
    print(f_out, file=f)

original.plist = 5e03964972def5b83880397b7377e6d1aea33e2boutput.plist = 6473aea0ae8bc75a04859effe1ee366de4cdd2d2

我已经对两个文件进行了深入分析:both files没有成功。

python encoding binary plist
1个回答
0
投票
with open('file.pk', 'rb') as f:
    f_open = f.read()

# do something with bytes here

with open('p.temp', 'wb') as f:
    pickle.dump(f_bytes, f) # temp file

# reload temp file
with open("p.temp", 'rb') as f:
    data = f.read()

# skip encodings and skip unwanted bytes
data = data[4:-3]

# save it
with open('p.plist', 'wb') as f:
    f.write(data)

os.remove('p.temp')
© www.soinside.com 2019 - 2024. All rights reserved.