aboutsummaryrefslogtreecommitdiff
path: root/manual.texi
diff options
context:
space:
mode:
Diffstat (limited to 'manual.texi')
-rw-r--r--manual.texi516
1 files changed, 291 insertions, 225 deletions
diff --git a/manual.texi b/manual.texi
index e48e656..336776a 100644
--- a/manual.texi
+++ b/manual.texi
@@ -2,10 +2,10 @@
2@setfilename bzip2.info 2@setfilename bzip2.info
3 3
4@ignore 4@ignore
5This file documents bzip2 version 0.9.5, and associated library 5This file documents bzip2 version 1.0, and associated library
6libbzip2, written by Julian Seward (jseward@acm.org). 6libbzip2, written by Julian Seward (jseward@acm.org).
7 7
8Copyright (C) 1996-1999 Julian R Seward 8Copyright (C) 1996-2000 Julian R Seward
9 9
10Permission is granted to make and distribute verbatim copies of 10Permission is granted to make and distribute verbatim copies of
11this manual provided the copyright notice and this permission notice 11this manual provided the copyright notice and this permission notice
@@ -30,8 +30,8 @@ END-INFO-DIR-ENTRY
30@titlepage 30@titlepage
31@title bzip2 and libbzip2 31@title bzip2 and libbzip2
32@subtitle a program and library for data compression 32@subtitle a program and library for data compression
33@subtitle copyright (C) 1996-1999 Julian Seward 33@subtitle copyright (C) 1996-2000 Julian Seward
34@subtitle version 0.9.5d of 4 September 1999 34@subtitle version 1.0 of 21 March 2000
35@author Julian Seward 35@author Julian Seward
36 36
37@end titlepage 37@end titlepage
@@ -44,7 +44,7 @@ END-INFO-DIR-ENTRY
44 44
45This program, @code{bzip2}, 45This program, @code{bzip2},
46and associated library @code{libbzip2}, are 46and associated library @code{libbzip2}, are
47Copyright (C) 1996-1999 Julian R Seward. All rights reserved. 47Copyright (C) 1996-2000 Julian R Seward. All rights reserved.
48 48
49Redistribution and use in source and binary forms, with or without 49Redistribution and use in source and binary forms, with or without
50modification, are permitted provided that the following conditions 50modification, are permitted provided that the following conditions
@@ -82,9 +82,13 @@ Julian Seward, Cambridge, UK.
82 82
83@code{jseward@@acm.org} 83@code{jseward@@acm.org}
84 84
85@code{http://sourceware.cygnus.com/bzip2}
86
87@code{http://www.cacheprof.org}
88
85@code{http://www.muraroa.demon.co.uk} 89@code{http://www.muraroa.demon.co.uk}
86 90
87@code{bzip2}/@code{libbzip2} version 0.9.5 of 24 May 1999. 91@code{bzip2}/@code{libbzip2} version 1.0 of 21 March 2000.
88 92
89PATENTS: To the best of my knowledge, @code{bzip2} does not use any patented 93PATENTS: To the best of my knowledge, @code{bzip2} does not use any patented
90algorithms. However, I do not have the resources available to carry out 94algorithms. However, I do not have the resources available to carry out
@@ -130,7 +134,7 @@ and nothing else.
130@unnumberedsubsubsec NAME 134@unnumberedsubsubsec NAME
131@itemize 135@itemize
132@item @code{bzip2}, @code{bunzip2} 136@item @code{bzip2}, @code{bunzip2}
133- a block-sorting file compressor, v0.9.5 137- a block-sorting file compressor, v1.0
134@item @code{bzcat} 138@item @code{bzcat}
135- decompresses files to stdout 139- decompresses files to stdout
136@item @code{bzip2recover} 140@item @code{bzip2recover}
@@ -431,10 +435,10 @@ I/O error messages are not as helpful as they could be. @code{bzip2}
431tries hard to detect I/O errors and exit cleanly, but the details of 435tries hard to detect I/O errors and exit cleanly, but the details of
432what the problem is sometimes seem rather misleading. 436what the problem is sometimes seem rather misleading.
433 437
434This manual page pertains to version 0.9.5 of @code{bzip2}. Compressed 438This manual page pertains to version 1.0 of @code{bzip2}. Compressed
435data created by this version is entirely forwards and backwards 439data created by this version is entirely forwards and backwards
436compatible with the previous public releases, versions 0.1pl2 and 0.9.0, 440compatible with the previous public releases, versions 0.1pl2, 0.9.0 and
437but with the following exception: 0.9.0 and above can correctly 4410.9.5, but with the following exception: 0.9.0 and above can correctly
438decompress multiple concatenated compressed files. 0.1pl2 cannot do 442decompress multiple concatenated compressed files. 0.1pl2 cannot do
439this; it will stop after decompressing just the first file in the 443this; it will stop after decompressing just the first file in the
440stream. 444stream.
@@ -486,6 +490,10 @@ The structure of @code{libbzip2}'s interfaces is similar to
486that of Jean-loup Gailly's and Mark Adler's excellent @code{zlib} 490that of Jean-loup Gailly's and Mark Adler's excellent @code{zlib}
487library. 491library.
488 492
493All externally visible symbols have names beginning @code{BZ2_}.
494This is new in version 1.0. The intention is to minimise pollution
495of the namespaces of library clients.
496
489@subsection Low-level summary 497@subsection Low-level summary
490 498
491This interface provides services for compressing and decompressing 499This interface provides services for compressing and decompressing
@@ -498,17 +506,17 @@ The low-level part of the library has no global variables and
498is therefore thread-safe. 506is therefore thread-safe.
499 507
500Six routines make up the low level interface: 508Six routines make up the low level interface:
501@code{bzCompressInit}, @code{bzCompress}, and @* @code{bzCompressEnd} 509@code{BZ2_bzCompressInit}, @code{BZ2_bzCompress}, and @* @code{BZ2_bzCompressEnd}
502for compression, 510for compression,
503and a corresponding trio @code{bzDecompressInit}, @* @code{bzDecompress} 511and a corresponding trio @code{BZ2_bzDecompressInit}, @* @code{BZ2_bzDecompress}
504and @code{bzDecompressEnd} for decompression. 512and @code{BZ2_bzDecompressEnd} for decompression.
505The @code{*Init} functions allocate 513The @code{*Init} functions allocate
506memory for compression/decompression and do other 514memory for compression/decompression and do other
507initialisations, whilst the @code{*End} functions close down operations 515initialisations, whilst the @code{*End} functions close down operations
508and release memory. 516and release memory.
509 517
510The real work is done by @code{bzCompress} and @code{bzDecompress}. 518The real work is done by @code{BZ2_bzCompress} and @code{BZ2_bzDecompress}.
511These compress/decompress data from a user-supplied input buffer 519These compress and decompress data from a user-supplied input buffer
512to a user-supplied output buffer. These buffers can be any size; 520to a user-supplied output buffer. These buffers can be any size;
513arbitrary quantities of data are handled by making repeated calls 521arbitrary quantities of data are handled by making repeated calls
514to these functions. This is a flexible mechanism allowing a 522to these functions. This is a flexible mechanism allowing a
@@ -526,10 +534,10 @@ reading files in which the @code{bzip2} data stream is embedded
526within some larger-scale file structure, or where there are 534within some larger-scale file structure, or where there are
527multiple @code{bzip2} data streams concatenated end-to-end. 535multiple @code{bzip2} data streams concatenated end-to-end.
528 536
529For reading files, @code{bzReadOpen}, @code{bzRead}, @code{bzReadClose} 537For reading files, @code{BZ2_bzReadOpen}, @code{BZ2_bzRead},
530and @code{bzReadGetUnused} are supplied. For writing files, 538@code{BZ2_bzReadClose} and @* @code{BZ2_bzReadGetUnused} are supplied. For
531@code{bzWriteOpen}, @code{bzWrite} and @code{bzWriteFinish} are 539writing files, @code{BZ2_bzWriteOpen}, @code{BZ2_bzWrite} and
532available. 540@code{BZ2_bzWriteFinish} are available.
533 541
534As with the low-level library, no global variables are used 542As with the low-level library, no global variables are used
535so the library is per se thread-safe. However, if I/O errors 543so the library is per se thread-safe. However, if I/O errors
@@ -539,7 +547,7 @@ the error. In that case, you'd need a C library which correctly
539supports @code{errno} in a multithreaded environment. 547supports @code{errno} in a multithreaded environment.
540 548
541To make the library a little simpler and more portable, 549To make the library a little simpler and more portable,
542@code{bzReadOpen} and @code{bzWriteOpen} require you to pass them file 550@code{BZ2_bzReadOpen} and @code{BZ2_bzWriteOpen} require you to pass them file
543handles (@code{FILE*}s) which have previously been opened for reading or 551handles (@code{FILE*}s) which have previously been opened for reading or
544writing respectively. That avoids portability problems associated with 552writing respectively. That avoids portability problems associated with
545file operations and file attributes, whilst not being much of an 553file operations and file attributes, whilst not being much of an
@@ -548,8 +556,8 @@ imposition on the programmer.
548 556
549 557
550@subsection Utility functions summary 558@subsection Utility functions summary
551For very simple needs, @code{bzBuffToBuffCompress} and 559For very simple needs, @code{BZ2_bzBuffToBuffCompress} and
552@code{bzBuffToBuffDecompress} are provided. These compress 560@code{BZ2_bzBuffToBuffDecompress} are provided. These compress
553data in memory from one buffer to another buffer in a single 561data in memory from one buffer to another buffer in a single
554function call. You should assess whether these functions 562function call. You should assess whether these functions
555fulfill your memory-to-memory compression/decompression 563fulfill your memory-to-memory compression/decompression
@@ -559,9 +567,9 @@ general but more complex low-level interface.
559Yoshioka Tsuneo (@code{QWF00133@@niftyserve.or.jp} / 567Yoshioka Tsuneo (@code{QWF00133@@niftyserve.or.jp} /
560@code{tsuneo-y@@is.aist-nara.ac.jp}) has contributed some functions to 568@code{tsuneo-y@@is.aist-nara.ac.jp}) has contributed some functions to
561give better @code{zlib} compatibility. These functions are 569give better @code{zlib} compatibility. These functions are
562@code{bzopen}, @code{bzread}, @code{bzwrite}, @code{bzflush}, 570@code{BZ2_bzopen}, @code{BZ2_bzread}, @code{BZ2_bzwrite}, @code{BZ2_bzflush},
563@code{bzclose}, 571@code{BZ2_bzclose},
564@code{bzerror} and @code{bzlibVersion}. You may find these functions 572@code{BZ2_bzerror} and @code{BZ2_bzlibVersion}. You may find these functions
565more convenient for simple file reading and writing, than those in the 573more convenient for simple file reading and writing, than those in the
566high-level interface. These functions are not (yet) officially part of 574high-level interface. These functions are not (yet) officially part of
567the library, and are minimally documented here. If they break, you 575the library, and are minimally documented here. If they break, you
@@ -582,6 +590,15 @@ if you are feeling especially paranoid. I would be interested in
582hearing more about the robustness of the library to corrupted 590hearing more about the robustness of the library to corrupted
583compressed data. 591compressed data.
584 592
593Version 1.0 is much more robust in this respect than
5940.9.0 or 0.9.5. Investigations with Checker (a tool for
595detecting problems with memory management, similar to Purify)
596indicate that, at least for the few files I tested, all single-bit
597errors in the decompressed data are caught properly, with no
598segmentation faults, no reads of uninitialised data and no
599out of range reads or writes. So it's certainly much improved,
600although I wouldn't claim it to be totally bombproof.
601
585The file @code{bzlib.h} contains all definitions needed to use 602The file @code{bzlib.h} contains all definitions needed to use
586the library. In particular, you should definitely not include 603the library. In particular, you should definitely not include
587@code{bzlib_private.h}. 604@code{bzlib_private.h}.
@@ -598,7 +615,7 @@ The requested action was completed successfully.
598@item BZ_RUN_OK 615@item BZ_RUN_OK
599@itemx BZ_FLUSH_OK 616@itemx BZ_FLUSH_OK
600@itemx BZ_FINISH_OK 617@itemx BZ_FINISH_OK
601In @code{bzCompress}, the requested flush/finish/nothing-special action 618In @code{BZ2_bzCompress}, the requested flush/finish/nothing-special action
602was completed successfully. 619was completed successfully.
603@item BZ_STREAM_END 620@item BZ_STREAM_END
604Compression of data was completed, or the logical stream end was 621Compression of data was completed, or the logical stream end was
@@ -607,6 +624,16 @@ detected during decompression.
607 624
608The following return values indicate an error of some kind. 625The following return values indicate an error of some kind.
609@table @code 626@table @code
627@item BZ_CONFIG_ERROR
628Indicates that the library has been improperly compiled on your
629platform -- a major configuration error. Specifically, it means
630that @code{sizeof(char)}, @code{sizeof(short)} and @code{sizeof(int)}
631are not 1, 2 and 4 respectively, as they should be. Note that the
632library should still work properly on 64-bit platforms which follow
633the LP64 programming model -- that is, where @code{sizeof(long)}
634and @code{sizeof(void*)} are 8. Under LP64, @code{sizeof(int)} is
635still 4, so @code{libbzip2}, which doesn't use the @code{long} type,
636is OK.
610@item BZ_SEQUENCE_ERROR 637@item BZ_SEQUENCE_ERROR
611When using the library, it is important to call the functions in the 638When using the library, it is important to call the functions in the
612correct sequence and with data structures (buffers etc) in the correct 639correct sequence and with data structures (buffers etc) in the correct
@@ -624,10 +651,10 @@ making.
624@item BZ_MEM_ERROR 651@item BZ_MEM_ERROR
625Returned when a request to allocate memory failed. Note that the 652Returned when a request to allocate memory failed. Note that the
626quantity of memory needed to decompress a stream cannot be determined 653quantity of memory needed to decompress a stream cannot be determined
627until the stream's header has been read. So @code{bzDecompress} and 654until the stream's header has been read. So @code{BZ2_bzDecompress} and
628@code{bzRead} may return @code{BZ_MEM_ERROR} even though some of 655@code{BZ2_bzRead} may return @code{BZ_MEM_ERROR} even though some of
629the compressed data has been read. The same is not true for 656the compressed data has been read. The same is not true for
630compression; once @code{bzCompressInit} or @code{bzWriteOpen} have 657compression; once @code{BZ2_bzCompressInit} or @code{BZ2_bzWriteOpen} have
631successfully completed, @code{BZ_MEM_ERROR} cannot occur. 658successfully completed, @code{BZ_MEM_ERROR} cannot occur.
632@item BZ_DATA_ERROR 659@item BZ_DATA_ERROR
633Returned when a data integrity error is detected during decompression. 660Returned when a data integrity error is detected during decompression.
@@ -639,19 +666,19 @@ As a special case of @code{BZ_DATA_ERROR}, it is sometimes useful to
639know when the compressed stream does not start with the correct 666know when the compressed stream does not start with the correct
640magic bytes (@code{'B' 'Z' 'h'}). 667magic bytes (@code{'B' 'Z' 'h'}).
641@item BZ_IO_ERROR 668@item BZ_IO_ERROR
642Returned by @code{bzRead} and @code{bzRead} when there is an error 669Returned by @code{BZ2_bzRead} and @code{BZ2_bzWrite} when there is an error
643reading or writing in the compressed file, and by @code{bzReadOpen} 670reading or writing in the compressed file, and by @code{BZ2_bzReadOpen}
644and @code{bzWriteOpen} for attempts to use a file for which the 671and @code{BZ2_bzWriteOpen} for attempts to use a file for which the
645error indicator (viz, @code{ferror(f)}) is set. 672error indicator (viz, @code{ferror(f)}) is set.
646On receipt of @code{BZ_IO_ERROR}, the caller should consult 673On receipt of @code{BZ_IO_ERROR}, the caller should consult
647@code{errno} and/or @code{perror} to acquire operating-system 674@code{errno} and/or @code{perror} to acquire operating-system
648specific information about the problem. 675specific information about the problem.
649@item BZ_UNEXPECTED_EOF 676@item BZ_UNEXPECTED_EOF
650Returned by @code{bzRead} when the compressed file finishes 677Returned by @code{BZ2_bzRead} when the compressed file finishes
651before the logical end of stream is detected. 678before the logical end of stream is detected.
652@item BZ_OUTBUFF_FULL 679@item BZ_OUTBUFF_FULL
653Returned by @code{bzBuffToBuffCompress} and 680Returned by @code{BZ2_bzBuffToBuffCompress} and
654@code{bzBuffToBuffDecompress} to indicate that the output data 681@code{BZ2_bzBuffToBuffDecompress} to indicate that the output data
655will not fit into the output buffer provided. 682will not fit into the output buffer provided.
656@end table 683@end table
657 684
@@ -659,17 +686,19 @@ will not fit into the output buffer provided.
659 686
660@section Low-level interface 687@section Low-level interface
661 688
662@subsection @code{bzCompressInit} 689@subsection @code{BZ2_bzCompressInit}
663@example 690@example
664typedef 691typedef
665 struct @{ 692 struct @{
666 char *next_in; 693 char *next_in;
667 unsigned int avail_in; 694 unsigned int avail_in;
668 unsigned int total_in; 695 unsigned int total_in_lo32;
696 unsigned int total_in_hi32;
669 697
670 char *next_out; 698 char *next_out;
671 unsigned int avail_out; 699 unsigned int avail_out;
672 unsigned int total_out; 700 unsigned int total_out_lo32;
701 unsigned int total_out_hi32;
673 702
674 void *state; 703 void *state;
675 704
@@ -679,10 +708,10 @@ typedef
679 @} 708 @}
680 bz_stream; 709 bz_stream;
681 710
682int bzCompressInit ( bz_stream *strm, 711int BZ2_bzCompressInit ( bz_stream *strm,
683 int blockSize100k, 712 int blockSize100k,
684 int verbosity, 713 int verbosity,
685 int workFactor ); 714 int workFactor );
686 715
687@end example 716@end example
688 717
@@ -712,14 +741,19 @@ If you don't want to use a custom memory allocator, set @code{bzalloc},
712and the library will then use the standard @code{malloc}/@code{free} 741and the library will then use the standard @code{malloc}/@code{free}
713routines. 742routines.
714 743
715Before calling @code{bzCompressInit}, fields @code{bzalloc}, 744Before calling @code{BZ2_bzCompressInit}, fields @code{bzalloc},
716@code{bzfree} and @code{opaque} should 745@code{bzfree} and @code{opaque} should
717be filled appropriately, as just described. Upon return, the internal 746be filled appropriately, as just described. Upon return, the internal
718state will have been allocated and initialised, and @code{total_in} and 747state will have been allocated and initialised, and @code{total_in_lo32},
719@code{total_out} will have been set to zero. 748@code{total_in_hi32}, @code{total_out_lo32} and
720These last two fields are used by the library 749@code{total_out_hi32} will have been set to zero.
750These four fields are used by the library
721to inform the caller of the total amount of data passed into and out of 751to inform the caller of the total amount of data passed into and out of
722the library, respectively. You should not try to change them. 752the library, respectively. You should not try to change them.
753As of version 1.0, 64-bit counts are maintained, even on 32-bit
754platforms, using the @code{_hi32} fields to store the upper 32 bits
755of the count. So, for example, the total amount of data in
756is @code{(total_in_hi32 << 32) + total_in_lo32}.
723 757
724Parameter @code{blockSize100k} specifies the block size to be used for 758Parameter @code{blockSize100k} specifies the block size to be used for
725compression. It should be a value between 1 and 9 inclusive, and the 759compression. It should be a value between 1 and 9 inclusive, and the
@@ -761,6 +795,8 @@ mechanism would render the parameter obsolete.
761 795
762Possible return values: 796Possible return values:
763@display 797@display
798 @code{BZ_CONFIG_ERROR}
799 if the library has been mis-compiled
764 @code{BZ_PARAM_ERROR} 800 @code{BZ_PARAM_ERROR}
765 if @code{strm} is @code{NULL} 801 if @code{strm} is @code{NULL}
766 or @code{blockSize} < 1 or @code{blockSize} > 9 802 or @code{blockSize} < 1 or @code{blockSize} > 9
@@ -773,86 +809,86 @@ Possible return values:
773@end display 809@end display
774Allowable next actions: 810Allowable next actions:
775@display 811@display
776 @code{bzCompress} 812 @code{BZ2_bzCompress}
777 if @code{BZ_OK} is returned 813 if @code{BZ_OK} is returned
778 no specific action needed in case of error 814 no specific action needed in case of error
779@end display 815@end display
780 816
781@subsection @code{bzCompress} 817@subsection @code{BZ2_bzCompress}
782@example 818@example
783 int bzCompress ( bz_stream *strm, int action ); 819 int BZ2_bzCompress ( bz_stream *strm, int action );
784@end example 820@end example
785Provides more input and/or output buffer space for the library. The 821Provides more input and/or output buffer space for the library. The
786caller maintains input and output buffers, and calls @code{bzCompress} to 822caller maintains input and output buffers, and calls @code{BZ2_bzCompress} to
787transfer data between them. 823transfer data between them.
788 824
789Before each call to @code{bzCompress}, @code{next_in} should point at 825Before each call to @code{BZ2_bzCompress}, @code{next_in} should point at
790the data to be compressed, and @code{avail_in} should indicate how many 826the data to be compressed, and @code{avail_in} should indicate how many
791bytes the library may read. @code{bzCompress} updates @code{next_in}, 827bytes the library may read. @code{BZ2_bzCompress} updates @code{next_in},
792@code{avail_in} and @code{total_in} to reflect the number of bytes it 828@code{avail_in} and @code{total_in} to reflect the number of bytes it
793has read. 829has read.
794 830
795Similarly, @code{next_out} should point to a buffer in which the 831Similarly, @code{next_out} should point to a buffer in which the
796compressed data is to be placed, with @code{avail_out} indicating how 832compressed data is to be placed, with @code{avail_out} indicating how
797much output space is available. @code{bzCompress} updates 833much output space is available. @code{BZ2_bzCompress} updates
798@code{next_out}, @code{avail_out} and @code{total_out} to reflect the 834@code{next_out}, @code{avail_out} and @code{total_out} to reflect the
799number of bytes output. 835number of bytes output.
800 836
801You may provide and remove as little or as much data as you like on each 837You may provide and remove as little or as much data as you like on each
802call of @code{bzCompress}. In the limit, it is acceptable to supply and 838call of @code{BZ2_bzCompress}. In the limit, it is acceptable to supply and
803remove data one byte at a time, although this would be terribly 839remove data one byte at a time, although this would be terribly
804inefficient. You should always ensure that at least one byte of output 840inefficient. You should always ensure that at least one byte of output
805space is available at each call. 841space is available at each call.
806 842
807A second purpose of @code{bzCompress} is to request a change of mode of the 843A second purpose of @code{BZ2_bzCompress} is to request a change of mode of the
808compressed stream. 844compressed stream.
809 845
810Conceptually, a compressed stream can be in one of four states: IDLE, 846Conceptually, a compressed stream can be in one of four states: IDLE,
811RUNNING, FLUSHING and FINISHING. Before initialisation 847RUNNING, FLUSHING and FINISHING. Before initialisation
812(@code{bzCompressInit}) and after termination (@code{bzCompressEnd}), a 848(@code{BZ2_bzCompressInit}) and after termination (@code{BZ2_bzCompressEnd}), a
813stream is regarded as IDLE. 849stream is regarded as IDLE.
814 850
815Upon initialisation (@code{bzCompressInit}), the stream is placed in the 851Upon initialisation (@code{BZ2_bzCompressInit}), the stream is placed in the
816RUNNING state. Subsequent calls to @code{bzCompress} should pass 852RUNNING state. Subsequent calls to @code{BZ2_bzCompress} should pass
817@code{BZ_RUN} as the requested action; other actions are illegal and 853@code{BZ_RUN} as the requested action; other actions are illegal and
818will result in @code{BZ_SEQUENCE_ERROR}. 854will result in @code{BZ_SEQUENCE_ERROR}.
819 855
820At some point, the calling program will have provided all the input data 856At some point, the calling program will have provided all the input data
821it wants to. It will then want to finish up -- in effect, asking the 857it wants to. It will then want to finish up -- in effect, asking the
822library to process any data it might have buffered internally. In this 858library to process any data it might have buffered internally. In this
823state, @code{bzCompress} will no longer attempt to read data from 859state, @code{BZ2_bzCompress} will no longer attempt to read data from
824@code{next_in}, but it will want to write data to @code{next_out}. 860@code{next_in}, but it will want to write data to @code{next_out}.
825Because the output buffer supplied by the user can be arbitrarily small, 861Because the output buffer supplied by the user can be arbitrarily small,
826the finishing-up operation cannot necessarily be done with a single call 862the finishing-up operation cannot necessarily be done with a single call
827of @code{bzCompress}. 863of @code{BZ2_bzCompress}.
828 864
829Instead, the calling program passes @code{BZ_FINISH} as an action to 865Instead, the calling program passes @code{BZ_FINISH} as an action to
830@code{bzCompress}. This changes the stream's state to FINISHING. Any 866@code{BZ2_bzCompress}. This changes the stream's state to FINISHING. Any
831remaining input (ie, @code{next_in[0 .. avail_in-1]}) is compressed and 867remaining input (ie, @code{next_in[0 .. avail_in-1]}) is compressed and
832transferred to the output buffer. To do this, @code{bzCompress} must be 868transferred to the output buffer. To do this, @code{BZ2_bzCompress} must be
833called repeatedly until all the output has been consumed. At that 869called repeatedly until all the output has been consumed. At that
834point, @code{bzCompress} returns @code{BZ_STREAM_END}, and the stream's 870point, @code{BZ2_bzCompress} returns @code{BZ_STREAM_END}, and the stream's
835state is set back to IDLE. @code{bzCompressEnd} should then be 871state is set back to IDLE. @code{BZ2_bzCompressEnd} should then be
836called. 872called.
837 873
838Just to make sure the calling program does not cheat, the library makes 874Just to make sure the calling program does not cheat, the library makes
839a note of @code{avail_in} at the time of the first call to 875a note of @code{avail_in} at the time of the first call to
840@code{bzCompress} which has @code{BZ_FINISH} as an action (ie, at the 876@code{BZ2_bzCompress} which has @code{BZ_FINISH} as an action (ie, at the
841time the program has announced its intention to not supply any more 877time the program has announced its intention to not supply any more
842input). By comparing this value with that of @code{avail_in} over 878input). By comparing this value with that of @code{avail_in} over
843subsequent calls to @code{bzCompress}, the library can detect any 879subsequent calls to @code{BZ2_bzCompress}, the library can detect any
844attempts to slip in more data to compress. Any calls for which this is 880attempts to slip in more data to compress. Any calls for which this is
845detected will return @code{BZ_SEQUENCE_ERROR}. This indicates a 881detected will return @code{BZ_SEQUENCE_ERROR}. This indicates a
846programming mistake which should be corrected. 882programming mistake which should be corrected.
847 883
848Instead of asking to finish, the calling program may ask 884Instead of asking to finish, the calling program may ask
849@code{bzCompress} to take all the remaining input, compress it and 885@code{BZ2_bzCompress} to take all the remaining input, compress it and
850terminate the current (Burrows-Wheeler) compression block. This could 886terminate the current (Burrows-Wheeler) compression block. This could
851be useful for error control purposes. The mechanism is analogous to 887be useful for error control purposes. The mechanism is analogous to
852that for finishing: call @code{bzCompress} with an action of 888that for finishing: call @code{BZ2_bzCompress} with an action of
853@code{BZ_FLUSH}, remove output data, and persist with the 889@code{BZ_FLUSH}, remove output data, and persist with the
854@code{BZ_FLUSH} action until the value @code{BZ_RUN} is returned. As 890@code{BZ_FLUSH} action until the value @code{BZ_RUN} is returned. As
855with finishing, @code{bzCompress} detects any attempt to provide more 891with finishing, @code{BZ2_bzCompress} detects any attempt to provide more
856input data once the flush has begun. 892input data once the flush has begun.
857 893
858Once the flush is complete, the stream returns to the normal RUNNING 894Once the flush is complete, the stream returns to the normal RUNNING
@@ -863,11 +899,11 @@ which shows which actions are allowable in each state, what action
863will be taken, what the next state is, and what the non-error return 899will be taken, what the next state is, and what the non-error return
864values are. Note that you can't explicitly ask what state the 900values are. Note that you can't explicitly ask what state the
865stream is in, but nor do you need to -- it can be inferred from the 901stream is in, but nor do you need to -- it can be inferred from the
866values returned by @code{bzCompress}. 902values returned by @code{BZ2_bzCompress}.
867@display 903@display
868IDLE/@code{any} 904IDLE/@code{any}
869 Illegal. IDLE state only exists after @code{bzCompressEnd} or 905 Illegal. IDLE state only exists after @code{BZ2_bzCompressEnd} or
870 before @code{bzCompressInit}. 906 before @code{BZ2_bzCompressInit}.
871 Return value = @code{BZ_SEQUENCE_ERROR} 907 Return value = @code{BZ_SEQUENCE_ERROR}
872 908
873RUNNING/@code{BZ_RUN} 909RUNNING/@code{BZ_RUN}
@@ -917,21 +953,21 @@ FINISHING/other
917That still looks complicated? Well, fair enough. The usual sequence 953That still looks complicated? Well, fair enough. The usual sequence
918of calls for compressing a load of data is: 954of calls for compressing a load of data is:
919@itemize @bullet 955@itemize @bullet
920@item Get started with @code{bzCompressInit}. 956@item Get started with @code{BZ2_bzCompressInit}.
921@item Shovel data in and shlurp out its compressed form using zero or more 957@item Shovel data in and shlurp out its compressed form using zero or more
922calls of @code{bzCompress} with action = @code{BZ_RUN}. 958calls of @code{BZ2_bzCompress} with action = @code{BZ_RUN}.
923@item Finish up. 959@item Finish up.
924Repeatedly call @code{bzCompress} with action = @code{BZ_FINISH}, 960Repeatedly call @code{BZ2_bzCompress} with action = @code{BZ_FINISH},
925copying out the compressed output, until @code{BZ_STREAM_END} is returned. 961copying out the compressed output, until @code{BZ_STREAM_END} is returned.
926@item Close up and go home. Call @code{bzCompressEnd}. 962@item Close up and go home. Call @code{BZ2_bzCompressEnd}.
927@end itemize 963@end itemize
928If the data you want to compress fits into your input buffer all 964If the data you want to compress fits into your input buffer all
929at once, you can skip the calls of @code{bzCompress ( ..., BZ_RUN )} and 965at once, you can skip the calls of @code{BZ2_bzCompress ( ..., BZ_RUN )} and
930just do the @code{bzCompress ( ..., BZ_FINISH )} calls. 966just do the @code{BZ2_bzCompress ( ..., BZ_FINISH )} calls.
931 967
932All required memory is allocated by @code{bzCompressInit}. The 968All required memory is allocated by @code{BZ2_bzCompressInit}. The
933compression library can accept any data at all (obviously). So you 969compression library can accept any data at all (obviously). So you
934shouldn't get any error return values from the @code{bzCompress} calls. 970shouldn't get any error return values from the @code{BZ2_bzCompress} calls.
935If you do, they will be @code{BZ_SEQUENCE_ERROR}, and indicate a bug in 971If you do, they will be @code{BZ_SEQUENCE_ERROR}, and indicate a bug in
936your programming. 972your programming.
937 973
@@ -941,9 +977,9 @@ Trivial other possible return values:
941 if @code{strm} is @code{NULL}, or @code{strm->s} is @code{NULL} 977 if @code{strm} is @code{NULL}, or @code{strm->s} is @code{NULL}
942@end display 978@end display
943 979
944@subsection @code{bzCompressEnd} 980@subsection @code{BZ2_bzCompressEnd}
945@example 981@example
946int bzCompressEnd ( bz_stream *strm ); 982int BZ2_bzCompressEnd ( bz_stream *strm );
947@end example 983@end example
948Releases all memory associated with a compression stream. 984Releases all memory associated with a compression stream.
949 985
@@ -954,11 +990,11 @@ Possible return values:
954@end display 990@end display
955 991
956 992
957@subsection @code{bzDecompressInit} 993@subsection @code{BZ2_bzDecompressInit}
958@example 994@example
959int bzDecompressInit ( bz_stream *strm, int verbosity, int small ); 995int BZ2_bzDecompressInit ( bz_stream *strm, int verbosity, int small );
960@end example 996@end example
961Prepares for decompression. As with @code{bzCompressInit}, a 997Prepares for decompression. As with @code{BZ2_bzCompressInit}, a
962@code{bz_stream} record should be allocated and initialised before the 998@code{bz_stream} record should be allocated and initialised before the
963call. Fields @code{bzalloc}, @code{bzfree} and @code{opaque} should be 999call. Fields @code{bzalloc}, @code{bzfree} and @code{opaque} should be
964set if a custom memory allocator is required, or made @code{NULL} for 1000set if a custom memory allocator is required, or made @code{NULL} for
@@ -966,7 +1002,7 @@ the normal @code{malloc}/@code{free} routines. Upon return, the internal
966state will have been initialised, and @code{total_in} and 1002state will have been initialised, and @code{total_in} and
967@code{total_out} will be zero. 1003@code{total_out} will be zero.
968 1004
969For the meaning of parameter @code{verbosity}, see @code{bzCompressInit}. 1005For the meaning of parameter @code{verbosity}, see @code{BZ2_bzCompressInit}.
970 1006
971If @code{small} is nonzero, the library will use an alternative 1007If @code{small} is nonzero, the library will use an alternative
972decompression algorithm which uses less memory but at the cost of 1008decompression algorithm which uses less memory but at the cost of
@@ -976,11 +1012,13 @@ more information on memory management.
976 1012
977Note that the amount of memory needed to decompress 1013Note that the amount of memory needed to decompress
978a stream cannot be determined until the stream's header has been read, 1014a stream cannot be determined until the stream's header has been read,
979so even if @code{bzDecompressInit} succeeds, a subsequent 1015so even if @code{BZ2_bzDecompressInit} succeeds, a subsequent
980@code{bzDecompress} could fail with @code{BZ_MEM_ERROR}. 1016@code{BZ2_bzDecompress} could fail with @code{BZ_MEM_ERROR}.
981 1017
982Possible return values: 1018Possible return values:
983@display 1019@display
1020 @code{BZ_CONFIG_ERROR}
1021 if the library has been mis-compiled
984 @code{BZ_PARAM_ERROR} 1022 @code{BZ_PARAM_ERROR}
985 if @code{(small != 0 && small != 1)} 1023 if @code{(small != 0 && small != 1)}
986 or @code{(verbosity < 0 || verbosity > 4)} 1024 or @code{(verbosity < 0 || verbosity > 4)}
@@ -990,54 +1028,54 @@ Possible return values:
990 1028
991Allowable next actions: 1029Allowable next actions:
992@display 1030@display
993 @code{bzDecompress} 1031 @code{BZ2_bzDecompress}
994 if @code{BZ_OK} was returned 1032 if @code{BZ_OK} was returned
995 no specific action required in case of error 1033 no specific action required in case of error
996@end display 1034@end display
997 1035
998 1036
999 1037
1000@subsection @code{bzDecompress} 1038@subsection @code{BZ2_bzDecompress}
1001@example 1039@example
1002int bzDecompress ( bz_stream *strm ); 1040int BZ2_bzDecompress ( bz_stream *strm );
1003@end example 1041@end example
1004Provides more input and/out output buffer space for the library. The 1042Provides more input and/out output buffer space for the library. The
1005caller maintains input and output buffers, and uses @code{bzDecompress} 1043caller maintains input and output buffers, and uses @code{BZ2_bzDecompress}
1006to transfer data between them. 1044to transfer data between them.
1007 1045
1008Before each call to @code{bzDecompress}, @code{next_in} 1046Before each call to @code{BZ2_bzDecompress}, @code{next_in}
1009should point at the compressed data, 1047should point at the compressed data,
1010and @code{avail_in} should indicate how many bytes the library 1048and @code{avail_in} should indicate how many bytes the library
1011may read. @code{bzDecompress} updates @code{next_in}, @code{avail_in} 1049may read. @code{BZ2_bzDecompress} updates @code{next_in}, @code{avail_in}
1012and @code{total_in} 1050and @code{total_in}
1013to reflect the number of bytes it has read. 1051to reflect the number of bytes it has read.
1014 1052
1015Similarly, @code{next_out} should point to a buffer in which the uncompressed 1053Similarly, @code{next_out} should point to a buffer in which the uncompressed
1016output is to be placed, with @code{avail_out} indicating how much output space 1054output is to be placed, with @code{avail_out} indicating how much output space
1017is available. @code{bzCompress} updates @code{next_out}, 1055is available. @code{BZ2_bzCompress} updates @code{next_out},
1018@code{avail_out} and @code{total_out} to reflect 1056@code{avail_out} and @code{total_out} to reflect
1019the number of bytes output. 1057the number of bytes output.
1020 1058
1021You may provide and remove as little or as much data as you like on 1059You may provide and remove as little or as much data as you like on
1022each call of @code{bzDecompress}. 1060each call of @code{BZ2_bzDecompress}.
1023In the limit, it is acceptable to 1061In the limit, it is acceptable to
1024supply and remove data one byte at a time, although this would be 1062supply and remove data one byte at a time, although this would be
1025terribly inefficient. You should always ensure that at least one 1063terribly inefficient. You should always ensure that at least one
1026byte of output space is available at each call. 1064byte of output space is available at each call.
1027 1065
1028Use of @code{bzDecompress} is simpler than @code{bzCompress}. 1066Use of @code{BZ2_bzDecompress} is simpler than @code{BZ2_bzCompress}.
1029 1067
1030You should provide input and remove output as described above, and 1068You should provide input and remove output as described above, and
1031repeatedly call @code{bzDecompress} until @code{BZ_STREAM_END} is 1069repeatedly call @code{BZ2_bzDecompress} until @code{BZ_STREAM_END} is
1032returned. Appearance of @code{BZ_STREAM_END} denotes that 1070returned. Appearance of @code{BZ_STREAM_END} denotes that
1033@code{bzDecompress} has detected the logical end of the compressed 1071@code{BZ2_bzDecompress} has detected the logical end of the compressed
1034stream. @code{bzDecompress} will not produce @code{BZ_STREAM_END} until 1072stream. @code{BZ2_bzDecompress} will not produce @code{BZ_STREAM_END} until
1035all output data has been placed into the output buffer, so once 1073all output data has been placed into the output buffer, so once
1036@code{BZ_STREAM_END} appears, you are guaranteed to have available all 1074@code{BZ_STREAM_END} appears, you are guaranteed to have available all
1037the decompressed output, and @code{bzDecompressEnd} can safely be 1075the decompressed output, and @code{BZ2_bzDecompressEnd} can safely be
1038called. 1076called.
1039 1077
1040If case of an error return value, you should call @code{bzDecompressEnd} 1078If case of an error return value, you should call @code{BZ2_bzDecompressEnd}
1041to clean up and release memory. 1079to clean up and release memory.
1042 1080
1043Possible return values: 1081Possible return values:
@@ -1059,16 +1097,16 @@ Possible return values:
1059@end display 1097@end display
1060Allowable next actions: 1098Allowable next actions:
1061@display 1099@display
1062 @code{bzDecompress} 1100 @code{BZ2_bzDecompress}
1063 if @code{BZ_OK} was returned 1101 if @code{BZ_OK} was returned
1064 @code{bzDecompressEnd} 1102 @code{BZ2_bzDecompressEnd}
1065 otherwise 1103 otherwise
1066@end display 1104@end display
1067 1105
1068 1106
1069@subsection @code{bzDecompressEnd} 1107@subsection @code{BZ2_bzDecompressEnd}
1070@example 1108@example
1071int bzDecompressEnd ( bz_stream *strm ); 1109int BZ2_bzDecompressEnd ( bz_stream *strm );
1072@end example 1110@end example
1073Releases all memory associated with a decompression stream. 1111Releases all memory associated with a decompression stream.
1074 1112
@@ -1107,16 +1145,16 @@ This interface provides functions for reading and writing
1107 given on a per-function basis below. 1145 given on a per-function basis below.
1108@item If @code{bzerror} indicates an error 1146@item If @code{bzerror} indicates an error
1109 (ie, anything except @code{BZ_OK} and @code{BZ_STREAM_END}), 1147 (ie, anything except @code{BZ_OK} and @code{BZ_STREAM_END}),
1110 you should immediately call @code{bzReadClose} (or @code{bzWriteClose}, 1148 you should immediately call @code{BZ2_bzReadClose} (or @code{BZ2_bzWriteClose},
1111 depending on whether you are attempting to read or to write) 1149 depending on whether you are attempting to read or to write)
1112 to free up all resources associated 1150 to free up all resources associated
1113 with the stream. Once an error has been indicated, behaviour of all calls 1151 with the stream. Once an error has been indicated, behaviour of all calls
1114 except @code{bzReadClose} (@code{bzWriteClose}) is undefined. 1152 except @code{BZ2_bzReadClose} (@code{BZ2_bzWriteClose}) is undefined.
1115 The implication is that (1) @code{bzerror} should 1153 The implication is that (1) @code{bzerror} should
1116 be checked after each call, and (2) if @code{bzerror} indicates an error, 1154 be checked after each call, and (2) if @code{bzerror} indicates an error,
1117 @code{bzReadClose} (@code{bzWriteClose}) should then be called to clean up. 1155 @code{BZ2_bzReadClose} (@code{BZ2_bzWriteClose}) should then be called to clean up.
1118@item The @code{FILE*} arguments passed to 1156@item The @code{FILE*} arguments passed to
1119 @code{bzReadOpen}/@code{bzWriteOpen} 1157 @code{BZ2_bzReadOpen}/@code{BZ2_bzWriteOpen}
1120 should be set to binary mode. 1158 should be set to binary mode.
1121 Most Unix systems will do this by default, but other platforms, 1159 Most Unix systems will do this by default, but other platforms,
1122 including Windows and Mac, will not. If you omit this, you may 1160 including Windows and Mac, will not. If you omit this, you may
@@ -1130,13 +1168,13 @@ This interface provides functions for reading and writing
1130 1168
1131 1169
1132 1170
1133@subsection @code{bzReadOpen} 1171@subsection @code{BZ2_bzReadOpen}
1134@example 1172@example
1135 typedef void BZFILE; 1173 typedef void BZFILE;
1136 1174
1137 BZFILE *bzReadOpen ( int *bzerror, FILE *f, 1175 BZFILE *BZ2_bzReadOpen ( int *bzerror, FILE *f,
1138 int small, int verbosity, 1176 int small, int verbosity,
1139 void *unused, int nUnused ); 1177 void *unused, int nUnused );
1140@end example 1178@end example
1141Prepare to read compressed data from file handle @code{f}. @code{f} 1179Prepare to read compressed data from file handle @code{f}. @code{f}
1142should refer to a file which has been opened for reading, and for which 1180should refer to a file which has been opened for reading, and for which
@@ -1144,7 +1182,7 @@ the error indicator (@code{ferror(f)})is not set. If @code{small} is 1,
1144the library will try to decompress using less memory, at the expense of 1182the library will try to decompress using less memory, at the expense of
1145speed. 1183speed.
1146 1184
1147For reasons explained below, @code{bzRead} will decompress the 1185For reasons explained below, @code{BZ2_bzRead} will decompress the
1148@code{nUnused} bytes starting at @code{unused}, before starting to read 1186@code{nUnused} bytes starting at @code{unused}, before starting to read
1149from the file @code{f}. At most @code{BZ_MAX_UNUSED} bytes may be 1187from the file @code{f}. At most @code{BZ_MAX_UNUSED} bytes may be
1150supplied like this. If this facility is not required, you should pass 1188supplied like this. If this facility is not required, you should pass
@@ -1152,15 +1190,17 @@ supplied like this. If this facility is not required, you should pass
1152respectively. 1190respectively.
1153 1191
1154For the meaning of parameters @code{small} and @code{verbosity}, 1192For the meaning of parameters @code{small} and @code{verbosity},
1155see @code{bzDecompressInit}. 1193see @code{BZ2_bzDecompressInit}.
1156 1194
1157The amount of memory needed to decompress a file cannot be determined 1195The amount of memory needed to decompress a file cannot be determined
1158until the file's header has been read. So it is possible that 1196until the file's header has been read. So it is possible that
1159@code{bzReadOpen} returns @code{BZ_OK} but a subsequent call of 1197@code{BZ2_bzReadOpen} returns @code{BZ_OK} but a subsequent call of
1160@code{bzRead} will return @code{BZ_MEM_ERROR}. 1198@code{BZ2_bzRead} will return @code{BZ_MEM_ERROR}.
1161 1199
1162Possible assignments to @code{bzerror}: 1200Possible assignments to @code{bzerror}:
1163@display 1201@display
1202 @code{BZ_CONFIG_ERROR}
1203 if the library has been mis-compiled
1164 @code{BZ_PARAM_ERROR} 1204 @code{BZ_PARAM_ERROR}
1165 if @code{f} is @code{NULL} 1205 if @code{f} is @code{NULL}
1166 or @code{small} is neither @code{0} nor @code{1} 1206 or @code{small} is neither @code{0} nor @code{1}
@@ -1184,16 +1224,16 @@ Possible return values:
1184 1224
1185Allowable next actions: 1225Allowable next actions:
1186@display 1226@display
1187 @code{bzRead} 1227 @code{BZ2_bzRead}
1188 if @code{bzerror} is @code{BZ_OK} 1228 if @code{bzerror} is @code{BZ_OK}
1189 @code{bzClose} 1229 @code{BZ2_bzClose}
1190 otherwise 1230 otherwise
1191@end display 1231@end display
1192 1232
1193 1233
1194@subsection @code{bzRead} 1234@subsection @code{BZ2_bzRead}
1195@example 1235@example
1196 int bzRead ( int *bzerror, BZFILE *b, void *buf, int len ); 1236 int BZ2_bzRead ( int *bzerror, BZFILE *b, void *buf, int len );
1197@end example 1237@end example
1198Reads up to @code{len} (uncompressed) bytes from the compressed file 1238Reads up to @code{len} (uncompressed) bytes from the compressed file
1199@code{b} into 1239@code{b} into
@@ -1204,7 +1244,7 @@ was detected, @code{bzerror} will be set to @code{BZ_STREAM_END},
1204and the number 1244and the number
1205of bytes read is returned. All other @code{bzerror} values denote an error. 1245of bytes read is returned. All other @code{bzerror} values denote an error.
1206 1246
1207@code{bzRead} will supply @code{len} bytes, 1247@code{BZ2_bzRead} will supply @code{len} bytes,
1208unless the logical stream end is detected 1248unless the logical stream end is detected
1209or an error occurs. Because of this, it is possible to detect the 1249or an error occurs. Because of this, it is possible to detect the
1210stream end by observing when the number of bytes returned is 1250stream end by observing when the number of bytes returned is
@@ -1213,20 +1253,20 @@ requested. Nevertheless, this is regarded as inadvisable; you should
1213instead check @code{bzerror} after every call and watch out for 1253instead check @code{bzerror} after every call and watch out for
1214@code{BZ_STREAM_END}. 1254@code{BZ_STREAM_END}.
1215 1255
1216Internally, @code{bzRead} copies data from the compressed file in chunks 1256Internally, @code{BZ2_bzRead} copies data from the compressed file in chunks
1217of size @code{BZ_MAX_UNUSED} bytes 1257of size @code{BZ_MAX_UNUSED} bytes
1218before decompressing it. If the file contains more bytes than strictly 1258before decompressing it. If the file contains more bytes than strictly
1219needed to reach the logical end-of-stream, @code{bzRead} will almost certainly 1259needed to reach the logical end-of-stream, @code{BZ2_bzRead} will almost certainly
1220read some of the trailing data before signalling @code{BZ_SEQUENCE_END}. 1260read some of the trailing data before signalling @code{BZ_SEQUENCE_END}.
1221To collect the read but unused data once @code{BZ_SEQUENCE_END} has 1261To collect the read but unused data once @code{BZ_SEQUENCE_END} has
1222appeared, call @code{bzReadGetUnused} immediately before @code{bzReadClose}. 1262appeared, call @code{BZ2_bzReadGetUnused} immediately before @code{BZ2_bzReadClose}.
1223 1263
1224Possible assignments to @code{bzerror}: 1264Possible assignments to @code{bzerror}:
1225@display 1265@display
1226 @code{BZ_PARAM_ERROR} 1266 @code{BZ_PARAM_ERROR}
1227 if @code{b} is @code{NULL} or @code{buf} is @code{NULL} or @code{len < 0} 1267 if @code{b} is @code{NULL} or @code{buf} is @code{NULL} or @code{len < 0}
1228 @code{BZ_SEQUENCE_ERROR} 1268 @code{BZ_SEQUENCE_ERROR}
1229 if @code{b} was opened with @code{bzWriteOpen} 1269 if @code{b} was opened with @code{BZ2_bzWriteOpen}
1230 @code{BZ_IO_ERROR} 1270 @code{BZ_IO_ERROR}
1231 if there is an error reading from the compressed file 1271 if there is an error reading from the compressed file
1232 @code{BZ_UNEXPECTED_EOF} 1272 @code{BZ_UNEXPECTED_EOF}
@@ -1254,28 +1294,28 @@ Possible return values:
1254 1294
1255Allowable next actions: 1295Allowable next actions:
1256@display 1296@display
1257 collect data from @code{buf}, then @code{bzRead} or @code{bzReadClose} 1297 collect data from @code{buf}, then @code{BZ2_bzRead} or @code{BZ2_bzReadClose}
1258 if @code{bzerror} is @code{BZ_OK} 1298 if @code{bzerror} is @code{BZ_OK}
1259 collect data from @code{buf}, then @code{bzReadClose} or @code{bzReadGetUnused} 1299 collect data from @code{buf}, then @code{BZ2_bzReadClose} or @code{BZ2_bzReadGetUnused}
1260 if @code{bzerror} is @code{BZ_SEQUENCE_END} 1300 if @code{bzerror} is @code{BZ_SEQUENCE_END}
1261 @code{bzReadClose} 1301 @code{BZ2_bzReadClose}
1262 otherwise 1302 otherwise
1263@end display 1303@end display
1264 1304
1265 1305
1266 1306
1267@subsection @code{bzReadGetUnused} 1307@subsection @code{BZ2_bzReadGetUnused}
1268@example 1308@example
1269 void bzReadGetUnused ( int* bzerror, BZFILE *b, 1309 void BZ2_bzReadGetUnused ( int* bzerror, BZFILE *b,
1270 void** unused, int* nUnused ); 1310 void** unused, int* nUnused );
1271@end example 1311@end example
1272Returns data which was read from the compressed file but was not needed 1312Returns data which was read from the compressed file but was not needed
1273to get to the logical end-of-stream. @code{*unused} is set to the address 1313to get to the logical end-of-stream. @code{*unused} is set to the address
1274of the data, and @code{*nUnused} to the number of bytes. @code{*nUnused} will 1314of the data, and @code{*nUnused} to the number of bytes. @code{*nUnused} will
1275be set to a value between @code{0} and @code{BZ_MAX_UNUSED} inclusive. 1315be set to a value between @code{0} and @code{BZ_MAX_UNUSED} inclusive.
1276 1316
1277This function may only be called once @code{bzRead} has signalled 1317This function may only be called once @code{BZ2_bzRead} has signalled
1278@code{BZ_STREAM_END} but before @code{bzReadClose}. 1318@code{BZ_STREAM_END} but before @code{BZ2_bzReadClose}.
1279 1319
1280Possible assignments to @code{bzerror}: 1320Possible assignments to @code{bzerror}:
1281@display 1321@display
@@ -1284,31 +1324,31 @@ Possible assignments to @code{bzerror}:
1284 or @code{unused} is @code{NULL} or @code{nUnused} is @code{NULL} 1324 or @code{unused} is @code{NULL} or @code{nUnused} is @code{NULL}
1285 @code{BZ_SEQUENCE_ERROR} 1325 @code{BZ_SEQUENCE_ERROR}
1286 if @code{BZ_STREAM_END} has not been signalled 1326 if @code{BZ_STREAM_END} has not been signalled
1287 or if @code{b} was opened with @code{bzWriteOpen} 1327 or if @code{b} was opened with @code{BZ2_bzWriteOpen}
1288 @code{BZ_OK} 1328 @code{BZ_OK}
1289 otherwise 1329 otherwise
1290@end display 1330@end display
1291 1331
1292Allowable next actions: 1332Allowable next actions:
1293@display 1333@display
1294 @code{bzReadClose} 1334 @code{BZ2_bzReadClose}
1295@end display 1335@end display
1296 1336
1297 1337
1298@subsection @code{bzReadClose} 1338@subsection @code{BZ2_bzReadClose}
1299@example 1339@example
1300 void bzReadClose ( int *bzerror, BZFILE *b ); 1340 void BZ2_bzReadClose ( int *bzerror, BZFILE *b );
1301@end example 1341@end example
1302Releases all memory pertaining to the compressed file @code{b}. 1342Releases all memory pertaining to the compressed file @code{b}.
1303@code{bzReadClose} does not call @code{fclose} on the underlying file 1343@code{BZ2_bzReadClose} does not call @code{fclose} on the underlying file
1304handle, so you should do that yourself if appropriate. 1344handle, so you should do that yourself if appropriate.
1305@code{bzReadClose} should be called to clean up after all error 1345@code{BZ2_bzReadClose} should be called to clean up after all error
1306situations. 1346situations.
1307 1347
1308Possible assignments to @code{bzerror}: 1348Possible assignments to @code{bzerror}:
1309@display 1349@display
1310 @code{BZ_SEQUENCE_ERROR} 1350 @code{BZ_SEQUENCE_ERROR}
1311 if @code{b} was opened with @code{bzOpenWrite} 1351 if @code{b} was opened with @code{BZ2_bzOpenWrite}
1312 @code{BZ_OK} 1352 @code{BZ_OK}
1313 otherwise 1353 otherwise
1314@end display 1354@end display
@@ -1320,11 +1360,11 @@ Allowable next actions:
1320 1360
1321 1361
1322 1362
1323@subsection @code{bzWriteOpen} 1363@subsection @code{BZ2_bzWriteOpen}
1324@example 1364@example
1325 BZFILE *bzWriteOpen ( int *bzerror, FILE *f, 1365 BZFILE *BZ2_bzWriteOpen ( int *bzerror, FILE *f,
1326 int blockSize100k, int verbosity, 1366 int blockSize100k, int verbosity,
1327 int workFactor ); 1367 int workFactor );
1328@end example 1368@end example
1329Prepare to write compressed data to file handle @code{f}. 1369Prepare to write compressed data to file handle @code{f}.
1330@code{f} should refer to 1370@code{f} should refer to
@@ -1333,14 +1373,16 @@ indicator (@code{ferror(f)})is not set.
1333 1373
1334For the meaning of parameters @code{blockSize100k}, 1374For the meaning of parameters @code{blockSize100k},
1335@code{verbosity} and @code{workFactor}, see 1375@code{verbosity} and @code{workFactor}, see
1336@* @code{bzCompressInit}. 1376@* @code{BZ2_bzCompressInit}.
1337 1377
1338All required memory is allocated at this stage, so if the call 1378All required memory is allocated at this stage, so if the call
1339completes successfully, @code{BZ_MEM_ERROR} cannot be signalled by a 1379completes successfully, @code{BZ_MEM_ERROR} cannot be signalled by a
1340subsequent call to @code{bzWrite}. 1380subsequent call to @code{BZ2_bzWrite}.
1341 1381
1342Possible assignments to @code{bzerror}: 1382Possible assignments to @code{bzerror}:
1343@display 1383@display
1384 @code{BZ_CONFIG_ERROR}
1385 if the library has been mis-compiled
1344 @code{BZ_PARAM_ERROR} 1386 @code{BZ_PARAM_ERROR}
1345 if @code{f} is @code{NULL} 1387 if @code{f} is @code{NULL}
1346 or @code{blockSize100k < 1} or @code{blockSize100k > 9} 1388 or @code{blockSize100k < 1} or @code{blockSize100k > 9}
@@ -1362,18 +1404,18 @@ Possible return values:
1362 1404
1363Allowable next actions: 1405Allowable next actions:
1364@display 1406@display
1365 @code{bzWrite} 1407 @code{BZ2_bzWrite}
1366 if @code{bzerror} is @code{BZ_OK} 1408 if @code{bzerror} is @code{BZ_OK}
1367 (you could go directly to @code{bzWriteClose}, but this would be pretty pointless) 1409 (you could go directly to @code{BZ2_bzWriteClose}, but this would be pretty pointless)
1368 @code{bzWriteClose} 1410 @code{BZ2_bzWriteClose}
1369 otherwise 1411 otherwise
1370@end display 1412@end display
1371 1413
1372 1414
1373 1415
1374@subsection @code{bzWrite} 1416@subsection @code{BZ2_bzWrite}
1375@example 1417@example
1376 void bzWrite ( int *bzerror, BZFILE *b, void *buf, int len ); 1418 void BZ2_bzWrite ( int *bzerror, BZFILE *b, void *buf, int len );
1377@end example 1419@end example
1378Absorbs @code{len} bytes from the buffer @code{buf}, eventually to be 1420Absorbs @code{len} bytes from the buffer @code{buf}, eventually to be
1379compressed and written to the file. 1421compressed and written to the file.
@@ -1383,7 +1425,7 @@ Possible assignments to @code{bzerror}:
1383 @code{BZ_PARAM_ERROR} 1425 @code{BZ_PARAM_ERROR}
1384 if @code{b} is @code{NULL} or @code{buf} is @code{NULL} or @code{len < 0} 1426 if @code{b} is @code{NULL} or @code{buf} is @code{NULL} or @code{len < 0}
1385 @code{BZ_SEQUENCE_ERROR} 1427 @code{BZ_SEQUENCE_ERROR}
1386 if b was opened with @code{bzReadOpen} 1428 if b was opened with @code{BZ2_bzReadOpen}
1387 @code{BZ_IO_ERROR} 1429 @code{BZ_IO_ERROR}
1388 if there is an error writing the compressed file. 1430 if there is an error writing the compressed file.
1389 @code{BZ_OK} 1431 @code{BZ_OK}
@@ -1393,22 +1435,29 @@ Possible assignments to @code{bzerror}:
1393 1435
1394 1436
1395 1437
1396@subsection @code{bzWriteClose} 1438@subsection @code{BZ2_bzWriteClose}
1397@example 1439@example
1398 int bzWriteClose ( int *bzerror, BZFILE* f, 1440 void BZ2_bzWriteClose ( int *bzerror, BZFILE* f,
1399 int abandon, 1441 int abandon,
1400 unsigned int* nbytes_in, 1442 unsigned int* nbytes_in,
1401 unsigned int* nbytes_out ); 1443 unsigned int* nbytes_out );
1444
1445 void BZ2_bzWriteClose64 ( int *bzerror, BZFILE* f,
1446 int abandon,
1447 unsigned int* nbytes_in_lo32,
1448 unsigned int* nbytes_in_hi32,
1449 unsigned int* nbytes_out_lo32,
1450 unsigned int* nbytes_out_hi32 );
1402@end example 1451@end example
1403 1452
1404Compresses and flushes to the compressed file all data so far supplied 1453Compresses and flushes to the compressed file all data so far supplied
1405by @code{bzWrite}. The logical end-of-stream markers are also written, so 1454by @code{BZ2_bzWrite}. The logical end-of-stream markers are also written, so
1406subsequent calls to @code{bzWrite} are illegal. All memory associated 1455subsequent calls to @code{BZ2_bzWrite} are illegal. All memory associated
1407with the compressed file @code{b} is released. 1456with the compressed file @code{b} is released.
1408@code{fflush} is called on the 1457@code{fflush} is called on the
1409compressed file, but it is not @code{fclose}'d. 1458compressed file, but it is not @code{fclose}'d.
1410 1459
1411If @code{bzWriteClose} is called to clean up after an error, the only 1460If @code{BZ2_bzWriteClose} is called to clean up after an error, the only
1412action is to release the memory. The library records the error codes 1461action is to release the memory. The library records the error codes
1413issued by previous calls, so this situation will be detected 1462issued by previous calls, so this situation will be detected
1414automatically. There is no attempt to complete the compression 1463automatically. There is no attempt to complete the compression
@@ -1418,12 +1467,17 @@ value to @code{abandon}.
1418 1467
1419If @code{nbytes_in} is non-null, @code{*nbytes_in} will be set to be the 1468If @code{nbytes_in} is non-null, @code{*nbytes_in} will be set to be the
1420total volume of uncompressed data handled. Similarly, @code{nbytes_out} 1469total volume of uncompressed data handled. Similarly, @code{nbytes_out}
1421will be set to the total volume of compressed data written. 1470will be set to the total volume of compressed data written. For
1471compatibility with older versions of the library, @code{BZ2_bzWriteClose}
1472only yields the lower 32 bits of these counts. Use
1473@code{BZ2_bzWriteClose64} if you want the full 64 bit counts. These
1474two functions are otherwise absolutely identical.
1475
1422 1476
1423Possible assignments to @code{bzerror}: 1477Possible assignments to @code{bzerror}:
1424@display 1478@display
1425 @code{BZ_SEQUENCE_ERROR} 1479 @code{BZ_SEQUENCE_ERROR}
1426 if @code{b} was opened with @code{bzReadOpen} 1480 if @code{b} was opened with @code{BZ2_bzReadOpen}
1427 @code{BZ_IO_ERROR} 1481 @code{BZ_IO_ERROR}
1428 if there is an error writing the compressed file 1482 if there is an error writing the compressed file
1429 @code{BZ_OK} 1483 @code{BZ_OK}
@@ -1442,26 +1496,26 @@ The calling application can write its own data before and after the
1442compressed data stream, using that same file handle. 1496compressed data stream, using that same file handle.
1443@item Reading is more complex, and the facilities are not as general 1497@item Reading is more complex, and the facilities are not as general
1444as they could be since generality is hard to reconcile with efficiency. 1498as they could be since generality is hard to reconcile with efficiency.
1445@code{bzRead} reads from the compressed file in blocks of size 1499@code{BZ2_bzRead} reads from the compressed file in blocks of size
1446@code{BZ_MAX_UNUSED} bytes, and in doing so probably will overshoot 1500@code{BZ_MAX_UNUSED} bytes, and in doing so probably will overshoot
1447the logical end of compressed stream. 1501the logical end of compressed stream.
1448To recover this data once decompression has 1502To recover this data once decompression has
1449ended, call @code{bzReadGetUnused} after the last call of @code{bzRead} 1503ended, call @code{BZ2_bzReadGetUnused} after the last call of @code{BZ2_bzRead}
1450(the one returning @code{BZ_STREAM_END}) but before calling 1504(the one returning @code{BZ_STREAM_END}) but before calling
1451@code{bzReadClose}. 1505@code{BZ2_bzReadClose}.
1452@end itemize 1506@end itemize
1453 1507
1454This mechanism makes it easy to decompress multiple @code{bzip2} 1508This mechanism makes it easy to decompress multiple @code{bzip2}
1455streams placed end-to-end. As the end of one stream, when @code{bzRead} 1509streams placed end-to-end. As the end of one stream, when @code{BZ2_bzRead}
1456returns @code{BZ_STREAM_END}, call @code{bzReadGetUnused} to collect the 1510returns @code{BZ_STREAM_END}, call @code{BZ2_bzReadGetUnused} to collect the
1457unused data (copy it into your own buffer somewhere). 1511unused data (copy it into your own buffer somewhere).
1458That data forms the start of the next compressed stream. 1512That data forms the start of the next compressed stream.
1459To start uncompressing that next stream, call @code{bzReadOpen} again, 1513To start uncompressing that next stream, call @code{BZ2_bzReadOpen} again,
1460feeding in the unused data via the @code{unused}/@code{nUnused} 1514feeding in the unused data via the @code{unused}/@code{nUnused}
1461parameters. 1515parameters.
1462Keep doing this until @code{BZ_STREAM_END} return coincides with the 1516Keep doing this until @code{BZ_STREAM_END} return coincides with the
1463physical end of file (@code{feof(f)}). In this situation 1517physical end of file (@code{feof(f)}). In this situation
1464@code{bzReadGetUnused} 1518@code{BZ2_bzReadGetUnused}
1465will of course return no data. 1519will of course return no data.
1466 1520
1467This should give some feel for how the high-level interface can be used. 1521This should give some feel for how the high-level interface can be used.
@@ -1482,22 +1536,22 @@ f = fopen ( "myfile.bz2", "w" );
1482if (!f) @{ 1536if (!f) @{
1483 /* handle error */ 1537 /* handle error */
1484@} 1538@}
1485b = bzWriteOpen ( &bzerror, f, 9 ); 1539b = BZ2_bzWriteOpen ( &bzerror, f, 9 );
1486if (bzerror != BZ_OK) @{ 1540if (bzerror != BZ_OK) @{
1487 bzWriteClose ( b ); 1541 BZ2_bzWriteClose ( b );
1488 /* handle error */ 1542 /* handle error */
1489@} 1543@}
1490 1544
1491while ( /* condition */ ) @{ 1545while ( /* condition */ ) @{
1492 /* get data to write into buf, and set nBuf appropriately */ 1546 /* get data to write into buf, and set nBuf appropriately */
1493 nWritten = bzWrite ( &bzerror, b, buf, nBuf ); 1547 nWritten = BZ2_bzWrite ( &bzerror, b, buf, nBuf );
1494 if (bzerror == BZ_IO_ERROR) @{ 1548 if (bzerror == BZ_IO_ERROR) @{
1495 bzWriteClose ( &bzerror, b ); 1549 BZ2_bzWriteClose ( &bzerror, b );
1496 /* handle error */ 1550 /* handle error */
1497 @} 1551 @}
1498@} 1552@}
1499 1553
1500bzWriteClose ( &bzerror, b ); 1554BZ2_bzWriteClose ( &bzerror, b );
1501if (bzerror == BZ_IO_ERROR) @{ 1555if (bzerror == BZ_IO_ERROR) @{
1502 /* handle error */ 1556 /* handle error */
1503@} 1557@}
@@ -1515,39 +1569,39 @@ f = fopen ( "myfile.bz2", "r" );
1515if (!f) @{ 1569if (!f) @{
1516 /* handle error */ 1570 /* handle error */
1517@} 1571@}
1518b = bzReadOpen ( &bzerror, f, 0, NULL, 0 ); 1572b = BZ2_bzReadOpen ( &bzerror, f, 0, NULL, 0 );
1519if (bzerror != BZ_OK) @{ 1573if (bzerror != BZ_OK) @{
1520 bzReadClose ( &bzerror, b ); 1574 BZ2_bzReadClose ( &bzerror, b );
1521 /* handle error */ 1575 /* handle error */
1522@} 1576@}
1523 1577
1524bzerror = BZ_OK; 1578bzerror = BZ_OK;
1525while (bzerror == BZ_OK && /* arbitrary other conditions */) @{ 1579while (bzerror == BZ_OK && /* arbitrary other conditions */) @{
1526 nBuf = bzRead ( &bzerror, b, buf, /* size of buf */ ); 1580 nBuf = BZ2_bzRead ( &bzerror, b, buf, /* size of buf */ );
1527 if (bzerror == BZ_OK) @{ 1581 if (bzerror == BZ_OK) @{
1528 /* do something with buf[0 .. nBuf-1] */ 1582 /* do something with buf[0 .. nBuf-1] */
1529 @} 1583 @}
1530@} 1584@}
1531if (bzerror != BZ_STREAM_END) @{ 1585if (bzerror != BZ_STREAM_END) @{
1532 bzReadClose ( &bzerror, b ); 1586 BZ2_bzReadClose ( &bzerror, b );
1533 /* handle error */ 1587 /* handle error */
1534@} else @{ 1588@} else @{
1535 bzReadClose ( &bzerror ); 1589 BZ2_bzReadClose ( &bzerror );
1536@} 1590@}
1537@end example 1591@end example
1538 1592
1539 1593
1540 1594
1541@section Utility functions 1595@section Utility functions
1542@subsection @code{bzBuffToBuffCompress} 1596@subsection @code{BZ2_bzBuffToBuffCompress}
1543@example 1597@example
1544 int bzBuffToBuffCompress( char* dest, 1598 int BZ2_bzBuffToBuffCompress( char* dest,
1545 unsigned int* destLen, 1599 unsigned int* destLen,
1546 char* source, 1600 char* source,
1547 unsigned int sourceLen, 1601 unsigned int sourceLen,
1548 int blockSize100k, 1602 int blockSize100k,
1549 int verbosity, 1603 int verbosity,
1550 int workFactor ); 1604 int workFactor );
1551@end example 1605@end example
1552Attempts to compress the data in @code{source[0 .. sourceLen-1]} 1606Attempts to compress the data in @code{source[0 .. sourceLen-1]}
1553into the destination buffer, @code{dest[0 .. *destLen-1]}. 1607into the destination buffer, @code{dest[0 .. *destLen-1]}.
@@ -1563,17 +1617,19 @@ additional calls to provide extra input data. If you want that kind of
1563mechanism, use the low-level interface. 1617mechanism, use the low-level interface.
1564 1618
1565For the meaning of parameters @code{blockSize100k}, @code{verbosity} 1619For the meaning of parameters @code{blockSize100k}, @code{verbosity}
1566and @code{workFactor}, @* see @code{bzCompressInit}. 1620and @code{workFactor}, @* see @code{BZ2_bzCompressInit}.
1567 1621
1568To guarantee that the compressed data will fit in its buffer, allocate 1622To guarantee that the compressed data will fit in its buffer, allocate
1569an output buffer of size 1% larger than the uncompressed data, plus 1623an output buffer of size 1% larger than the uncompressed data, plus
1570six hundred extra bytes. 1624six hundred extra bytes.
1571 1625
1572@code{bzBuffToBuffDecompress} will not write data at or 1626@code{BZ2_bzBuffToBuffDecompress} will not write data at or
1573beyond @code{dest[*destLen]}, even in case of buffer overflow. 1627beyond @code{dest[*destLen]}, even in case of buffer overflow.
1574 1628
1575Possible return values: 1629Possible return values:
1576@display 1630@display
1631 @code{BZ_CONFIG_ERROR}
1632 if the library has been mis-compiled
1577 @code{BZ_PARAM_ERROR} 1633 @code{BZ_PARAM_ERROR}
1578 if @code{dest} is @code{NULL} or @code{destLen} is @code{NULL} 1634 if @code{dest} is @code{NULL} or @code{destLen} is @code{NULL}
1579 or @code{blockSize100k < 1} or @code{blockSize100k > 9} 1635 or @code{blockSize100k < 1} or @code{blockSize100k > 9}
@@ -1589,14 +1645,14 @@ Possible return values:
1589 1645
1590 1646
1591 1647
1592@subsection @code{bzBuffToBuffDecompress} 1648@subsection @code{BZ2_bzBuffToBuffDecompress}
1593@example 1649@example
1594 int bzBuffToBuffDecompress ( char* dest, 1650 int BZ2_bzBuffToBuffDecompress ( char* dest,
1595 unsigned int* destLen, 1651 unsigned int* destLen,
1596 char* source, 1652 char* source,
1597 unsigned int sourceLen, 1653 unsigned int sourceLen,
1598 int small, 1654 int small,
1599 int verbosity ); 1655 int verbosity );
1600@end example 1656@end example
1601Attempts to decompress the data in @code{source[0 .. sourceLen-1]} 1657Attempts to decompress the data in @code{source[0 .. sourceLen-1]}
1602into the destination buffer, @code{dest[0 .. *destLen-1]}. 1658into the destination buffer, @code{dest[0 .. *destLen-1]}.
@@ -1606,11 +1662,11 @@ returned. If the compressed data won't fit, @code{*destLen}
1606is unchanged, and @code{BZ_OUTBUFF_FULL} is returned. 1662is unchanged, and @code{BZ_OUTBUFF_FULL} is returned.
1607 1663
1608@code{source} is assumed to hold a complete @code{bzip2} format 1664@code{source} is assumed to hold a complete @code{bzip2} format
1609data stream. @code{bzBuffToBuffDecompress} tries to decompress 1665data stream. @* @code{BZ2_bzBuffToBuffDecompress} tries to decompress
1610the entirety of the stream into the output buffer. 1666the entirety of the stream into the output buffer.
1611 1667
1612For the meaning of parameters @code{small} and @code{verbosity}, 1668For the meaning of parameters @code{small} and @code{verbosity},
1613see @code{bzDecompressInit}. 1669see @code{BZ2_bzDecompressInit}.
1614 1670
1615Because the compression ratio of the compressed data cannot be known in 1671Because the compression ratio of the compressed data cannot be known in
1616advance, there is no easy way to guarantee that the output buffer will 1672advance, there is no easy way to guarantee that the output buffer will
@@ -1618,11 +1674,13 @@ be big enough. You may of course make arrangements in your code to
1618record the size of the uncompressed data, but such a mechanism is beyond 1674record the size of the uncompressed data, but such a mechanism is beyond
1619the scope of this library. 1675the scope of this library.
1620 1676
1621@code{bzBuffToBuffDecompress} will not write data at or 1677@code{BZ2_bzBuffToBuffDecompress} will not write data at or
1622beyond @code{dest[*destLen]}, even in case of buffer overflow. 1678beyond @code{dest[*destLen]}, even in case of buffer overflow.
1623 1679
1624Possible return values: 1680Possible return values:
1625@display 1681@display
1682 @code{BZ_CONFIG_ERROR}
1683 if the library has been mis-compiled
1626 @code{BZ_PARAM_ERROR} 1684 @code{BZ_PARAM_ERROR}
1627 if @code{dest} is @code{NULL} or @code{destLen} is @code{NULL} 1685 if @code{dest} is @code{NULL} or @code{destLen} is @code{NULL}
1628 or @code{small != 0 && small != 1} 1686 or @code{small != 0 && small != 1}
@@ -1646,40 +1704,40 @@ Possible return values:
1646@section @code{zlib} compatibility functions 1704@section @code{zlib} compatibility functions
1647Yoshioka Tsuneo has contributed some functions to 1705Yoshioka Tsuneo has contributed some functions to
1648give better @code{zlib} compatibility. These functions are 1706give better @code{zlib} compatibility. These functions are
1649@code{bzopen}, @code{bzread}, @code{bzwrite}, @code{bzflush}, 1707@code{BZ2_bzopen}, @code{BZ2_bzread}, @code{BZ2_bzwrite}, @code{BZ2_bzflush},
1650@code{bzclose}, 1708@code{BZ2_bzclose},
1651@code{bzerror} and @code{bzlibVersion}. 1709@code{BZ2_bzerror} and @code{BZ2_bzlibVersion}.
1652These functions are not (yet) officially part of 1710These functions are not (yet) officially part of
1653the library. If they break, you get to keep all the pieces. 1711the library. If they break, you get to keep all the pieces.
1654Nevertheless, I think they work ok. 1712Nevertheless, I think they work ok.
1655@example 1713@example
1656typedef void BZFILE; 1714typedef void BZFILE;
1657 1715
1658const char * bzlibVersion ( void ); 1716const char * BZ2_bzlibVersion ( void );
1659@end example 1717@end example
1660Returns a string indicating the library version. 1718Returns a string indicating the library version.
1661@example 1719@example
1662BZFILE * bzopen ( const char *path, const char *mode ); 1720BZFILE * BZ2_bzopen ( const char *path, const char *mode );
1663BZFILE * bzdopen ( int fd, const char *mode ); 1721BZFILE * BZ2_bzdopen ( int fd, const char *mode );
1664@end example 1722@end example
1665Opens a @code{.bz2} file for reading or writing, using either its name 1723Opens a @code{.bz2} file for reading or writing, using either its name
1666or a pre-existing file descriptor. 1724or a pre-existing file descriptor.
1667Analogous to @code{fopen} and @code{fdopen}. 1725Analogous to @code{fopen} and @code{fdopen}.
1668@example 1726@example
1669int bzread ( BZFILE* b, void* buf, int len ); 1727int BZ2_bzread ( BZFILE* b, void* buf, int len );
1670int bzwrite ( BZFILE* b, void* buf, int len ); 1728int BZ2_bzwrite ( BZFILE* b, void* buf, int len );
1671@end example 1729@end example
1672Reads/writes data from/to a previously opened @code{BZFILE}. 1730Reads/writes data from/to a previously opened @code{BZFILE}.
1673Analogous to @code{fread} and @code{fwrite}. 1731Analogous to @code{fread} and @code{fwrite}.
1674@example 1732@example
1675int bzflush ( BZFILE* b ); 1733int BZ2_bzflush ( BZFILE* b );
1676void bzclose ( BZFILE* b ); 1734void BZ2_bzclose ( BZFILE* b );
1677@end example 1735@end example
1678Flushes/closes a @code{BZFILE}. @code{bzflush} doesn't actually do 1736Flushes/closes a @code{BZFILE}. @code{BZ2_bzflush} doesn't actually do
1679anything. Analogous to @code{fflush} and @code{fclose}. 1737anything. Analogous to @code{fflush} and @code{fclose}.
1680 1738
1681@example 1739@example
1682const char * bzerror ( BZFILE *b, int *errnum ) 1740const char * BZ2_bzerror ( BZFILE *b, int *errnum )
1683@end example 1741@end example
1684Returns a string describing the more recent error status of 1742Returns a string describing the more recent error status of
1685@code{b}, and also sets @code{*errnum} to its numerical value. 1743@code{b}, and also sets @code{*errnum} to its numerical value.
@@ -1695,9 +1753,9 @@ by compiling the library with preprocessor symbol @code{BZ_NO_STDIO}
1695defined. Doing this gives you a library containing only the following 1753defined. Doing this gives you a library containing only the following
1696eight functions: 1754eight functions:
1697 1755
1698@code{bzCompressInit}, @code{bzCompress}, @code{bzCompressEnd} @* 1756@code{BZ2_bzCompressInit}, @code{BZ2_bzCompress}, @code{BZ2_bzCompressEnd} @*
1699@code{bzDecompressInit}, @code{bzDecompress}, @code{bzDecompressEnd} @* 1757@code{BZ2_bzDecompressInit}, @code{BZ2_bzDecompress}, @code{BZ2_bzDecompressEnd} @*
1700@code{bzBuffToBuffCompress}, @code{bzBuffToBuffDecompress} 1758@code{BZ2_bzBuffToBuffCompress}, @code{BZ2_bzBuffToBuffDecompress}
1701 1759
1702When compiled like this, all functions will ignore @code{verbosity} 1760When compiled like this, all functions will ignore @code{verbosity}
1703settings. 1761settings.
@@ -1710,14 +1768,14 @@ was compiled with @code{BZ_NO_STDIO} set.
1710 1768
1711For a normal compile, an assertion failure yields the message 1769For a normal compile, an assertion failure yields the message
1712@example 1770@example
1713 bzip2/libbzip2, v0.9.5: internal error number N. 1771 bzip2/libbzip2: internal error number N.
1714 This is a bug in bzip2/libbzip2, v0.9.5. Please report 1772 This is a bug in bzip2/libbzip2, 1.0 of 21-Mar-2000.
1715 it to me at: jseward@@acm.org. If this happened when 1773 Please report it to me at: jseward@@acm.org. If this happened
1716 you were using some program which uses libbzip2 as a 1774 when you were using some program which uses libbzip2 as a
1717 component, you should also report this bug to the author(s) 1775 component, you should also report this bug to the author(s)
1718 of that program. Please make an effort to report this bug; 1776 of that program. Please make an effort to report this bug;
1719 timely and accurate bug reports eventually lead to higher 1777 timely and accurate bug reports eventually lead to higher
1720 quality software. Thanks. Julian Seward, 24 May 1999. 1778 quality software. Thanks. Julian Seward, 21 March 2000.
1721@end example 1779@end example
1722where @code{N} is some error code number. @code{exit(3)} 1780where @code{N} is some error code number. @code{exit(3)}
1723is then called. 1781is then called.
@@ -1781,7 +1839,7 @@ These are just some random thoughts of mine. Your mileage may
1781vary. 1839vary.
1782 1840
1783@section Limitations of the compressed file format 1841@section Limitations of the compressed file format
1784@code{bzip2-0.9.5} and @code{0.9.0} 1842@code{bzip2-1.0}, @code{0.9.5} and @code{0.9.0}
1785use exactly the same file format as the previous 1843use exactly the same file format as the previous
1786version, @code{bzip2-0.1}. This decision was made in the interests of 1844version, @code{bzip2-0.1}. This decision was made in the interests of
1787stability. Creating yet another incompatible compressed file format 1845stability. Creating yet another incompatible compressed file format
@@ -1860,7 +1918,7 @@ require some careful design of compressed file formats.
1860 1918
1861@section Portability issues 1919@section Portability issues
1862After some consideration, I have decided not to use 1920After some consideration, I have decided not to use
1863GNU @code{autoconf} to configure 0.9.5. 1921GNU @code{autoconf} to configure 0.9.5 or 1.0.
1864 1922
1865@code{autoconf}, admirable and wonderful though it is, 1923@code{autoconf}, admirable and wonderful though it is,
1866mainly assists with portability problems between Unix-like 1924mainly assists with portability problems between Unix-like
@@ -1925,7 +1983,7 @@ If you get problems, try using the flags
1925@code{-O2} @code{-fomit-frame-pointer} @code{-fno-strength-reduce}. 1983@code{-O2} @code{-fomit-frame-pointer} @code{-fno-strength-reduce}.
1926You should specifically @emph{not} use @code{-funroll-loops}. 1984You should specifically @emph{not} use @code{-funroll-loops}.
1927 1985
1928You may notice that the Makefile runs four tests as part of 1986You may notice that the Makefile runs six tests as part of
1929the build process. If the program passes all of these, it's 1987the build process. If the program passes all of these, it's
1930a pretty good (but not 100%) indication that the compiler has 1988a pretty good (but not 100%) indication that the compiler has
1931done its job correctly. 1989done its job correctly.
@@ -2000,6 +2058,7 @@ memory but gets pretty good compression, and has minimal latency,
2000consider Jean-loup 2058consider Jean-loup
2001Gailly's and Mark Adler's work, @code{zlib-1.1.2} and 2059Gailly's and Mark Adler's work, @code{zlib-1.1.2} and
2002@code{gzip-1.2.4}. Look for them at 2060@code{gzip-1.2.4}. Look for them at
2061
2003@code{http://www.cdrom.com/pub/infozip/zlib} and 2062@code{http://www.cdrom.com/pub/infozip/zlib} and
2004@code{http://www.gzip.org} respectively. 2063@code{http://www.gzip.org} respectively.
2005 2064
@@ -2140,7 +2199,14 @@ available from:
2140@example 2199@example
2141http://www.cs.arizona.edu/people/gene/PAPERS/suffix.ps 2200http://www.cs.arizona.edu/people/gene/PAPERS/suffix.ps
2142@end example 2201@end example
2143 2202Finally, the following paper documents some recent investigations
2203I made into the performance of sorting algorithms:
2204@example
2205Julian Seward:
2206 On the Performance of BWT Sorting Algorithms
2207 Proceedings of the IEEE Data Compression Conference 2000
2208 Snowbird, Utah. 28-30 March 2000.
2209@end example
2144 2210
2145 2211
2146@contents 2212@contents