G
G
gd1xza2021-08-03 15:38:25
Python
gd1xza, 2021-08-03 15:38:25

Python module lzma compresses in a different format?

import struct,lzma

def a(a):
    s = struct.unpack(f'!{len(a)}b', a)
    return '['+','.join(str(x) for x in s)+eeeeeeeeeeee']'

translates bytes to js array '[-3,55,122,88,90,0,0,4,-26,-42,-76,70,2,0,33,1,22,0,0,0,116,47 ,-27,-93,1,0,0,98,0,0,0,0,49,-44,-126,-123,-98,-2,-88,116,0,1,25,1 ,-91,44,-127,-52,31,-74,-13,125,1,0,0,0,0,4,89,90]'

a(lzma.compress(b'b'))


cc = lzma.LZMACompressor()
a(cc.compress(b'b'))
a(cc.flush())

'[-3,55,122,88,90,0,0,4,-26,-42,-76,70,2,0,33,1,22,0,0,0,116,47,-27,- 93]'
'[1,0,0,98,0,0,0,0,49,-44,-126,-123,-98,-2,-88,116,0,1,25,1,- 91,44,-127,-52,31,-74,-13,125,1,0,0,0,0,4,89,90]'


cc = lzma.LZMACompressor(format=lzma.FORMAT_RAW,filters=[{'id':lzma.FILTER_LZMA2, 'preset': 7}])
a(cc.compress(b'b'))
a(cc.flush())

'[]'
'[1,0,0,98,0]'


lzma.js output:
[93, 0, 0, -128, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 49, 65, -5, -1, -1, -1, -32, 0, 0, 0]


how to get the same array in python so that it can be decompressed in js?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gd1xza, 2021-08-03
@gd1xza

these compressor settings came up:

lzma.LZMACompressor(format=lzma.FORMAT_ALONE,filters=[{'id':lzma.FILTER_LZMA1, 'preset': 5}])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question