Skip to content

[Feature] Support mozLz4 (de)compression, as used by Firefox #185

@EmperorArthur

Description

@EmperorArthur

Issue

Firefox compresses many files in a simple format, which is not recognized or supported by applications. It would be nice if 7z detected this file format, and supported compression/decompression.

If LZ4 compression is already supported by other file formats, the implementation boils down to detecting the header and using the existing code.

For example, Firefox the profile folder stores details about the current and previous session in "<profile_folder>/sessionstore-backups/<file_name>.jsonlz4".

File format Details

The file format is simply a magic header, the uncompressed file size, and raw LZ4 block data.

Start Content Description
0 b"mozLz40\x00" Magic file header
8 signed int_32 Uncompressed file size
12 Compressed LZ4 Data

Example Python Code

This leverages the existing lz4 Python library.

from lz4.block import compress as _lz4_compress, decompress as _lz4_decompress

_MAGIC_START = b"mozLz40\x00"
def is_mozlz4(data):
  return len(data) > 12 and data[0:8] == _MAGIC_START
def decompress(data):
  return _lz4_decompress(data[8:])
def compress(data):
  return _MAGIC_START + _lz4_compress(data)

Example files

Here is the exact same file both in "raw" format, and compressed. To comply with GitHub upload requirements, the "jsonlz4" file has also had GZip compression applied.

empty_object.json
empty_object.jsonlz4.gz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions