Bzip2 è un nuovo algoritmo per la compressione dei dati. Generalmente crea file che sono il 60-70% della dimensione dei corrispondenti ottenuti usando gzip.
Per mezzo di questo documento potrai utilizzare alcune applicazioni comuni con bzip2.
Per traduzione in francese puoi far riferimeno a documento di Arnaud Launay. Una versione web si trova qui, oppure puoi usare ftp qui Arnaud può essere contattato via posta elettronica a questo indirizzo
Per traduzione in giapponese puoi far riferimento qui ai documenti di Tetsu Isaji. Isaji può essere contattato tramite la sua home page, oppure via posta elettronica a questo indirizzo.
Modificato anche lesspipe.sh secondo i sui suggerimenti. Adesso dovrebbe funzionare meglio.
(Su suo consiglio, corretta anche la patch jka-compr.el per emacs. Oops! Bzip2 non ha ancora(?) un'opzione "append".)
L'home page di Bzip2 si trova presso l' home site UK. Il sito mirror negli STATI UNITI è qui. Puoi anche trovarlo sul sito della Red Hat qui.
Vedi gli home site. I binari per Intel della Red Hat si trovano qui. Per la Debian sono qui, e qui per la Slackware. Puoi prenderlo negli analogi posti presso i vari siti mirror.
Sono reperibili dal sito ufficiale (vedi Ottenere Bzip2), oppure qui presso Red Hat.
Se hai gcc 2.7.2.3, cambia la linea
CFLAGS = -O3 -fomit-frame-pointer -funroll-loops
in
CFLAGS = -fomit-frame-pointer -funroll-loops
ovvero, togli la parte -O3. Dopo di che semplicemente lancia
make e installalo come spiegato nel README.
Leggi la raffinata pagina del manuale :)
Di base, ci sono due modi di usarlo, chiamiamoli
questo metodo non richiede un setup generale. Per un-tarare un archivo tar bzip2, foo.tar.bz2, nella corrente directory, fai
/percorso/per/bzip2 -cd foo.tar.bz2 | tar xf -
Questo metodo funziona, ma può essere un po' noioso da scrivere spesso.
Applica la seguente patch a gnu tar 1.12, compilalo, ed installalo, e sei pronto per partire. Assicurati che tar and bzip2 si trovino nel tuo $PATH con "which tar" e "which bzip2". Per usarlo, semplicemente usa
 tar xyf foo.tar.bz2
Per creare un nuovo archivio, analogamnte:
 tar cyf foo.tar.bz2 file1 file2 file3...directory1 directory2...
E questa è la patch :)
*** tar.c.orig  Sat Apr 26 05:09:49 1997
--- tar.c       Feb  2 00:50:47 1998
***************
*** 16,21 ****
--- 16,24 ----
     with this program; if not, write to the Free Software Foundation, Inc.,
     59 Place - Suite 330, Boston, MA 02111-1307, USA.  */
+ /* Feb 2 98: patched by David Fetter to use bzip2 as a
+              filter (option -y) */
+
  #include "system.h"
  #include <getopt.h>
***************
*** 196,201 ****
--- 199,206 ----
    {"block-number", no_argument, NULL, 'R'},
    {"block-size", required_argument, NULL, OBSOLETE_BLOCKING_FACTOR},
    {"blocking-factor", required_argument, NULL, 'b'},
+   {"bzip2", required_argument, NULL, 'y'},
+   {"bunzip2", required_argument, NULL, 'y'},
    {"catenate", no_argument, NULL, 'A'},
    {"checkpoint", no_argument, &checkpoint_option, 1},
    {"compare", no_argument, NULL, 'd'},
***************
*** 372,377 ****
--- 377,383 ----
                PATTERN                at list/extract time, a globbing PATTERN\n\
    -o, --old-archive, --portability   write a V7 format archive\n\
        --posix                        write a POSIX conformant archive\n\
+   -y, --bzip2, --bunzip2             filter the archive through bzip2\n\
    -z, --gzip, --ungzip               filter the archive through gzip\n\
    -Z, --compress, --uncompress       filter the archive through compress\n\
        --use-compress-program=PROG    filter through PROG (must accept -d)\n"),
***************
*** 448,454 ****
     Y  per-block gzip compression */
  #define OPTION_STRING \
!   "-01234567ABC:F:GK:L:MN:OPRST:UV:WX:Zb:cdf:g:hiklmoprstuvwxz"
  static void
  set_subcommand_option (enum subcommand subcommand)
--- 454,460 ----
     Y  per-block gzip compression */
  #define OPTION_STRING \
!   "-01234567ABC:F:GK:L:MN:OPRST:UV:WX:Zb:cdf:g:hiklmoprstuvwxyz"
  static void
  set_subcommand_option (enum subcommand subcommand)
***************
*** 805,810 ****
--- 811,820 ----
        case 'X':
        exclude_option = 1;
        add_exclude_file (optarg);
+       break;
+
+       case 'y':
+       set_use_compress_program_option ("bzip2");
        break;
        case 'z':
