-
-
Save jdelisle/0d038ec255364fc2895950b61534b656 to your computer and use it in GitHub Desktop.
Convert from Mozilla's LZ4 format to LZ4 v1.3 (tested with FF51 profile & lz4 v1.7.5)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Convert from Mozilla's LZ4 format to LZ4 v1.3 | |
* | |
* @link https://dxr.mozilla.org/mozilla-central/source/toolkit/components/lz4/lz4.js | |
* @link https://github.com/lz4/lz4 | |
* @link https://github.com/lz4/lz4/blob/master/doc/lz4_Frame_format.md#legacy-frame | |
* | |
* @param string $input File content in Mozilla's LZ4 format | |
* @return string File content converted to LZ4 v1.3 | |
* | |
* @throws \RuntimeException If input data appears not to be of Mozilla's LZ4 format | |
*/ | |
function convert_lz4_header($input) { | |
$moz_header = substr($input, 0, 12); | |
$compressed_data = substr($input, 12); | |
if (substr($moz_header, 0, 8) !== "mozLz40\0") { | |
throw new \RuntimeException('Wrong magic number'); | |
} | |
$lz4_header = pack('V', 0x184C2102) // legacy frame magic number LZ4 v1.0-1.3, uint32_t little endian | |
. pack('V', strlen($compressed_data)); // size of compressed data (without header), uint32_t little endian | |
return $lz4_header . $compressed_data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can't decode the generator file with the current version of lz4 :/