bzip2
is a file format and a software application used for file compression and decompression that uses the Burrows–Wheeler algorithm.
bzip2
compresses most files more effectively than the older LZW (.Z) and Deflate (.zip and .gz) compression algorithms, but is considerably slower.
bzip2
compresses data in blocks of size between 100 and 900 kB and uses the Burrows–Wheeler transform to convert frequently-recurring character sequences into strings of identical letters. It then applies move-to-front transform and Huffman coding. bzip2
's ancestor bzip used arithmetic coding instead of Huffman.
1 Compress and uncompress a resource
Copy
<script> let file = new Ax.io.File("/tmp/sample.txt"); file.append(`Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua.`); var bzip2 = new Ax.util.zip.Bzip2(); var src = new Ax.io.File("/tmp/sample.txt"); var dst = new Ax.io.File("/tmp/sample.bz2"); var tmp = new Ax.io.File("/tmp/sample.txt"); dst.write(bzip2.compress(src)); console.log(src + " " + src.length() + " byte(s)"); console.log(dst + " " + dst.length() + " byte(s)"); tmp.write(bzip2.uncompress(dst)); dst.delete(); console.log(tmp + " " + tmp.length() + " byte(s)"); </script>
/etc/services 677972 byte(s)
/tmp/services.bz2 164677 byte(s)
/tmp/services.tmp 677972 byte(s)