Per decomprimere i file bzip2 al volo, ad esempio usare "less" senza prima bunziparli, tu puoi fare un lesspipe.sh (man less) simile a questo:
#!/bin/sh
# This is a preprocessor for 'less'.  It is used when this environment
# 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 ;;
# This one work for the unmodified version of tar:
  *.tar.bz2) bzip2 -cd $1 $1 2>/dev/null | tar tzvvf - ;;
#This one works with the patched version of tar:
# *.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 ;;
#  *) FILE=`file -L $1` ; # Check to see if binary, if so -- view with 'strings'
#    FILE1=`echo $FILE | cut -d ' ' -f 2`
#    FILE2=`echo $FILE | cut -d ' ' -f 3`
#    if [ "$FILE1" = "Linux/i386" -o "$FILE2" = "Linux/i386" \
#         -o "$FILE1" = "ELF" -o "$FILE2" = "ELF" ]; then
#      strings $1
#    fi ;;
  esac
Ho scritto la seguente patch per jka-compr.el la quale aggiunge bzip2 ad auto-compression-mode.
Disclaimer: Io l'ho solo testato con emacs-20.2, ma non c'è nessuna ragione per credere che un simile approccio non funzioni con altre versioni.
Come usarlo
 patch < jka-compr.el.diff
 M-x byte-compile-file jka-compr.el
--- 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
   ;;[regexp
   ;; compr-message  compr-prog  compr-args
@@ -131,6 +133,10 @@
      "compressing"    "compress"     ("-c")
      "uncompressing"  "uncompress"   ("-c")
      nil t]
+    ["\\.bz2\\'"
+     "bzip2ing"        "bzip2"         ("")
+     "bunzip2ing"      "bzip2"         ("-d")
+     nil t]
     ["\\.tgz\\'"
      "zipping"        "gzip"         ("-c" "-q")
      "unzipping"      "gzip"         ("-c" "-q" "-d")
Un ringraziamento per questa cosa va a Ulrik Dickow, ukd@kampsax.dk, Programmatore di Sistema presso Kampsax Technology:
Per fare in modo di usare bzip2 autmaticamente, senza essere un sysadmin, aggiungi ciò che segue nel tuo file .emacs.
;; Automatic (un)compression on loading/saving files (gzip(1) and similar)
;; We start it in the off state, so that bzip2(1) support can be added.
;; Code thrown together by Ulrik Dickow for ~/.emacs with Emacs 19.34.
;; Should work with many older and newer Emacsen too.  No warranty though.
;;
(if (fboundp 'auto-compression-mode) ; Emacs 19.30+
    (auto-compression-mode 0)
  (require 'jka-compr)
  (toggle-auto-compression 0))
;; Now add bzip2 support and turn auto compression back on.
(add-to-list 'jka-compr-compression-info-list
             ["\\.bz2\\(~\\|\\.~[0-9]+~\\)?\\'"
              "zipping"        "bzip2"         ()
              "unzipping"      "bzip2"         ("-d")
              nil t])
(toggle-auto-compression 1 t)
Ringrazio Arnaud Launay per questo salva banda. Ciò che segue va in /etc/ftpconversions per comprimere e decomprimere con bzip2 al volo. Assicurati che i percorsi (simile a /bin/compress) siano giusti.
:.Z: : :/bin/compress -d -c %s:T_REG|T_ASCII:O_UNCOMPRESS:UNCOMPRESS : : :.Z:/bin/compress -c %s:T_REG:O_COMPRESS:COMPRESS :.gz: : :/bin/gzip -cd %s:T_REG|T_ASCII:O_UNCOMPRESS:GUNZIP : : :.gz:/bin/gzip -9 -c %s:T_REG:O_COMPRESS:GZIP :.bz2: : :/bin/bzip2 -cd %s:T_REG|T_ASCII:O_UNCOMPRESS:BUNZIP2 : : :.bz2:/bin/bzip2 -9 -c %s:T_REG:O_COMPRESS:BZIP2 : : :.tar:/bin/tar -c -f - %s:T_REG|T_DIR:O_TAR:TAR : : :.tar.Z:/bin/tar -c -Z -f - %s:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+COMPRESS : : :.tar.gz:/bin/tar -c -z -f - %s:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+GZIP : : :.tar.bz2:/bin/tar -c -I -f - %s:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+BZIP2
tenthumbs@cybernex.net dice:
Ho trovato un modo di far usare bzip2 al Netscape per Linux per
Content-Encoding nello stesso modo con cui usa gzip. Aggiungi quanto
segue a $HOME/.Xdefaults oppure $HOME/.Xresources
Io uso l opzione -s poiché preferisco sacrificare un po' di velocità
di decompressione piuttosto che l'utilizzo di memoria RAM. Puoi
togliere questa opzione se non ne hai bisogno. 
Netscape*encodingFilters:      \
        x-compress :  : .Z     : uncompress -c  \n\
        compress   :  : .Z     : uncompress -c  \n\
        x-gzip     :  : .z,.gz : gzip -cdq      \n\
        gzip       :  : .z,.gz : gzip -cdq      \n\
        x-bzip2    :  : .bz2   : bzip2 -ds \n
Sto lavorando ad una patch, in modo tale che xv autodecomprima i file bzip2 nello stesso modo con cui può decomprimere quelli di gzip. Nessuno vuole aiutarmi?