Convert BZ2 to GZ

Converting BZ2 to GZ trades a little size for a great deal of speed. Bzip2 gets its ratio from a Burrows–Wheeler transform over blocks of up to 900 KB, and undoing that transform is genuinely expensive work, while gzip’s 32 KB back-references unpack at close to memory speed. The result is a slightly larger file that opens far more quickly and on far more machines.

  • Where it runs On our server, because a browser cannot run the software this needs.
  • Lossless Nothing is discarded. The GZ holds exactly what the BZ2 held.
  • File size limit Up to 25 MB per file, free, without an account.
  • Worth knowing The files come out byte for byte. What does not survive is anything the container held about them rather than in them — a password, and on some formats the original permissions and timestamps.

Up to 100 files at once. Mixed formats are fine.

The bzip2 archive that is still in a pipeline nobody rewrote

Bzip2 had a good decade. Between roughly 1998 and 2010 it was the obvious answer when gzip was not compressing enough, and a great deal of what was published in that window is still `.tar.bz2`: reference datasets, corpora, kernel and source tarballs, scientific data deposits, the fixture that a test suite has downloaded on every run since before anyone currently on the team joined.

The archive is not the problem. The problem is that something unpacks it on a schedule, and bzip2 decompression is slow enough to be visible in a build log. Nobody is going to re-cut the upstream release, so the practical move is to recompress locally into something that opens quickly and cache that instead. That is a different reader from the one converting for storage, and it points at a different answer: gzip, not XZ.

Why undoing a block sort costs so much more than following a back-reference

The two formats decompress in structurally different ways and the gap is not a matter of implementation quality. Gzip’s output is built by copying literal bytes and copying earlier runs from a 32 KB window — the inner loop is essentially memory movement, and modern hardware is extremely good at it.

Bzip2 has to invert a Burrows–Wheeler transform for every block of up to 900 KB. That means reconstructing the original ordering from a sorted permutation, which is a scattered, cache-unfriendly pass over the whole block before a single output byte of it is final, plus undoing the move-to-front and Huffman layers around it. It is real computation rather than data movement, and no amount of tuning turns it into memory speed. On an archive of any size the difference is minutes against seconds.

The size you give back, and when it is nothing at all

Expect the GZ to be larger, and expect the margin to depend entirely on the contents. Bzip2 sees up to 900 KB of context at a time where gzip sees 32 KB, so on prose, logs, CSV, source code and XML it finds repetition gzip cannot reach and the gap is real. The registry records exactly those two numbers, and they are the whole explanation.

On other contents there is no gap worth measuring. A bzip2 archive of JPEGs, PNGs, MP3s, MP4s or an already-compressed database file is barely compressed to begin with — the redundancy was removed by those formats before the archiving started — so recompressing it as gzip costs almost nothing and buys the full speed benefit. If that describes your archive, this conversion is close to free and there is nothing to weigh.

The nameless stream, and a bug it caused in this converter

A gzip stream stores the original file name in its header. A bzip2 stream stores nothing of the sort — no name, no path, no hint about what it holds. That asymmetry is normally a curiosity and it produced a genuine defect here, which is recorded in the converter’s source.

The repack has to unwrap the TAR that sits inside a compressed archive, and the first version of the code decided whether it had found one by looking at the file name. From a GZ that worked, because gzip had remembered `output.tar`. From a BZ2 or an XZ the same tarball arrived called `input`, the check missed it, and the conversion produced an archive containing one opaque file instead of the thirty that went in — a success that returned the wrong thing. The fix was to force the tar type rather than infer it, which is why a bzip2 source is handled correctly today.

Gzip is in places bzip2 never reached

Ubiquity is the second half of this conversion’s argument and it is easy to underrate. DEFLATE is the compression inside HTTP `Content-Encoding: gzip`, inside PNG, inside a ZIP file and inside a Git object. Every mainstream language has it in its standard library — Python’s `gzip`, Go’s `compress/gzip`, Java’s `GZIPInputStream`, Node’s `zlib` — with no dependency to add and no licence question to answer.

Bzip2 is a separate library that has to be present, and in a minimal container, a locked-down runtime, a browser or a cloud function it often is not. Gzip is a registered HTTP content coding and bzip2 never was, so every HTTP client already decompresses one and none of them decompresses the other. If the archive is going to be read by code rather than by a person at a shell, gzip removes a dependency as well as a delay.

The blocks bzip2 could recover, and what you lose by leaving

It is worth naming what you are giving up rather than only what you gain. Bzip2 compresses each block independently, so damage to one block does not automatically destroy everything after it, and recovery tools can walk a corrupted file and salvage the intact blocks. A gzip stream has no such structure — a flipped bit part way through generally ends the archive there.

How much that matters depends on where the file lives. On a modern filesystem with checksums, on object storage that verifies what it returns, or anywhere with a second copy, it matters very little. On a single ageing disk holding the only copy of something irreplaceable, it matters more — and in that case the right answer is neither format but a real backup with per-file integrity data. Recovery-friendliness is a poor substitute for redundancy.

When to jump to XZ instead of stepping across to gzip

If the archive is being kept rather than read, gzip is the wrong destination and XZ is the right one — it will compress the same contents considerably better than bzip2 did and still decompress faster. The reader on this page is not that person, but plenty of people converting a bzip2 archive are, and it is worth being told so.

The test is simple: count how often the archive is unpacked. Frequently, by machines, in a step somebody is waiting on — gzip. Rarely, by a person, from a bucket that charges by the gigabyte-month — XZ. The only case where bzip2 should stay is a machine with very little memory, because bzip2’s fixed 900 KB blocks need almost nothing to unpack where XZ needs a buffer scaled to its dictionary.

Where the bzip2 archive is decompressed on the way to gzip

On our server rather than on your device. Most tools on this site convert locally and say so; archives are one of the exceptions, because the work needs 7-Zip and gzip as real programs. The file travels over an encrypted connection to a container that runs them and that has no outbound internet access of its own.

The job gets a scratch directory on a memory-backed filesystem, deleted the moment the job ends whether or not it succeeded, and it is killed after sixty seconds — which on this pair is a real constraint, since bzip2 is slow to decompress and a large archive of text is exactly the input that takes its time. The free tier accepts 25 MB per uploaded file, and before anything is extracted the archive is asked what it claims to expand to, with a declared total above 2 GB refused outright.

Timing the extraction before and after, and keeping the original

This conversion is worth doing only if the numbers say so, and getting them is a two-minute job: time the extraction of the bzip2 archive, time the extraction of the gzipped one, and put the two file sizes beside them. If the archive is small or the pipeline unpacks it once a month, the saving is noise and the change is not worth the churn of updating whatever points at the file.

Keep the bzip2 original until something has actually consumed the new file successfully. Not because the conversion is lossy — it is not, every member comes out byte for byte — but because the tarball is rebuilt rather than passed through, so member order, timestamps and permission bits can shift, and a build that depended on one of those fails in a way that looks nothing like an archive problem. Compare `tar tjf` on the source with `tar tzf` on the result first, and retire the original once they agree.

How to recompress a bzip2 archive as GZ

  1. Drop the BZ2 or .tar.bz2 file onto this page, or click to choose one.
  2. It is decompressed, re-tarred and compressed with gzip on our server.
  3. Time both extractions, compare the listings, then point your pipeline at the GZ.

BZ2 and GZ: block sorting against a sliding window

BZ2 compared with GZ
BZ2GZ
Full nameBzip2 ArchiveGzip Archive
File extension.bz2.gz, .tgz
Media typeapplication/x-bzip2application/gzip
CompressionLossless — nothing is discardedLossless — nothing is discarded
First published19961992
SpecificationRFC 1952
LicensingOpen standardOpen standard
Standing todayLegacy, still read everywhereCurrent
Opens in a browserNo browserNo browser
Considered insteadXZXZ, ZIP

What survives

Nothing is discarded. BZ2 and GZ both store their content losslessly, so the conversion is a change of packaging rather than a change of quality, and it can be repeated without accumulating damage.

Opening the result

BZ2 dates from 1996 and is largely superseded. GZ is what current software writes, so the conversion is as much about staying readable as about the file itself.

7-Zip and Keka read both BZ2 and GZ, so there is a way to check the result against the original without a second tool.

File size and quality

GZ works over 32 KB at a time against BZ2's 900 KB — that is the span a repetition has to fall inside before it can be compressed away. It is where the difference in ratio comes from, and why it is the faster of the two.

What each format is for

GZ dates from 1992, specified as RFC 1952. gzip, 7-Zip and Keka all read it.

BZ2 to GZ: speed, size and the archives that are still bzip2

Are my BZ2 files uploaded anywhere?

Yes — this conversion needs software that cannot run in a browser, so the file is uploaded over an encrypted connection. It is deleted as soon as the job finishes, and the result is sent straight back to you without being stored. The work is done by 7-Zip, the archiver, in its command-line form.

Will the GZ be larger than the BZ2?

On text, usually yes, and typically by a noticeable margin — bzip2 sorts blocks of up to 900 KB while gzip looks back only 32 KB. On a bzip2 archive holding images, video or already-compressed data the two land within a rounding error of each other, because neither compressor had anything to find in the first place.

How much faster is gzip to unpack?

Substantially, and it is a structural difference rather than a tuning one. Undoing bzip2’s Burrows–Wheeler transform is real computation; undoing gzip’s back-references is close to a memory copy. On an archive that is fetched and extracted on every build, that gap is the entire reason to do this conversion.

Is bzip2 actually obsolete?

The registry marks it legacy, which is fair. XZ compresses better and decompresses faster; gzip decompresses far faster still and is installed everywhere. Bzip2 keeps one genuine advantage — it needs very little memory to unpack — so it survives on small devices and in recipes that name it.

Do I get a .gz or a .tar.gz back?

A file ending `.gz` whose contents are a TAR, which is what `.tar.gz` means. Neither format can hold more than one stream, so the members are collected into a tarball before compression. Rename the download to end `.tar.gz` and `tar xzf` will handle both layers in one command.

Is anything inside the archive altered?

No. Both formats are lossless, so every file comes out byte for byte. What may not survive is what the container recorded about the files rather than in them — permissions and timestamps — because the tarball is rebuilt from the extracted contents rather than passed through untouched.

How large a bzip2 archive can I upload?

25 MB on the free tier, because this pair runs on our server rather than in your browser. It is also refused before extraction if it declares that it unpacks to more than 2 GB, and a well-compressed bzip2 archive of text can genuinely make that claim.

More about these formats