How to pack arbitrary bit sequence in Python?

后端 未结 3 2133
南笙
南笙 2021-01-06 06:56

I want to encode/compress some binary image data as a sequence if bits. (This sequence will, in general, have a length that does not fit neatly in a whole number of standar

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-06 07:16

    have you tried simply compressing the whole sequence with bz2? If the sequence is long you should use the bz2.BZ2Compressor to allow chunked processing, otherwise use bz2.compress on the whole thing. The compression will probably not be ideal but will typically get very close when dealing with sparse data.

    hope that helps.

提交回复
热议问题