{
  "schemaVersion": 1,
  "contentVersion": "ca42e61ede0a24f789d7287a0001244ad22f4abf",
  "id": "docs/codecs/data/bzip2",
  "collection": "docs",
  "title": "bzip2",
  "description": "bzip2 is a block-sorting compressor that beats gzip on ratio but is slow and has been overtaken by xz and zstd; you mostly meet it in old .tar.bz2 files.",
  "canonicalUrl": "https://encode.wiki/codecs/data/bzip2/",
  "apiUrl": "https://encode.wiki/api/v1/documents/docs/codecs/data/bzip2.json",
  "markdownUrl": "https://encode.wiki/api/v1/markdown/docs/codecs/data/bzip2.md",
  "status": "current",
  "tags": [
    "migrated"
  ],
  "license": "CC BY-SA 4.0",
  "dates": {
    "lastVerified": "2026-10-08T00:00:00.000Z"
  },
  "authors": [],
  "sources": [
    {
      "title": "bzip2 and libbzip2 manual",
      "url": "https://sourceware.org/bzip2/manual/manual.html",
      "accessedAt": "2026-10-08T00:00:00.000Z"
    },
    {
      "title": "bzip2 home page",
      "url": "https://sourceware.org/bzip2/",
      "accessedAt": "2026-10-08T00:00:00.000Z"
    }
  ],
  "provenance": {
    "originUrl": "https://github.com/av1-community-contributors/codec-wiki/blob/37c3317fd058b23c71a87679bed5619a98f77752/docs/data/bzip2.mdx",
    "originCommit": "37c3317fd058b23c71a87679bed5619a98f77752",
    "migratedAt": "2026-08-21T00:00:00.000Z",
    "modified": true,
    "originPath": "docs/data/bzip2.mdx"
  },
  "headings": [
    {
      "depth": 2,
      "text": "Common commands",
      "anchor": "common-commands"
    },
    {
      "depth": 2,
      "text": "Archives and parallelism",
      "anchor": "archives-and-parallelism"
    },
    {
      "depth": 2,
      "text": "Pitfalls",
      "anchor": "pitfalls"
    }
  ],
  "sections": [
    {
      "id": "_preamble",
      "title": "Page introduction",
      "depth": 0,
      "canonicalUrl": "https://encode.wiki/codecs/data/bzip2/",
      "apiUrl": "https://encode.wiki/api/v1/sections/docs/codecs/data/bzip2/_preamble.json",
      "markdownUrl": "https://encode.wiki/api/v1/sections/docs/codecs/data/bzip2/_preamble.md",
      "checksum": "6a5f68745263de93d3d280bd8079166e9c1a2dbabba9fca85ca417575bd5c044",
      "bytes": 468
    },
    {
      "id": "common-commands",
      "title": "Common commands",
      "depth": 2,
      "anchor": "common-commands",
      "canonicalUrl": "https://encode.wiki/codecs/data/bzip2/#common-commands",
      "apiUrl": "https://encode.wiki/api/v1/sections/docs/codecs/data/bzip2/common-commands.json",
      "markdownUrl": "https://encode.wiki/api/v1/sections/docs/codecs/data/bzip2/common-commands.md",
      "checksum": "203e022fe49b35969bc89ec7e3c47b991234f6c324f8f4bf7ed8ca534e98f8c8",
      "bytes": 621
    },
    {
      "id": "archives-and-parallelism",
      "title": "Archives and parallelism",
      "depth": 2,
      "anchor": "archives-and-parallelism",
      "canonicalUrl": "https://encode.wiki/codecs/data/bzip2/#archives-and-parallelism",
      "apiUrl": "https://encode.wiki/api/v1/sections/docs/codecs/data/bzip2/archives-and-parallelism.json",
      "markdownUrl": "https://encode.wiki/api/v1/sections/docs/codecs/data/bzip2/archives-and-parallelism.md",
      "checksum": "6c890043a0709342defba78f9eb97f39ae969f737dba813eee5a08f4605378ec",
      "bytes": 353
    },
    {
      "id": "pitfalls",
      "title": "Pitfalls",
      "depth": 2,
      "anchor": "pitfalls",
      "canonicalUrl": "https://encode.wiki/codecs/data/bzip2/#pitfalls",
      "apiUrl": "https://encode.wiki/api/v1/sections/docs/codecs/data/bzip2/pitfalls.json",
      "markdownUrl": "https://encode.wiki/api/v1/sections/docs/codecs/data/bzip2/pitfalls.md",
      "checksum": "7148997b629f7b30bed3b78376d54697de77a4b7bef2956061c277eaf11bbe90",
      "bytes": 407
    }
  ],
  "outboundReferences": [
    "/codecs/data/gzip/",
    "/codecs/data/tar/",
    "/codecs/data/xz/",
    "/codecs/data/zstd/"
  ],
  "checksum": "625f9d783511d8ba7a82f7d95c83dafe8fcb3d52f800f69f823b10abe2e1fa22",
  "contentFormat": "markdown",
  "markdown": "bzip2, by Julian Seward, compresses with the Burrows–Wheeler transform in independent blocks of 100–900 kB. It beats [gzip](/codecs/data/gzip/) on ratio, particularly for text, but is slow in both directions, single-threaded, and is outperformed on speed, and usually on ratio, by [xz](/codecs/data/xz/) and [zstd](/codecs/data/zstd/). Today it is mainly something you decompress: old source tarballs (`.tar.bz2`) and some datasets. For new files, use zstd or xz.\n\n## Common commands\n\n```sh\nbzip2 -k file              # file.bz2, 900k blocks, keep the original\nbzip2 -1 file              # 100k blocks: faster, less memory, worse ratio\nbzip2 -d file.bz2          # decompress (or bunzip2); bzcat to stdout\nbzip2 -t file.bz2          # test integrity\n```\n\nbzip2 **deletes** the input unless you pass `-k`. The `-1` … `-9` options set the block size to 100 kB … 900 kB; the default is `-9`, and smaller blocks only help when memory is limited. Compression at `-9` needs about 7.6 MB of memory and decompression about 3.7 MB (`-s` reduces it to at most 2.5 MB, at some cost in speed).\n\n## Archives and parallelism\n\n```sh\ntar -cjf backup.tar.bz2 dir/\ntar -xf backup.tar.bz2\n```\n\nThe reference `bzip2` uses a single thread. Because blocks are independent, parallel implementations such as `pbzip2` and `lbzip2` can speed it up and also decompress `.bz2` files in parallel. 7-Zip can also create bzip2 with multiple threads (`7z a -tbzip2`).\n\n## Pitfalls\n\n- **Block independence helps recovery.** Damage to one block loses only that block, and `bzip2recover` can extract the intact ones. gzip has no equivalent.\n- **Poor on binary or already-compressed data** and slower than modern alternatives; the gain over gzip rarely justifies the time.\n- **`.bz2` is a single stream,** not an archive. Combine it with [tar](/codecs/data/tar/) for directories.\n"
}
