简体   繁体   中英

Python bz2 in c#

I got several strings like :

BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\...

After googling a whlke, found that those seems to be Python bz2 encoded strings, since "BZh91AY" appears to be a bz2 standard header.

Now I need to decode such strings. I've tried some components (SharpCompress and SharpZipLib) to attempt the decoding, but failed miserably.

Can someone point me towards a viable solution that doesn't involve python coding (I don't want to create a python's bz2 wrapper with IronPython)?

Thanks.

import bz2

un = b'BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M\x07<]\xc9\x14\xe1BA\x06\xbe\x084'

pw = b'BZh91AY&SY\x94$|\x0e\x00\x00\x00\x81\x00\x03$ \x00!\x9ah3M\x13<]\xc9\x14\xe1BBP\x91\xf08'

print(bz2.decompress(un).decode('utf-8'))
print(bz2.decompress(pw).decode('utf-8'))

# pw = 'huge'
# un = 'file'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM