  Bzip2 mini-HOWTO
  David Fetter, david@fetter.org <mailto:david@fetter.org>
  v2.00, 22 August 1999

  이 문서는 새로운 압축 프로그램 bzip2를 어떻게 사용하는지 이야기한다.
  현재의 사이트 <Bzip2-HOWTO.sgml>에 sgml의 로컬카피가 있고, 그리고
  "권위가 있는" sgml은 <http://fetter.org/Bzip2-HOWTO/>에 있다.
  ______________________________________________________________________

  차례


  1. 소개

     1.1 (BF
        1.1.1 v2.00
        1.1.2 v1.92
        1.1.3 v1.91
        1.1.4 v1.9
        1.1.5 v1.8
        1.1.6 v1.7
        1.1.7 v1.6
        1.1.8 v1.5
        1.1.9 v1.4
        1.1.10 v1.3
        1.1.11 v1.2
        1.1.12 v1.1
        1.1.13 v1.0

  2. Bzip2 얻기

     2.1 당신의 언어의 bzip2-HOWTO
     2.2 컴파일되지 않은 bzip2 바이너리 얻기
     2.3 Bzip2 소스 얻기
     2.4 당신의 컴퓨터로 bzip2 컴파일하기

  3. Bzip2를 그 것으로 사용하기

  4. Bzip2를 tar과 같이 쓰기

     4.1 설치하는 것은 가장 쉽다:
     4.2 설치하는 것과 적절하게 쓰는것은 쉽고, root의 특권이 필요하지 않다:
     4.3 쓰는것 또한 쉽다, 그러나 루트의 접근이 필요없다.

  5. Bzip2를 less와 같이 쓰기

  6. Bzip2를 emacs와 같이 쓰기

     6.1 모두를 위해 emacs를 바꾸기:
     6.2 한 사람을 위해 emacs를 바꾸기:

  7. Bzip2를 wu-ftpd와 같이 쓰기

  8. Bzip2를 grep와 같이 쓰기

  9. Bzip2를 X의 Netscape와 같이 쓰기.

  10. Bzip2로 다른 압축 형식으로 다시 압축하기

  ______________________________________________________________________

  1.  소개

  Bzip2는 자료를 압축하기 위한 좋은 새로운 알고리즘이다. 일반적으로 gzip
  의 크기의 60-70%로 파일을 만든다.


  이 문서는 당신을 bzip2를 통하여 일반 애플리케이션을 이용하게 만들 것이
  다.


  그 문서의 미래의 버전은 libbzip2의 애플리케이션, bzip2를 만든 Julian 
  Seward <mailto:Julian_Seward@muraroa.demon.co.uk> 가 친절히 쓴 bzip2 
  C 라이브러리가 있을 것이다. Bzip2 메뉴얼 <http://www.bzip2.org/bzip2
  /docs/manual_toc.html>에서 찾을 수 있는 라이브러리에 관한 낮은 수준의
  정보가 추가되었다.


  그 문서의 미래의 버전들은 아마 또한 bzip2를 리눅스 커널에서 써야하는지
  (그리고 어떻게)에 관한 해설에 대한 요약을 포함할 것이다.


  1.1.  개정판 역사

  1.1.1.  v2.00

  ``Bzip2를 less와 같이 사용하기'' 부문이 변경되었다 그래서 .tar.bzip2 
  파일을 실제로 읽을수 있다. 정정한 것에 대해 Nicola Fabiano <mailto:mc8
  644@mclink.it> 에게 감사한다.

  buzzit 유틸리티가 갱신되었다.

  tar 정보가 갱신되었다.


  1.1.2.  v1.92

  ``Bzip2 바이너리 얻기'' 부문이 변경되었고, S.u.S.E.의 추가한 것을 포함
  한다.


  1.1.3.  v1.91

  오타가 교정되었고 ``Bzip2를 tar과 같이 쓰는 부문''의 셸 표현형식의 일
  부를 깨끗하게 했다.  이 것들에 대해 Alessandro Rubini에게 감사한다.


  최초의 bzip2 데이터를 짓밟지 않기 위해 buzzit 툴을 갱신했다.


  Zgrep같은 툴인 bgrep가 추가되었다.


  1.1.4.  v1.9

  Gcc 2.7.* 문제를 깨끗하게 했다. 이것을 지적한 Ulrik Dickow에게 감사한
  다.



  Leonard Jean-Marc의 훌륭한 tar과 같이 사용하는 방법이 추가되었다.


  Linux Akerlund의 스웨덴 번역이 추가되었다.

  Arnaud Launay의 제안으로 wu-ftpd 부문을 고쳤다.


 번역들이 그들 자신의 부문으로 옮겨졌다.


  1.1.5.  v1.8

  Buzzit과 그것들이 속한곳의 sgml의 tar.diff를 넣었다. 구두점과 형식을
  수정했다.  Arnaud Launay에게 나의 복사를 정정한 그의 도움에 대해 감사
  한다. :-)


  대중의 관심의 부족으로 새로운 적당한 xv 프로젝트를 했다.


  그 문서의 미래의 버전을 위한 문제를 추가했다.


  1.1.6.  v1.7

  Buzzit 유틸리티가 추가되었다.  Gnu tar에 대한 패치를 고쳤다.


  1.1.7.  v1.6

  Added TenThumbs' Netscape enabler.


  또한 그의 제안으로 lesspipe.sh를 변경했다.  지금보다 훌륭하게 작동할
  것이다.


  1.1.8.  v1.5

  Arnaud Launay의 프랑스어 번역, 그리고 그의 wu-ftpd 파일이 추가되었다.


  1.1.9.  v1.4

  Tetsu Isaji의 일본 번역이 추가되었다.


  1.1.10.  v1.3

  Ulrik Dickow의 19.30와 더 높은 수준의 .emacs가 추가되었다.


  (또한 그의 제안으로 emacs의 jka-compr.el패치가 정정되었다. 이런!
  Bzip2의 기가 아직(?) 없군.)


  1.1.11.  v1.2

  Emacs의 패치가 변경되어서 자동적으로 .bz2 파일들을 인식한다.


  1.1.12.  v1.1

  Emacs의 패치가 추가되었다.


  1.1.13.  v1.0

  라운드 1.

  2.  Bzip2 얻기

  Bzip2의 홈페이지는 영국 홈 사이트 <http://www.bzip2.org/>.
  미국 미러사이트 <http://www.digistar.com/bzip2/index.html>.


  2.1.  당신의 언어의 bzip2-HOWTO

  프랑스인들은 아마 Arnaud Launay의 프랑스 문서를 참고하기를 바랄 것이다.
  웹 버전 <http://www.freenix.fr/linux/HOWTO/mini/Bzip2.html>, 그리고
  ftp <ftp://ftp.lip6.fr/pub/linux/french/docs/HOWTO/mini/Bzip2.gz>
  Arnaud와 전자메일로 연락할 수 있다. 메일 주소는 <mailto:zoro@mygale.org>


  일본인들은 아마 Tetsu Isaji의 일본 문서를 참조하기를 바랄 것이다.
  <http://jf.gee.kyoto-u.ac.jp/JF/JF.html>.  Isaji와 홈페이지 <http://ww
  w2s.biglobe.ne.jp/~kaien/>에서 연락할수 있고, 혹은 전자메일로 할수있다.
  <mailto:isaji@mxu.meshnet.or.jp>


  스웨덴인들은 아마 Linus Akerlund의 스웨덴 문서를 참조하기를 바랄 것이
  다 <http://user.tninet.se/~uxm165t/linux_doc.html>.  Linus와 전자메일
  로 연락할수 있다. <mailto:uxm165t@tninet.se>


  2.2.  컴파일되지 않은 bzip2 바이너리 얻기

  홈 사이트를 봐라.


  2.3.  bzip2 소스 얻기

  그것들은 공식적인 사이트로부터 왔다 (``Bzip2 얻기''를 봐라.


  2.4.  당신의 컴퓨터로 bzip2 컴파일하기

  만약 당신이 gcc 2.7.*을 가지고 있으면, 읽은 라인을 바꿔라


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

  으로


       CFLAGS = -O2 -fomit-frame-pointer

  -O3 과 -O2를 바꾸고 -funroll-loops를 넣는다. 커널 컴파일할때 당신은 아
  마 어떠한 -m* 플래그를(예를들어, -m486) 추가하길 원할 것이다.

  -funroll-loops를 피하는 것은 제일 중요한 부분이고, gcc 2.7의 잘못된 코
  드를 생성하는 많은 원인이 되고, gcc 2.7의 코드가 더 느리고 더 커지기
  때문이다.  다른 컴파일러들 (lcc, egcs, gcc 2.8.x)을 위해 디폴트 CFLAGS
  가 좋다.

  그 후, README대로 바로 그것을 만들고 설치해라.


  3.  Bzip2를 그 것으로 사용하기

  좋은 메뉴얼 페이지를 읽어봐라 :)


  4.  Bzip2를 tar과 같이 쓰기.

  바꾸어 말하면 bzip2를 tar과 같이 쓰는 세가지 방법이 밑에 리스트 된다.

  4.1.  설치하는것은 가장 쉽다:

  이 방법은 전혀 설치가 필요하지 않다.  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 -

  또는


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

  이 일, 그러나 but can be a PITA to type often.


  4.2.  설치하는 것은 쉽고, 적절하게 사용하는것은 쉽고, root의 특권이 필요하지 않다:

  팁에 대해 Leonard Jean-Marc <mailto:leonard@sct1.is.belgacom.be>에게
  감사한다.  csh와 bash 구별이 생기는 것에 대해 Alessandro Rubini
  <mailto:rubini@morgana.systemy.it> 에게 역시 감사한다.


  당신의 .bashrc, 이것과 같은 라인을 넣어라:


       alias btar='tar --use-compress-program /usr/local/bin/bzip2 '

  당신의 .tcshrc, 또는 .cshrc, 이것과 유사하게 보이는 라인:


       alias btar 'tar --use-compress-program /usr/local/bin/bzip2'

  4.3.  쓰는것 또한 쉽다, 그러나 루트의 접근이 필요없다.

  당신의 tar을 GNU의 가장 새로운 버전으로 갱신해라, 현재는 1.13.10이다.
  그것은 GNU의 ftp 사이트 <ftp://alpha.gnu.org/gnu/tar/>에서 찾을 수 있다 또한
  어떤 미러.
  5.  Bzip2를 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:

  #!/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 tvvf - ;;
  #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

  6.  Bzip2를 emacs와 같이 쓰기

  6.1.  모두를 위해 emacs를 바꾸기:

  나는 자동압축모드를 추가한 jka-compr.el패치에 따라 썼다.

  부인서: 나는 emacs-20.0에서만 테스트를 해봤다, 그러나 다른 버전에 비슷
  하게 접근하지 못한다고 믿을 이유가 없다.

  이 것을 써라,

  1. emacs-20.2/lisp 소스 디렉토리에 가라 (wherever you untarred it)

  2. jka-compr.el.diff부른 파일의 아래에 패치를 놓아라  (그 것은 저 파일
  에 단독으로 있어야한다 ;).

  3. 해라

   patch < jka-compr.el.diff

  4. emacs를 시작해라, 그리고 해라


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

  5. emacs를 종료해라.

  6. 당신의 최초의 jka-compr.elc를 버그의 케이스안의 안전한 곳으로 옮겨라.

  7. 새로운 jka-compr.elc와 그 것을 바꿔라.

  8. 즐겨라!


     --- 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")

  6.2.  한 사람을 위해 emacs를 바꾸기:

  Thanks for this one go to Ulrik Dickow, ukd@kampsax.dk
  <mailto:ukdATkampsax.dk>, Kampsax Technology에 있는 시스템 프로그래머:

  당신이 시스템관리자가 아닐때 그것을 만들면 bzip2를 자동적으로 쓸 수 있다.
  ,  당신의 .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)

  7.  Bzip2를 wu-ftpd와 같이 쓰기

  Arnaud Launay에게 이 bandwidth 세이버에 대해 감사한다. The following
  should go in /etc/ftpconversions to do on-the-fly compressions and
  decompressions with bzip2. Make sure that the paths (like
  /bin/compress) are right.


   :.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 -y -f - %s:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+BZIP2

  8.  Bzip2를 grep와 같이 쓰기

  The following utility, which I call bgrep, is a slight modification of
  the zgrep which comes with Linux.  You can use it to grep through
  files without bunzip2'ing them first.

  #!/bin/sh

  # bgrep -- a wrapper around a grep program that decompresses files as needed
  PATH="/usr/bin:$PATH"; export PATH

  prog=`echo $0 | sed 's|.*/||'`
  case "$prog" in
          *egrep) grep=${EGREP-egrep}     ;;
          *fgrep) grep=${FGREP-fgrep}     ;;
          *)      grep=${GREP-grep}       ;;
  esac
  pat=""
  while test $# -ne 0; do
    case "$1" in
    -e | -f) opt="$opt $1"; shift; pat="$1"
             if test "$grep" = grep; then  # grep is buggy with -e on SVR4
               grep=egrep
             fi;;
    -*)      opt="$opt $1";;
     *)      if test -z "$pat"; then
               pat="$1"
             else
               break;
             fi;;
    esac
    shift
  done

  if test -z "$pat"; then
    echo "grep through bzip2 files"
    echo "usage: $prog [grep_options] pattern [files]"
    exit 1
  fi

  list=0
  silent=0
  op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
  case "$op" in
    *l*) list=1
  esac
  case "$op" in
    *h*) silent=1
  esac

  if test $# -eq 0; then
    bzip2 -cd | $grep $opt "$pat"
    exit $?
  fi

  res=0
  for i do
    if test $list -eq 1; then
      bzip2 -cdfq "$i" | $grep $opt "$pat" > /dev/null && echo $i
      r=$?
    elif test $# -eq 1 -o $silent -eq 1; then
      bzip2 -cd "$i" | $grep $opt "$pat"
      r=$?
    else
      bzip2 -cd "$i" | $grep $opt "$pat" | sed "s|^|${i}:|"
      r=$?
    fi
    test "$r" -ne 0 && res="$r"
  done
  exit $res


  9.  Bzip2를 X의 Netscape와 같이 쓰기.

  tenthumbs@cybernex.net says:


       I also found a way to get Linux Netscape to use bzip2 for Content-
       Encoding just as it uses gzip. Add this to $HOME/.Xdefaults or
       $HOME/.Xresources

       I use the -s option because I would rather trade some decompressing
       speed for RAM usage. You can leave the option out if you want to.

  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

  10.  Bzip2로 다른 압축 형식으로 다시 압축하기

  The following perl program takes files compressed in other formats
  (.tar.gz, .tgz. .tar.Z, and .Z for this iteration) and repacks them
  for better compression.  The perl source has all kinds of neat
  documentation on what it does and how it does what it does.  This
  latest version takes files as input on the command line.  Without
  command line arguments, it tries to repack every file in the current
  working directory.

  #!/usr/bin/perl -w

  #######################################################
  #                                                     #
  # This program takes compressed and gzipped programs  #
  # in the current directory and turns them into bzip2  #
  # format.  It handles the .tgz extension in a         #
  # reasonable way, producing a .tar.bz2 file.          #
  #                                                     #
  #######################################################
  $counter = 0;
  $saved_bytes = 0;
  $totals_file = '/tmp/machine_bzip2_total';
  $machine_bzip2_total = 0;

  @raw = (defined @ARGV)?@ARGV:<*>;

  foreach(@raw) {
      next if /^bzip/;
      next unless /\.(tgz|gz|Z)$/;
      push @files, $_;
  }
  $total = scalar(@files);

  foreach (@files) {
      if (/tgz$/) {
          ($new=$_) =~ s/tgz$/tar.bz2/;
      } else {
          ($new=$_) =~ s/\.g?z$/.bz2/i;
      }
      $orig_size = (stat $_)[7];
      ++$counter;
      print "Repacking $_ ($counter/$total)...\n";
      if ((system "gzip -cd $_ |bzip2 >$new") == 0) {
          $new_size = (stat $new)[7];
          $factor = int(100*$new_size/$orig_size+.5);
          $saved_bytes += $orig_size-$new_size;
          print "$new is about $factor% of the size of $_. :",($factor<100)?')':'(',"\n";
          unlink $_;
      } else {
          print "Arrgghh!  Something happened to $_: $!\n";
      }
  }
  print "You've "
      , ($saved_bytes>=0)?"saved ":"lost "
      , abs($saved_bytes)
      , " bytes of storage space :"
      , ($saved_bytes>=0)?")":"("
      , "\n"
      ;

  unless (-e '/tmp/machine_bzip2_total') {
      system ('echo "0" >/tmp/machine_bzip2_total');
      system ('chmod', '0666', '/tmp/machine_bzip2_total');
  }


  chomp($machine_bzip2_total = `cat $totals_file`);
  open TOTAL, ">$totals_file"
       or die "Can't open system-wide total: $!";
  $machine_bzip2_total += $saved_bytes;
  print TOTAL $machine_bzip2_total;
  close TOTAL;

  print "That's a machine-wide total of ",`cat $totals_file`," bytes saved.\n";

