Penguin
Note: You are viewing an old revision of this page. View the current version.

Bzip2 mini-HOWTO

David Fetter,

david@fetter.org v2.00, 22 August 1999


1. Introduction

Bzip2 is a groovy new algorithm for compressing data. It generally makes files that are 60-70% of the size of their gzip'd counterparts.

This document will take you through a few common applications for bzip2.

Future versions of the document will have applications of libbzip2, the bzip2 C library which bzip2's author, Julian Seward has kindly written. The bzip2 manual, which includes low-level information about the library, can be found here: bzip2(1).

Future versions of the document may also include a summary of the discussion over whether (and how) bzip2 should be used in the Linux kernel.


2. Getting bzip2

Bzip2's home page is at http://sources.redhat.com/bzip2/.

2.2 Getting bzip2 precompiled binaries

See the home sites.

2.3 Getting bzip2 sources

They come from the Official sites (see Getting Bzip2 for where.

2.4 Compiling bzip2 for your machine

If you have gcc 2.7.*, change the line that reads

CFLAGS = -O3 -fomit-frame-pointer -funroll-loops

to

CFLAGS = -O2 -fomit-frame-pointer

that is, replace -O3 with -O2 and drop the -funroll-loops. You may also wish to add any -m* flags (like -m486, for example) you use when compiling kernels.

Avoiding -funroll-loops is the most important part, since this will cause many gcc 2.7's to generate wrong code, and all gcc 2.7's to generate slower and larger code. For other compilers (lcc, egcs, gcc 2.8.x) the default CFLAGS are fine.

After that, just make it and install it per the README.


3. Using bzip2 by itself

Read the Fine Manual Page :)


4. Using bzip2 with tar

Listed below are three ways to use bzip2 with tar, namely

4.1 Easiest to set up:

This method requires no setup at all. To un-tar the bzip2'd tar archive, foo.tar.bz2 in the current directory, do

/path/to/bzip2 -cd foo.tar.bz2 | tar xf -

or

tar --use-compress-prog=bzip2 xf foo.tar.bz2

These work, but can be a PITA to type often.

4.2 Easy to set up, fairly easy to use, no need for root privileges:

Thanks to Leonard Jean-Marc for the tip. Thanks also to Alessandro Rubini for differentiating bash from the csh's.

In your .bashrc, you can put in a line like this
alias btar='tar --use-compress-program /usr/local/bin/bzip2 '
In your .tcshrc, or .cshrc, the analogous line looks like this
alias btar 'tar --use-compress-program /usr/local/bin/bzip2'

4.3 Also easy to use, but needs root access.

Update your tar to GNU's newest version, which is currently 1.13.10. It can be found at GNU's ftp site or any mirror.


5. Using bzip2 with less

To uncompress bzip2'd files on the fly, i.e. to be able to use "less" on them without first bunzip2'ing them, you can make a lesspipe.sh (man

less) like this
  1. /bin/sh

  2. This is a preprocessor for 'less'. It is used when this environment
  3. variable is set: LESSOPEN="|lesspipe.sh %s"

case "$1" in

  • .tar) tar tvvf $1 2>/dev/null ;; # View contents of various tar'd files
  • .tgz) tar tzvvf $1 2>/dev/null ;;
  1. This one work for the unmodified version of tar:

    • .tar.bz2) bzip2 -cd $1 $1 2>/dev/null | tar tvvf - ;;
  2. This one works with the patched version of tar:
  3. *.tar.bz2) tyvvf $1 2>/dev/null ;;

    • .tar.gz) tar tzvvf $1 2>/dev/null ;;
    • .tar.Z) tar tzvvf $1 2>/dev/null ;;
    • .tar.z) tar tzvvf $1 2>/dev/null ;;
    • .bz2) bzip2 -dc $1 2>/dev/null ;; # View compressed files correctly
    • .Z) gzip -dc $1 2>/dev/null ;;
    • .z) gzip -dc $1 2>/dev/null ;;
    • .gz) gzip -dc $1 2>/dev/null ;;
    • .zip) unzip -l $1 2>/dev/null ;;

    .1|.2|*.3|*.4|*.5|*.6|*.7|*.8|*.9|*.n|*.man) FILE=`file -L $1` ; # groff src

    FILE=`echo $FILE | cut -d ' ' -f 2` if [ "$FILE" = "troff"?; then

    groff -s -p -t -e -Tascii -mandoc $1

    fi ;;

    • ) cat $1 2>/dev/null ;;
  4. *) FILE=`file -L $1` ; # Check to see if binary, if so -- view with 'strings'
  5. FILE1=`echo $FILE | cut -d ' ' -f 2`
  6. FILE2=`echo $FILE | cut -d ' ' -f 3`
  7. if [[ "$FILE1" = "Linux/i386" -o "$FILE2" = "Linux/i386" \
  8. -o "$FILE1" = "ELF" -o "$FILE2" = "ELF" ]; then
  9. strings $1
  10. fi ;;

esac


6. Using bzip2 with emacs

6.1 Changing emacs for everyone:

I've written the following patch to jka-compr.el which adds bzip2 to auto-compression-mode.

Disclaimer: I have only tested this with emacs-20.2, but have no reason to believe that a similar approach won't work with other versions.

To use it,

  1. Go to the emacs-20.2/lisp source directory (wherever you untarred it)
  2. Put the patch below in a file called jka-compr.el.diff (it should

be alone in that file ;).

  1. Do

patch < jka-compr.el.diff #

  1. Start emacs, and do

M-x byte-compile-file jka-compr.el #

  1. Leave emacs.

#

  1. Move your original jka-compr.elc to a safe place in case of bugs.

#

  1. Replace it with the new jka-compr.elc.

#

  1. Have fun!

#

--- jka-compr.el Sat Jul 26 17:02:39 1997

  • ++ jka-compr.el.new Thu Feb 5 17:44:35 1998

@@ -44,7 +44,7 @@ ;; The variable, jka-compr-compression-info-list can be used to ;; customize jka-compr to work with other compression programs. ;; The default value of this variable allows jka-compr to work with

  • ;; Unix compress and gzip.
  • ;; Unix compress and gzip. David Fetter added bzip2 support :)

;; ;; If you are concerned about the stderr output of gzip and other ;; compression/decompression programs showing up in your buffers, you @@ -121,7 +121,9 @@ ;;; I have this defined so that .Z files are assumed to be in unix

  • ;;; compress format; and .gz files, in gzip format.
  • ;;; compress format; and .gz files, in gzip format, and .bz2 files,
  • ;;; in the snappy new bzip2 format from http://www.muraroa.demon.co.uk.
  • ;;; Keep up the good work, people!

(defcustom jka-compr-compression-info-list ;;

Fatal Error:

lib/CachedMarkup.php (In template 'browse' < 'body' < 'html'):257: Error: Pure virtual

lib/InlineParser.php:336: Warning: Invalid [] syntax ignored: [[regexp

  • ;; compr-message compr-prog compr-args
  • @@ -131,6 +133,10 @@
  • "compressing" "compress" ("-c")
  • "uncompressing" "uncompress" ("-c")
  • nil t]

lib/BlockParser.php:505: Notice: Undefined property: _tight_top



Fatal PhpWiki Error

lib/CachedMarkup.php (In template 'browse' < 'body' < 'html'):257: Error: Pure virtual