diff options
Diffstat (limited to 'manual.texi')
-rw-r--r-- | manual.texi | 516 |
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 |
5 | This file documents bzip2 version 0.9.5, and associated library | 5 | This file documents bzip2 version 1.0, and associated library |
6 | libbzip2, written by Julian Seward (jseward@acm.org). | 6 | libbzip2, written by Julian Seward (jseward@acm.org). |
7 | 7 | ||
8 | Copyright (C) 1996-1999 Julian R Seward | 8 | Copyright (C) 1996-2000 Julian R Seward |
9 | 9 | ||
10 | Permission is granted to make and distribute verbatim copies of | 10 | Permission is granted to make and distribute verbatim copies of |
11 | this manual provided the copyright notice and this permission notice | 11 | this 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 | ||
45 | This program, @code{bzip2}, | 45 | This program, @code{bzip2}, |
46 | and associated library @code{libbzip2}, are | 46 | and associated library @code{libbzip2}, are |
47 | Copyright (C) 1996-1999 Julian R Seward. All rights reserved. | 47 | Copyright (C) 1996-2000 Julian R Seward. All rights reserved. |
48 | 48 | ||
49 | Redistribution and use in source and binary forms, with or without | 49 | Redistribution and use in source and binary forms, with or without |
50 | modification, are permitted provided that the following conditions | 50 | modification, 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 | ||
89 | PATENTS: To the best of my knowledge, @code{bzip2} does not use any patented | 93 | PATENTS: To the best of my knowledge, @code{bzip2} does not use any patented |
90 | algorithms. However, I do not have the resources available to carry out | 94 | algorithms. 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} | |||
431 | tries hard to detect I/O errors and exit cleanly, but the details of | 435 | tries hard to detect I/O errors and exit cleanly, but the details of |
432 | what the problem is sometimes seem rather misleading. | 436 | what the problem is sometimes seem rather misleading. |
433 | 437 | ||
434 | This manual page pertains to version 0.9.5 of @code{bzip2}. Compressed | 438 | This manual page pertains to version 1.0 of @code{bzip2}. Compressed |
435 | data created by this version is entirely forwards and backwards | 439 | data created by this version is entirely forwards and backwards |
436 | compatible with the previous public releases, versions 0.1pl2 and 0.9.0, | 440 | compatible with the previous public releases, versions 0.1pl2, 0.9.0 and |
437 | but with the following exception: 0.9.0 and above can correctly | 441 | 0.9.5, but with the following exception: 0.9.0 and above can correctly |
438 | decompress multiple concatenated compressed files. 0.1pl2 cannot do | 442 | decompress multiple concatenated compressed files. 0.1pl2 cannot do |
439 | this; it will stop after decompressing just the first file in the | 443 | this; it will stop after decompressing just the first file in the |
440 | stream. | 444 | stream. |
@@ -486,6 +490,10 @@ The structure of @code{libbzip2}'s interfaces is similar to | |||
486 | that of Jean-loup Gailly's and Mark Adler's excellent @code{zlib} | 490 | that of Jean-loup Gailly's and Mark Adler's excellent @code{zlib} |
487 | library. | 491 | library. |
488 | 492 | ||
493 | All externally visible symbols have names beginning @code{BZ2_}. | ||
494 | This is new in version 1.0. The intention is to minimise pollution | ||
495 | of the namespaces of library clients. | ||
496 | |||
489 | @subsection Low-level summary | 497 | @subsection Low-level summary |
490 | 498 | ||
491 | This interface provides services for compressing and decompressing | 499 | This interface provides services for compressing and decompressing |
@@ -498,17 +506,17 @@ The low-level part of the library has no global variables and | |||
498 | is therefore thread-safe. | 506 | is therefore thread-safe. |
499 | 507 | ||
500 | Six routines make up the low level interface: | 508 | Six 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} |
502 | for compression, | 510 | for compression, |
503 | and a corresponding trio @code{bzDecompressInit}, @* @code{bzDecompress} | 511 | and a corresponding trio @code{BZ2_bzDecompressInit}, @* @code{BZ2_bzDecompress} |
504 | and @code{bzDecompressEnd} for decompression. | 512 | and @code{BZ2_bzDecompressEnd} for decompression. |
505 | The @code{*Init} functions allocate | 513 | The @code{*Init} functions allocate |
506 | memory for compression/decompression and do other | 514 | memory for compression/decompression and do other |
507 | initialisations, whilst the @code{*End} functions close down operations | 515 | initialisations, whilst the @code{*End} functions close down operations |
508 | and release memory. | 516 | and release memory. |
509 | 517 | ||
510 | The real work is done by @code{bzCompress} and @code{bzDecompress}. | 518 | The real work is done by @code{BZ2_bzCompress} and @code{BZ2_bzDecompress}. |
511 | These compress/decompress data from a user-supplied input buffer | 519 | These compress and decompress data from a user-supplied input buffer |
512 | to a user-supplied output buffer. These buffers can be any size; | 520 | to a user-supplied output buffer. These buffers can be any size; |
513 | arbitrary quantities of data are handled by making repeated calls | 521 | arbitrary quantities of data are handled by making repeated calls |
514 | to these functions. This is a flexible mechanism allowing a | 522 | to these functions. This is a flexible mechanism allowing a |
@@ -526,10 +534,10 @@ reading files in which the @code{bzip2} data stream is embedded | |||
526 | within some larger-scale file structure, or where there are | 534 | within some larger-scale file structure, or where there are |
527 | multiple @code{bzip2} data streams concatenated end-to-end. | 535 | multiple @code{bzip2} data streams concatenated end-to-end. |
528 | 536 | ||
529 | For reading files, @code{bzReadOpen}, @code{bzRead}, @code{bzReadClose} | 537 | For reading files, @code{BZ2_bzReadOpen}, @code{BZ2_bzRead}, |
530 | and @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 | 539 | writing files, @code{BZ2_bzWriteOpen}, @code{BZ2_bzWrite} and |
532 | available. | 540 | @code{BZ2_bzWriteFinish} are available. |
533 | 541 | ||
534 | As with the low-level library, no global variables are used | 542 | As with the low-level library, no global variables are used |
535 | so the library is per se thread-safe. However, if I/O errors | 543 | so 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 | |||
539 | supports @code{errno} in a multithreaded environment. | 547 | supports @code{errno} in a multithreaded environment. |
540 | 548 | ||
541 | To make the library a little simpler and more portable, | 549 | To 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 |
543 | handles (@code{FILE*}s) which have previously been opened for reading or | 551 | handles (@code{FILE*}s) which have previously been opened for reading or |
544 | writing respectively. That avoids portability problems associated with | 552 | writing respectively. That avoids portability problems associated with |
545 | file operations and file attributes, whilst not being much of an | 553 | file 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 |
551 | For very simple needs, @code{bzBuffToBuffCompress} and | 559 | For very simple needs, @code{BZ2_bzBuffToBuffCompress} and |
552 | @code{bzBuffToBuffDecompress} are provided. These compress | 560 | @code{BZ2_bzBuffToBuffDecompress} are provided. These compress |
553 | data in memory from one buffer to another buffer in a single | 561 | data in memory from one buffer to another buffer in a single |
554 | function call. You should assess whether these functions | 562 | function call. You should assess whether these functions |
555 | fulfill your memory-to-memory compression/decompression | 563 | fulfill your memory-to-memory compression/decompression |
@@ -559,9 +567,9 @@ general but more complex low-level interface. | |||
559 | Yoshioka Tsuneo (@code{QWF00133@@niftyserve.or.jp} / | 567 | Yoshioka 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 |
561 | give better @code{zlib} compatibility. These functions are | 569 | give 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 |
565 | more convenient for simple file reading and writing, than those in the | 573 | more convenient for simple file reading and writing, than those in the |
566 | high-level interface. These functions are not (yet) officially part of | 574 | high-level interface. These functions are not (yet) officially part of |
567 | the library, and are minimally documented here. If they break, you | 575 | the 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 | |||
582 | hearing more about the robustness of the library to corrupted | 590 | hearing more about the robustness of the library to corrupted |
583 | compressed data. | 591 | compressed data. |
584 | 592 | ||
593 | Version 1.0 is much more robust in this respect than | ||
594 | 0.9.0 or 0.9.5. Investigations with Checker (a tool for | ||
595 | detecting problems with memory management, similar to Purify) | ||
596 | indicate that, at least for the few files I tested, all single-bit | ||
597 | errors in the decompressed data are caught properly, with no | ||
598 | segmentation faults, no reads of uninitialised data and no | ||
599 | out of range reads or writes. So it's certainly much improved, | ||
600 | although I wouldn't claim it to be totally bombproof. | ||
601 | |||
585 | The file @code{bzlib.h} contains all definitions needed to use | 602 | The file @code{bzlib.h} contains all definitions needed to use |
586 | the library. In particular, you should definitely not include | 603 | the 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 |
601 | In @code{bzCompress}, the requested flush/finish/nothing-special action | 618 | In @code{BZ2_bzCompress}, the requested flush/finish/nothing-special action |
602 | was completed successfully. | 619 | was completed successfully. |
603 | @item BZ_STREAM_END | 620 | @item BZ_STREAM_END |
604 | Compression of data was completed, or the logical stream end was | 621 | Compression of data was completed, or the logical stream end was |
@@ -607,6 +624,16 @@ detected during decompression. | |||
607 | 624 | ||
608 | The following return values indicate an error of some kind. | 625 | The following return values indicate an error of some kind. |
609 | @table @code | 626 | @table @code |
627 | @item BZ_CONFIG_ERROR | ||
628 | Indicates that the library has been improperly compiled on your | ||
629 | platform -- a major configuration error. Specifically, it means | ||
630 | that @code{sizeof(char)}, @code{sizeof(short)} and @code{sizeof(int)} | ||
631 | are not 1, 2 and 4 respectively, as they should be. Note that the | ||
632 | library should still work properly on 64-bit platforms which follow | ||
633 | the LP64 programming model -- that is, where @code{sizeof(long)} | ||
634 | and @code{sizeof(void*)} are 8. Under LP64, @code{sizeof(int)} is | ||
635 | still 4, so @code{libbzip2}, which doesn't use the @code{long} type, | ||
636 | is OK. | ||
610 | @item BZ_SEQUENCE_ERROR | 637 | @item BZ_SEQUENCE_ERROR |
611 | When using the library, it is important to call the functions in the | 638 | When using the library, it is important to call the functions in the |
612 | correct sequence and with data structures (buffers etc) in the correct | 639 | correct 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 |
625 | Returned when a request to allocate memory failed. Note that the | 652 | Returned when a request to allocate memory failed. Note that the |
626 | quantity of memory needed to decompress a stream cannot be determined | 653 | quantity of memory needed to decompress a stream cannot be determined |
627 | until the stream's header has been read. So @code{bzDecompress} and | 654 | until 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 |
629 | the compressed data has been read. The same is not true for | 656 | the compressed data has been read. The same is not true for |
630 | compression; once @code{bzCompressInit} or @code{bzWriteOpen} have | 657 | compression; once @code{BZ2_bzCompressInit} or @code{BZ2_bzWriteOpen} have |
631 | successfully completed, @code{BZ_MEM_ERROR} cannot occur. | 658 | successfully completed, @code{BZ_MEM_ERROR} cannot occur. |
632 | @item BZ_DATA_ERROR | 659 | @item BZ_DATA_ERROR |
633 | Returned when a data integrity error is detected during decompression. | 660 | Returned 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 | |||
639 | know when the compressed stream does not start with the correct | 666 | know when the compressed stream does not start with the correct |
640 | magic bytes (@code{'B' 'Z' 'h'}). | 667 | magic bytes (@code{'B' 'Z' 'h'}). |
641 | @item BZ_IO_ERROR | 668 | @item BZ_IO_ERROR |
642 | Returned by @code{bzRead} and @code{bzRead} when there is an error | 669 | Returned by @code{BZ2_bzRead} and @code{BZ2_bzWrite} when there is an error |
643 | reading or writing in the compressed file, and by @code{bzReadOpen} | 670 | reading or writing in the compressed file, and by @code{BZ2_bzReadOpen} |
644 | and @code{bzWriteOpen} for attempts to use a file for which the | 671 | and @code{BZ2_bzWriteOpen} for attempts to use a file for which the |
645 | error indicator (viz, @code{ferror(f)}) is set. | 672 | error indicator (viz, @code{ferror(f)}) is set. |
646 | On receipt of @code{BZ_IO_ERROR}, the caller should consult | 673 | On 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 |
648 | specific information about the problem. | 675 | specific information about the problem. |
649 | @item BZ_UNEXPECTED_EOF | 676 | @item BZ_UNEXPECTED_EOF |
650 | Returned by @code{bzRead} when the compressed file finishes | 677 | Returned by @code{BZ2_bzRead} when the compressed file finishes |
651 | before the logical end of stream is detected. | 678 | before the logical end of stream is detected. |
652 | @item BZ_OUTBUFF_FULL | 679 | @item BZ_OUTBUFF_FULL |
653 | Returned by @code{bzBuffToBuffCompress} and | 680 | Returned by @code{BZ2_bzBuffToBuffCompress} and |
654 | @code{bzBuffToBuffDecompress} to indicate that the output data | 681 | @code{BZ2_bzBuffToBuffDecompress} to indicate that the output data |
655 | will not fit into the output buffer provided. | 682 | will 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 |
664 | typedef | 691 | typedef |
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 | ||
682 | int bzCompressInit ( bz_stream *strm, | 711 | int 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}, | |||
712 | and the library will then use the standard @code{malloc}/@code{free} | 741 | and the library will then use the standard @code{malloc}/@code{free} |
713 | routines. | 742 | routines. |
714 | 743 | ||
715 | Before calling @code{bzCompressInit}, fields @code{bzalloc}, | 744 | Before calling @code{BZ2_bzCompressInit}, fields @code{bzalloc}, |
716 | @code{bzfree} and @code{opaque} should | 745 | @code{bzfree} and @code{opaque} should |
717 | be filled appropriately, as just described. Upon return, the internal | 746 | be filled appropriately, as just described. Upon return, the internal |
718 | state will have been allocated and initialised, and @code{total_in} and | 747 | state 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 |
720 | These last two fields are used by the library | 749 | @code{total_out_hi32} will have been set to zero. |
750 | These four fields are used by the library | ||
721 | to inform the caller of the total amount of data passed into and out of | 751 | to inform the caller of the total amount of data passed into and out of |
722 | the library, respectively. You should not try to change them. | 752 | the library, respectively. You should not try to change them. |
753 | As of version 1.0, 64-bit counts are maintained, even on 32-bit | ||
754 | platforms, using the @code{_hi32} fields to store the upper 32 bits | ||
755 | of the count. So, for example, the total amount of data in | ||
756 | is @code{(total_in_hi32 << 32) + total_in_lo32}. | ||
723 | 757 | ||
724 | Parameter @code{blockSize100k} specifies the block size to be used for | 758 | Parameter @code{blockSize100k} specifies the block size to be used for |
725 | compression. It should be a value between 1 and 9 inclusive, and the | 759 | compression. It should be a value between 1 and 9 inclusive, and the |
@@ -761,6 +795,8 @@ mechanism would render the parameter obsolete. | |||
761 | 795 | ||
762 | Possible return values: | 796 | Possible 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 |
774 | Allowable next actions: | 810 | Allowable 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 |
785 | Provides more input and/or output buffer space for the library. The | 821 | Provides more input and/or output buffer space for the library. The |
786 | caller maintains input and output buffers, and calls @code{bzCompress} to | 822 | caller maintains input and output buffers, and calls @code{BZ2_bzCompress} to |
787 | transfer data between them. | 823 | transfer data between them. |
788 | 824 | ||
789 | Before each call to @code{bzCompress}, @code{next_in} should point at | 825 | Before each call to @code{BZ2_bzCompress}, @code{next_in} should point at |
790 | the data to be compressed, and @code{avail_in} should indicate how many | 826 | the data to be compressed, and @code{avail_in} should indicate how many |
791 | bytes the library may read. @code{bzCompress} updates @code{next_in}, | 827 | bytes 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 |
793 | has read. | 829 | has read. |
794 | 830 | ||
795 | Similarly, @code{next_out} should point to a buffer in which the | 831 | Similarly, @code{next_out} should point to a buffer in which the |
796 | compressed data is to be placed, with @code{avail_out} indicating how | 832 | compressed data is to be placed, with @code{avail_out} indicating how |
797 | much output space is available. @code{bzCompress} updates | 833 | much 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 |
799 | number of bytes output. | 835 | number of bytes output. |
800 | 836 | ||
801 | You may provide and remove as little or as much data as you like on each | 837 | You may provide and remove as little or as much data as you like on each |
802 | call of @code{bzCompress}. In the limit, it is acceptable to supply and | 838 | call of @code{BZ2_bzCompress}. In the limit, it is acceptable to supply and |
803 | remove data one byte at a time, although this would be terribly | 839 | remove data one byte at a time, although this would be terribly |
804 | inefficient. You should always ensure that at least one byte of output | 840 | inefficient. You should always ensure that at least one byte of output |
805 | space is available at each call. | 841 | space is available at each call. |
806 | 842 | ||
807 | A second purpose of @code{bzCompress} is to request a change of mode of the | 843 | A second purpose of @code{BZ2_bzCompress} is to request a change of mode of the |
808 | compressed stream. | 844 | compressed stream. |
809 | 845 | ||
810 | Conceptually, a compressed stream can be in one of four states: IDLE, | 846 | Conceptually, a compressed stream can be in one of four states: IDLE, |
811 | RUNNING, FLUSHING and FINISHING. Before initialisation | 847 | RUNNING, 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 |
813 | stream is regarded as IDLE. | 849 | stream is regarded as IDLE. |
814 | 850 | ||
815 | Upon initialisation (@code{bzCompressInit}), the stream is placed in the | 851 | Upon initialisation (@code{BZ2_bzCompressInit}), the stream is placed in the |
816 | RUNNING state. Subsequent calls to @code{bzCompress} should pass | 852 | RUNNING 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 |
818 | will result in @code{BZ_SEQUENCE_ERROR}. | 854 | will result in @code{BZ_SEQUENCE_ERROR}. |
819 | 855 | ||
820 | At some point, the calling program will have provided all the input data | 856 | At some point, the calling program will have provided all the input data |
821 | it wants to. It will then want to finish up -- in effect, asking the | 857 | it wants to. It will then want to finish up -- in effect, asking the |
822 | library to process any data it might have buffered internally. In this | 858 | library to process any data it might have buffered internally. In this |
823 | state, @code{bzCompress} will no longer attempt to read data from | 859 | state, @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}. |
825 | Because the output buffer supplied by the user can be arbitrarily small, | 861 | Because the output buffer supplied by the user can be arbitrarily small, |
826 | the finishing-up operation cannot necessarily be done with a single call | 862 | the finishing-up operation cannot necessarily be done with a single call |
827 | of @code{bzCompress}. | 863 | of @code{BZ2_bzCompress}. |
828 | 864 | ||
829 | Instead, the calling program passes @code{BZ_FINISH} as an action to | 865 | Instead, 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 |
831 | remaining input (ie, @code{next_in[0 .. avail_in-1]}) is compressed and | 867 | remaining input (ie, @code{next_in[0 .. avail_in-1]}) is compressed and |
832 | transferred to the output buffer. To do this, @code{bzCompress} must be | 868 | transferred to the output buffer. To do this, @code{BZ2_bzCompress} must be |
833 | called repeatedly until all the output has been consumed. At that | 869 | called repeatedly until all the output has been consumed. At that |
834 | point, @code{bzCompress} returns @code{BZ_STREAM_END}, and the stream's | 870 | point, @code{BZ2_bzCompress} returns @code{BZ_STREAM_END}, and the stream's |
835 | state is set back to IDLE. @code{bzCompressEnd} should then be | 871 | state is set back to IDLE. @code{BZ2_bzCompressEnd} should then be |
836 | called. | 872 | called. |
837 | 873 | ||
838 | Just to make sure the calling program does not cheat, the library makes | 874 | Just to make sure the calling program does not cheat, the library makes |
839 | a note of @code{avail_in} at the time of the first call to | 875 | a 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 |
841 | time the program has announced its intention to not supply any more | 877 | time the program has announced its intention to not supply any more |
842 | input). By comparing this value with that of @code{avail_in} over | 878 | input). By comparing this value with that of @code{avail_in} over |
843 | subsequent calls to @code{bzCompress}, the library can detect any | 879 | subsequent calls to @code{BZ2_bzCompress}, the library can detect any |
844 | attempts to slip in more data to compress. Any calls for which this is | 880 | attempts to slip in more data to compress. Any calls for which this is |
845 | detected will return @code{BZ_SEQUENCE_ERROR}. This indicates a | 881 | detected will return @code{BZ_SEQUENCE_ERROR}. This indicates a |
846 | programming mistake which should be corrected. | 882 | programming mistake which should be corrected. |
847 | 883 | ||
848 | Instead of asking to finish, the calling program may ask | 884 | Instead 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 |
850 | terminate the current (Burrows-Wheeler) compression block. This could | 886 | terminate the current (Burrows-Wheeler) compression block. This could |
851 | be useful for error control purposes. The mechanism is analogous to | 887 | be useful for error control purposes. The mechanism is analogous to |
852 | that for finishing: call @code{bzCompress} with an action of | 888 | that 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 |
855 | with finishing, @code{bzCompress} detects any attempt to provide more | 891 | with finishing, @code{BZ2_bzCompress} detects any attempt to provide more |
856 | input data once the flush has begun. | 892 | input data once the flush has begun. |
857 | 893 | ||
858 | Once the flush is complete, the stream returns to the normal RUNNING | 894 | Once 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 | |||
863 | will be taken, what the next state is, and what the non-error return | 899 | will be taken, what the next state is, and what the non-error return |
864 | values are. Note that you can't explicitly ask what state the | 900 | values are. Note that you can't explicitly ask what state the |
865 | stream is in, but nor do you need to -- it can be inferred from the | 901 | stream is in, but nor do you need to -- it can be inferred from the |
866 | values returned by @code{bzCompress}. | 902 | values returned by @code{BZ2_bzCompress}. |
867 | @display | 903 | @display |
868 | IDLE/@code{any} | 904 | IDLE/@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 | ||
873 | RUNNING/@code{BZ_RUN} | 909 | RUNNING/@code{BZ_RUN} |
@@ -917,21 +953,21 @@ FINISHING/other | |||
917 | That still looks complicated? Well, fair enough. The usual sequence | 953 | That still looks complicated? Well, fair enough. The usual sequence |
918 | of calls for compressing a load of data is: | 954 | of 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 |
922 | calls of @code{bzCompress} with action = @code{BZ_RUN}. | 958 | calls of @code{BZ2_bzCompress} with action = @code{BZ_RUN}. |
923 | @item Finish up. | 959 | @item Finish up. |
924 | Repeatedly call @code{bzCompress} with action = @code{BZ_FINISH}, | 960 | Repeatedly call @code{BZ2_bzCompress} with action = @code{BZ_FINISH}, |
925 | copying out the compressed output, until @code{BZ_STREAM_END} is returned. | 961 | copying 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 |
928 | If the data you want to compress fits into your input buffer all | 964 | If the data you want to compress fits into your input buffer all |
929 | at once, you can skip the calls of @code{bzCompress ( ..., BZ_RUN )} and | 965 | at once, you can skip the calls of @code{BZ2_bzCompress ( ..., BZ_RUN )} and |
930 | just do the @code{bzCompress ( ..., BZ_FINISH )} calls. | 966 | just do the @code{BZ2_bzCompress ( ..., BZ_FINISH )} calls. |
931 | 967 | ||
932 | All required memory is allocated by @code{bzCompressInit}. The | 968 | All required memory is allocated by @code{BZ2_bzCompressInit}. The |
933 | compression library can accept any data at all (obviously). So you | 969 | compression library can accept any data at all (obviously). So you |
934 | shouldn't get any error return values from the @code{bzCompress} calls. | 970 | shouldn't get any error return values from the @code{BZ2_bzCompress} calls. |
935 | If you do, they will be @code{BZ_SEQUENCE_ERROR}, and indicate a bug in | 971 | If you do, they will be @code{BZ_SEQUENCE_ERROR}, and indicate a bug in |
936 | your programming. | 972 | your 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 |
946 | int bzCompressEnd ( bz_stream *strm ); | 982 | int BZ2_bzCompressEnd ( bz_stream *strm ); |
947 | @end example | 983 | @end example |
948 | Releases all memory associated with a compression stream. | 984 | Releases 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 |
959 | int bzDecompressInit ( bz_stream *strm, int verbosity, int small ); | 995 | int BZ2_bzDecompressInit ( bz_stream *strm, int verbosity, int small ); |
960 | @end example | 996 | @end example |
961 | Prepares for decompression. As with @code{bzCompressInit}, a | 997 | Prepares 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 |
963 | call. Fields @code{bzalloc}, @code{bzfree} and @code{opaque} should be | 999 | call. Fields @code{bzalloc}, @code{bzfree} and @code{opaque} should be |
964 | set if a custom memory allocator is required, or made @code{NULL} for | 1000 | set 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 | |||
966 | state will have been initialised, and @code{total_in} and | 1002 | state 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 | ||
969 | For the meaning of parameter @code{verbosity}, see @code{bzCompressInit}. | 1005 | For the meaning of parameter @code{verbosity}, see @code{BZ2_bzCompressInit}. |
970 | 1006 | ||
971 | If @code{small} is nonzero, the library will use an alternative | 1007 | If @code{small} is nonzero, the library will use an alternative |
972 | decompression algorithm which uses less memory but at the cost of | 1008 | decompression algorithm which uses less memory but at the cost of |
@@ -976,11 +1012,13 @@ more information on memory management. | |||
976 | 1012 | ||
977 | Note that the amount of memory needed to decompress | 1013 | Note that the amount of memory needed to decompress |
978 | a stream cannot be determined until the stream's header has been read, | 1014 | a stream cannot be determined until the stream's header has been read, |
979 | so even if @code{bzDecompressInit} succeeds, a subsequent | 1015 | so 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 | ||
982 | Possible return values: | 1018 | Possible 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 | ||
991 | Allowable next actions: | 1029 | Allowable 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 |
1002 | int bzDecompress ( bz_stream *strm ); | 1040 | int BZ2_bzDecompress ( bz_stream *strm ); |
1003 | @end example | 1041 | @end example |
1004 | Provides more input and/out output buffer space for the library. The | 1042 | Provides more input and/out output buffer space for the library. The |
1005 | caller maintains input and output buffers, and uses @code{bzDecompress} | 1043 | caller maintains input and output buffers, and uses @code{BZ2_bzDecompress} |
1006 | to transfer data between them. | 1044 | to transfer data between them. |
1007 | 1045 | ||
1008 | Before each call to @code{bzDecompress}, @code{next_in} | 1046 | Before each call to @code{BZ2_bzDecompress}, @code{next_in} |
1009 | should point at the compressed data, | 1047 | should point at the compressed data, |
1010 | and @code{avail_in} should indicate how many bytes the library | 1048 | and @code{avail_in} should indicate how many bytes the library |
1011 | may read. @code{bzDecompress} updates @code{next_in}, @code{avail_in} | 1049 | may read. @code{BZ2_bzDecompress} updates @code{next_in}, @code{avail_in} |
1012 | and @code{total_in} | 1050 | and @code{total_in} |
1013 | to reflect the number of bytes it has read. | 1051 | to reflect the number of bytes it has read. |
1014 | 1052 | ||
1015 | Similarly, @code{next_out} should point to a buffer in which the uncompressed | 1053 | Similarly, @code{next_out} should point to a buffer in which the uncompressed |
1016 | output is to be placed, with @code{avail_out} indicating how much output space | 1054 | output is to be placed, with @code{avail_out} indicating how much output space |
1017 | is available. @code{bzCompress} updates @code{next_out}, | 1055 | is 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 |
1019 | the number of bytes output. | 1057 | the number of bytes output. |
1020 | 1058 | ||
1021 | You may provide and remove as little or as much data as you like on | 1059 | You may provide and remove as little or as much data as you like on |
1022 | each call of @code{bzDecompress}. | 1060 | each call of @code{BZ2_bzDecompress}. |
1023 | In the limit, it is acceptable to | 1061 | In the limit, it is acceptable to |
1024 | supply and remove data one byte at a time, although this would be | 1062 | supply and remove data one byte at a time, although this would be |
1025 | terribly inefficient. You should always ensure that at least one | 1063 | terribly inefficient. You should always ensure that at least one |
1026 | byte of output space is available at each call. | 1064 | byte of output space is available at each call. |
1027 | 1065 | ||
1028 | Use of @code{bzDecompress} is simpler than @code{bzCompress}. | 1066 | Use of @code{BZ2_bzDecompress} is simpler than @code{BZ2_bzCompress}. |
1029 | 1067 | ||
1030 | You should provide input and remove output as described above, and | 1068 | You should provide input and remove output as described above, and |
1031 | repeatedly call @code{bzDecompress} until @code{BZ_STREAM_END} is | 1069 | repeatedly call @code{BZ2_bzDecompress} until @code{BZ_STREAM_END} is |
1032 | returned. Appearance of @code{BZ_STREAM_END} denotes that | 1070 | returned. 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 |
1034 | stream. @code{bzDecompress} will not produce @code{BZ_STREAM_END} until | 1072 | stream. @code{BZ2_bzDecompress} will not produce @code{BZ_STREAM_END} until |
1035 | all output data has been placed into the output buffer, so once | 1073 | all 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 |
1037 | the decompressed output, and @code{bzDecompressEnd} can safely be | 1075 | the decompressed output, and @code{BZ2_bzDecompressEnd} can safely be |
1038 | called. | 1076 | called. |
1039 | 1077 | ||
1040 | If case of an error return value, you should call @code{bzDecompressEnd} | 1078 | If case of an error return value, you should call @code{BZ2_bzDecompressEnd} |
1041 | to clean up and release memory. | 1079 | to clean up and release memory. |
1042 | 1080 | ||
1043 | Possible return values: | 1081 | Possible return values: |
@@ -1059,16 +1097,16 @@ Possible return values: | |||
1059 | @end display | 1097 | @end display |
1060 | Allowable next actions: | 1098 | Allowable 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 |
1071 | int bzDecompressEnd ( bz_stream *strm ); | 1109 | int BZ2_bzDecompressEnd ( bz_stream *strm ); |
1072 | @end example | 1110 | @end example |
1073 | Releases all memory associated with a decompression stream. | 1111 | Releases 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 |
1141 | Prepare to read compressed data from file handle @code{f}. @code{f} | 1179 | Prepare to read compressed data from file handle @code{f}. @code{f} |
1142 | should refer to a file which has been opened for reading, and for which | 1180 | should 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, | |||
1144 | the library will try to decompress using less memory, at the expense of | 1182 | the library will try to decompress using less memory, at the expense of |
1145 | speed. | 1183 | speed. |
1146 | 1184 | ||
1147 | For reasons explained below, @code{bzRead} will decompress the | 1185 | For 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 |
1149 | from the file @code{f}. At most @code{BZ_MAX_UNUSED} bytes may be | 1187 | from the file @code{f}. At most @code{BZ_MAX_UNUSED} bytes may be |
1150 | supplied like this. If this facility is not required, you should pass | 1188 | supplied 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 | |||
1152 | respectively. | 1190 | respectively. |
1153 | 1191 | ||
1154 | For the meaning of parameters @code{small} and @code{verbosity}, | 1192 | For the meaning of parameters @code{small} and @code{verbosity}, |
1155 | see @code{bzDecompressInit}. | 1193 | see @code{BZ2_bzDecompressInit}. |
1156 | 1194 | ||
1157 | The amount of memory needed to decompress a file cannot be determined | 1195 | The amount of memory needed to decompress a file cannot be determined |
1158 | until the file's header has been read. So it is possible that | 1196 | until 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 | ||
1162 | Possible assignments to @code{bzerror}: | 1200 | Possible 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 | ||
1185 | Allowable next actions: | 1225 | Allowable 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 |
1198 | Reads up to @code{len} (uncompressed) bytes from the compressed file | 1238 | Reads 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}, | |||
1204 | and the number | 1244 | and the number |
1205 | of bytes read is returned. All other @code{bzerror} values denote an error. | 1245 | of 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, |
1208 | unless the logical stream end is detected | 1248 | unless the logical stream end is detected |
1209 | or an error occurs. Because of this, it is possible to detect the | 1249 | or an error occurs. Because of this, it is possible to detect the |
1210 | stream end by observing when the number of bytes returned is | 1250 | stream end by observing when the number of bytes returned is |
@@ -1213,20 +1253,20 @@ requested. Nevertheless, this is regarded as inadvisable; you should | |||
1213 | instead check @code{bzerror} after every call and watch out for | 1253 | instead check @code{bzerror} after every call and watch out for |
1214 | @code{BZ_STREAM_END}. | 1254 | @code{BZ_STREAM_END}. |
1215 | 1255 | ||
1216 | Internally, @code{bzRead} copies data from the compressed file in chunks | 1256 | Internally, @code{BZ2_bzRead} copies data from the compressed file in chunks |
1217 | of size @code{BZ_MAX_UNUSED} bytes | 1257 | of size @code{BZ_MAX_UNUSED} bytes |
1218 | before decompressing it. If the file contains more bytes than strictly | 1258 | before decompressing it. If the file contains more bytes than strictly |
1219 | needed to reach the logical end-of-stream, @code{bzRead} will almost certainly | 1259 | needed to reach the logical end-of-stream, @code{BZ2_bzRead} will almost certainly |
1220 | read some of the trailing data before signalling @code{BZ_SEQUENCE_END}. | 1260 | read some of the trailing data before signalling @code{BZ_SEQUENCE_END}. |
1221 | To collect the read but unused data once @code{BZ_SEQUENCE_END} has | 1261 | To collect the read but unused data once @code{BZ_SEQUENCE_END} has |
1222 | appeared, call @code{bzReadGetUnused} immediately before @code{bzReadClose}. | 1262 | appeared, call @code{BZ2_bzReadGetUnused} immediately before @code{BZ2_bzReadClose}. |
1223 | 1263 | ||
1224 | Possible assignments to @code{bzerror}: | 1264 | Possible 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 | ||
1255 | Allowable next actions: | 1295 | Allowable 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 |
1272 | Returns data which was read from the compressed file but was not needed | 1312 | Returns data which was read from the compressed file but was not needed |
1273 | to get to the logical end-of-stream. @code{*unused} is set to the address | 1313 | to get to the logical end-of-stream. @code{*unused} is set to the address |
1274 | of the data, and @code{*nUnused} to the number of bytes. @code{*nUnused} will | 1314 | of the data, and @code{*nUnused} to the number of bytes. @code{*nUnused} will |
1275 | be set to a value between @code{0} and @code{BZ_MAX_UNUSED} inclusive. | 1315 | be set to a value between @code{0} and @code{BZ_MAX_UNUSED} inclusive. |
1276 | 1316 | ||
1277 | This function may only be called once @code{bzRead} has signalled | 1317 | This 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 | ||
1280 | Possible assignments to @code{bzerror}: | 1320 | Possible 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 | ||
1292 | Allowable next actions: | 1332 | Allowable 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 |
1302 | Releases all memory pertaining to the compressed file @code{b}. | 1342 | Releases 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 |
1304 | handle, so you should do that yourself if appropriate. | 1344 | handle, 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 |
1306 | situations. | 1346 | situations. |
1307 | 1347 | ||
1308 | Possible assignments to @code{bzerror}: | 1348 | Possible 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 |
1329 | Prepare to write compressed data to file handle @code{f}. | 1369 | Prepare 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 | ||
1334 | For the meaning of parameters @code{blockSize100k}, | 1374 | For 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 | ||
1338 | All required memory is allocated at this stage, so if the call | 1378 | All required memory is allocated at this stage, so if the call |
1339 | completes successfully, @code{BZ_MEM_ERROR} cannot be signalled by a | 1379 | completes successfully, @code{BZ_MEM_ERROR} cannot be signalled by a |
1340 | subsequent call to @code{bzWrite}. | 1380 | subsequent call to @code{BZ2_bzWrite}. |
1341 | 1381 | ||
1342 | Possible assignments to @code{bzerror}: | 1382 | Possible 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 | ||
1363 | Allowable next actions: | 1405 | Allowable 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 |
1378 | Absorbs @code{len} bytes from the buffer @code{buf}, eventually to be | 1420 | Absorbs @code{len} bytes from the buffer @code{buf}, eventually to be |
1379 | compressed and written to the file. | 1421 | compressed 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 | ||
1404 | Compresses and flushes to the compressed file all data so far supplied | 1453 | Compresses and flushes to the compressed file all data so far supplied |
1405 | by @code{bzWrite}. The logical end-of-stream markers are also written, so | 1454 | by @code{BZ2_bzWrite}. The logical end-of-stream markers are also written, so |
1406 | subsequent calls to @code{bzWrite} are illegal. All memory associated | 1455 | subsequent calls to @code{BZ2_bzWrite} are illegal. All memory associated |
1407 | with the compressed file @code{b} is released. | 1456 | with the compressed file @code{b} is released. |
1408 | @code{fflush} is called on the | 1457 | @code{fflush} is called on the |
1409 | compressed file, but it is not @code{fclose}'d. | 1458 | compressed file, but it is not @code{fclose}'d. |
1410 | 1459 | ||
1411 | If @code{bzWriteClose} is called to clean up after an error, the only | 1460 | If @code{BZ2_bzWriteClose} is called to clean up after an error, the only |
1412 | action is to release the memory. The library records the error codes | 1461 | action is to release the memory. The library records the error codes |
1413 | issued by previous calls, so this situation will be detected | 1462 | issued by previous calls, so this situation will be detected |
1414 | automatically. There is no attempt to complete the compression | 1463 | automatically. There is no attempt to complete the compression |
@@ -1418,12 +1467,17 @@ value to @code{abandon}. | |||
1418 | 1467 | ||
1419 | If @code{nbytes_in} is non-null, @code{*nbytes_in} will be set to be the | 1468 | If @code{nbytes_in} is non-null, @code{*nbytes_in} will be set to be the |
1420 | total volume of uncompressed data handled. Similarly, @code{nbytes_out} | 1469 | total volume of uncompressed data handled. Similarly, @code{nbytes_out} |
1421 | will be set to the total volume of compressed data written. | 1470 | will be set to the total volume of compressed data written. For |
1471 | compatibility with older versions of the library, @code{BZ2_bzWriteClose} | ||
1472 | only yields the lower 32 bits of these counts. Use | ||
1473 | @code{BZ2_bzWriteClose64} if you want the full 64 bit counts. These | ||
1474 | two functions are otherwise absolutely identical. | ||
1475 | |||
1422 | 1476 | ||
1423 | Possible assignments to @code{bzerror}: | 1477 | Possible 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 | |||
1442 | compressed data stream, using that same file handle. | 1496 | compressed 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 |
1444 | as they could be since generality is hard to reconcile with efficiency. | 1498 | as 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 |
1447 | the logical end of compressed stream. | 1501 | the logical end of compressed stream. |
1448 | To recover this data once decompression has | 1502 | To recover this data once decompression has |
1449 | ended, call @code{bzReadGetUnused} after the last call of @code{bzRead} | 1503 | ended, 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 | ||
1454 | This mechanism makes it easy to decompress multiple @code{bzip2} | 1508 | This mechanism makes it easy to decompress multiple @code{bzip2} |
1455 | streams placed end-to-end. As the end of one stream, when @code{bzRead} | 1509 | streams placed end-to-end. As the end of one stream, when @code{BZ2_bzRead} |
1456 | returns @code{BZ_STREAM_END}, call @code{bzReadGetUnused} to collect the | 1510 | returns @code{BZ_STREAM_END}, call @code{BZ2_bzReadGetUnused} to collect the |
1457 | unused data (copy it into your own buffer somewhere). | 1511 | unused data (copy it into your own buffer somewhere). |
1458 | That data forms the start of the next compressed stream. | 1512 | That data forms the start of the next compressed stream. |
1459 | To start uncompressing that next stream, call @code{bzReadOpen} again, | 1513 | To start uncompressing that next stream, call @code{BZ2_bzReadOpen} again, |
1460 | feeding in the unused data via the @code{unused}/@code{nUnused} | 1514 | feeding in the unused data via the @code{unused}/@code{nUnused} |
1461 | parameters. | 1515 | parameters. |
1462 | Keep doing this until @code{BZ_STREAM_END} return coincides with the | 1516 | Keep doing this until @code{BZ_STREAM_END} return coincides with the |
1463 | physical end of file (@code{feof(f)}). In this situation | 1517 | physical end of file (@code{feof(f)}). In this situation |
1464 | @code{bzReadGetUnused} | 1518 | @code{BZ2_bzReadGetUnused} |
1465 | will of course return no data. | 1519 | will of course return no data. |
1466 | 1520 | ||
1467 | This should give some feel for how the high-level interface can be used. | 1521 | This should give some feel for how the high-level interface can be used. |
@@ -1482,22 +1536,22 @@ f = fopen ( "myfile.bz2", "w" ); | |||
1482 | if (!f) @{ | 1536 | if (!f) @{ |
1483 | /* handle error */ | 1537 | /* handle error */ |
1484 | @} | 1538 | @} |
1485 | b = bzWriteOpen ( &bzerror, f, 9 ); | 1539 | b = BZ2_bzWriteOpen ( &bzerror, f, 9 ); |
1486 | if (bzerror != BZ_OK) @{ | 1540 | if (bzerror != BZ_OK) @{ |
1487 | bzWriteClose ( b ); | 1541 | BZ2_bzWriteClose ( b ); |
1488 | /* handle error */ | 1542 | /* handle error */ |
1489 | @} | 1543 | @} |
1490 | 1544 | ||
1491 | while ( /* condition */ ) @{ | 1545 | while ( /* 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 | ||
1500 | bzWriteClose ( &bzerror, b ); | 1554 | BZ2_bzWriteClose ( &bzerror, b ); |
1501 | if (bzerror == BZ_IO_ERROR) @{ | 1555 | if (bzerror == BZ_IO_ERROR) @{ |
1502 | /* handle error */ | 1556 | /* handle error */ |
1503 | @} | 1557 | @} |
@@ -1515,39 +1569,39 @@ f = fopen ( "myfile.bz2", "r" ); | |||
1515 | if (!f) @{ | 1569 | if (!f) @{ |
1516 | /* handle error */ | 1570 | /* handle error */ |
1517 | @} | 1571 | @} |
1518 | b = bzReadOpen ( &bzerror, f, 0, NULL, 0 ); | 1572 | b = BZ2_bzReadOpen ( &bzerror, f, 0, NULL, 0 ); |
1519 | if (bzerror != BZ_OK) @{ | 1573 | if (bzerror != BZ_OK) @{ |
1520 | bzReadClose ( &bzerror, b ); | 1574 | BZ2_bzReadClose ( &bzerror, b ); |
1521 | /* handle error */ | 1575 | /* handle error */ |
1522 | @} | 1576 | @} |
1523 | 1577 | ||
1524 | bzerror = BZ_OK; | 1578 | bzerror = BZ_OK; |
1525 | while (bzerror == BZ_OK && /* arbitrary other conditions */) @{ | 1579 | while (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 | @} |
1531 | if (bzerror != BZ_STREAM_END) @{ | 1585 | if (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 |
1552 | Attempts to compress the data in @code{source[0 .. sourceLen-1]} | 1606 | Attempts to compress the data in @code{source[0 .. sourceLen-1]} |
1553 | into the destination buffer, @code{dest[0 .. *destLen-1]}. | 1607 | into 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 | |||
1563 | mechanism, use the low-level interface. | 1617 | mechanism, use the low-level interface. |
1564 | 1618 | ||
1565 | For the meaning of parameters @code{blockSize100k}, @code{verbosity} | 1619 | For the meaning of parameters @code{blockSize100k}, @code{verbosity} |
1566 | and @code{workFactor}, @* see @code{bzCompressInit}. | 1620 | and @code{workFactor}, @* see @code{BZ2_bzCompressInit}. |
1567 | 1621 | ||
1568 | To guarantee that the compressed data will fit in its buffer, allocate | 1622 | To guarantee that the compressed data will fit in its buffer, allocate |
1569 | an output buffer of size 1% larger than the uncompressed data, plus | 1623 | an output buffer of size 1% larger than the uncompressed data, plus |
1570 | six hundred extra bytes. | 1624 | six hundred extra bytes. |
1571 | 1625 | ||
1572 | @code{bzBuffToBuffDecompress} will not write data at or | 1626 | @code{BZ2_bzBuffToBuffDecompress} will not write data at or |
1573 | beyond @code{dest[*destLen]}, even in case of buffer overflow. | 1627 | beyond @code{dest[*destLen]}, even in case of buffer overflow. |
1574 | 1628 | ||
1575 | Possible return values: | 1629 | Possible 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 |
1601 | Attempts to decompress the data in @code{source[0 .. sourceLen-1]} | 1657 | Attempts to decompress the data in @code{source[0 .. sourceLen-1]} |
1602 | into the destination buffer, @code{dest[0 .. *destLen-1]}. | 1658 | into the destination buffer, @code{dest[0 .. *destLen-1]}. |
@@ -1606,11 +1662,11 @@ returned. If the compressed data won't fit, @code{*destLen} | |||
1606 | is unchanged, and @code{BZ_OUTBUFF_FULL} is returned. | 1662 | is 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 |
1609 | data stream. @code{bzBuffToBuffDecompress} tries to decompress | 1665 | data stream. @* @code{BZ2_bzBuffToBuffDecompress} tries to decompress |
1610 | the entirety of the stream into the output buffer. | 1666 | the entirety of the stream into the output buffer. |
1611 | 1667 | ||
1612 | For the meaning of parameters @code{small} and @code{verbosity}, | 1668 | For the meaning of parameters @code{small} and @code{verbosity}, |
1613 | see @code{bzDecompressInit}. | 1669 | see @code{BZ2_bzDecompressInit}. |
1614 | 1670 | ||
1615 | Because the compression ratio of the compressed data cannot be known in | 1671 | Because the compression ratio of the compressed data cannot be known in |
1616 | advance, there is no easy way to guarantee that the output buffer will | 1672 | advance, 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 | |||
1618 | record the size of the uncompressed data, but such a mechanism is beyond | 1674 | record the size of the uncompressed data, but such a mechanism is beyond |
1619 | the scope of this library. | 1675 | the 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 |
1622 | beyond @code{dest[*destLen]}, even in case of buffer overflow. | 1678 | beyond @code{dest[*destLen]}, even in case of buffer overflow. |
1623 | 1679 | ||
1624 | Possible return values: | 1680 | Possible 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 |
1647 | Yoshioka Tsuneo has contributed some functions to | 1705 | Yoshioka Tsuneo has contributed some functions to |
1648 | give better @code{zlib} compatibility. These functions are | 1706 | give 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}. |
1652 | These functions are not (yet) officially part of | 1710 | These functions are not (yet) officially part of |
1653 | the library. If they break, you get to keep all the pieces. | 1711 | the library. If they break, you get to keep all the pieces. |
1654 | Nevertheless, I think they work ok. | 1712 | Nevertheless, I think they work ok. |
1655 | @example | 1713 | @example |
1656 | typedef void BZFILE; | 1714 | typedef void BZFILE; |
1657 | 1715 | ||
1658 | const char * bzlibVersion ( void ); | 1716 | const char * BZ2_bzlibVersion ( void ); |
1659 | @end example | 1717 | @end example |
1660 | Returns a string indicating the library version. | 1718 | Returns a string indicating the library version. |
1661 | @example | 1719 | @example |
1662 | BZFILE * bzopen ( const char *path, const char *mode ); | 1720 | BZFILE * BZ2_bzopen ( const char *path, const char *mode ); |
1663 | BZFILE * bzdopen ( int fd, const char *mode ); | 1721 | BZFILE * BZ2_bzdopen ( int fd, const char *mode ); |
1664 | @end example | 1722 | @end example |
1665 | Opens a @code{.bz2} file for reading or writing, using either its name | 1723 | Opens a @code{.bz2} file for reading or writing, using either its name |
1666 | or a pre-existing file descriptor. | 1724 | or a pre-existing file descriptor. |
1667 | Analogous to @code{fopen} and @code{fdopen}. | 1725 | Analogous to @code{fopen} and @code{fdopen}. |
1668 | @example | 1726 | @example |
1669 | int bzread ( BZFILE* b, void* buf, int len ); | 1727 | int BZ2_bzread ( BZFILE* b, void* buf, int len ); |
1670 | int bzwrite ( BZFILE* b, void* buf, int len ); | 1728 | int BZ2_bzwrite ( BZFILE* b, void* buf, int len ); |
1671 | @end example | 1729 | @end example |
1672 | Reads/writes data from/to a previously opened @code{BZFILE}. | 1730 | Reads/writes data from/to a previously opened @code{BZFILE}. |
1673 | Analogous to @code{fread} and @code{fwrite}. | 1731 | Analogous to @code{fread} and @code{fwrite}. |
1674 | @example | 1732 | @example |
1675 | int bzflush ( BZFILE* b ); | 1733 | int BZ2_bzflush ( BZFILE* b ); |
1676 | void bzclose ( BZFILE* b ); | 1734 | void BZ2_bzclose ( BZFILE* b ); |
1677 | @end example | 1735 | @end example |
1678 | Flushes/closes a @code{BZFILE}. @code{bzflush} doesn't actually do | 1736 | Flushes/closes a @code{BZFILE}. @code{BZ2_bzflush} doesn't actually do |
1679 | anything. Analogous to @code{fflush} and @code{fclose}. | 1737 | anything. Analogous to @code{fflush} and @code{fclose}. |
1680 | 1738 | ||
1681 | @example | 1739 | @example |
1682 | const char * bzerror ( BZFILE *b, int *errnum ) | 1740 | const char * BZ2_bzerror ( BZFILE *b, int *errnum ) |
1683 | @end example | 1741 | @end example |
1684 | Returns a string describing the more recent error status of | 1742 | Returns 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} | |||
1695 | defined. Doing this gives you a library containing only the following | 1753 | defined. Doing this gives you a library containing only the following |
1696 | eight functions: | 1754 | eight 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 | ||
1702 | When compiled like this, all functions will ignore @code{verbosity} | 1760 | When compiled like this, all functions will ignore @code{verbosity} |
1703 | settings. | 1761 | settings. |
@@ -1710,14 +1768,14 @@ was compiled with @code{BZ_NO_STDIO} set. | |||
1710 | 1768 | ||
1711 | For a normal compile, an assertion failure yields the message | 1769 | For 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 |
1722 | where @code{N} is some error code number. @code{exit(3)} | 1780 | where @code{N} is some error code number. @code{exit(3)} |
1723 | is then called. | 1781 | is then called. |
@@ -1781,7 +1839,7 @@ These are just some random thoughts of mine. Your mileage may | |||
1781 | vary. | 1839 | vary. |
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} |
1785 | use exactly the same file format as the previous | 1843 | use exactly the same file format as the previous |
1786 | version, @code{bzip2-0.1}. This decision was made in the interests of | 1844 | version, @code{bzip2-0.1}. This decision was made in the interests of |
1787 | stability. Creating yet another incompatible compressed file format | 1845 | stability. 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 |
1862 | After some consideration, I have decided not to use | 1920 | After some consideration, I have decided not to use |
1863 | GNU @code{autoconf} to configure 0.9.5. | 1921 | GNU @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, |
1866 | mainly assists with portability problems between Unix-like | 1924 | mainly 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}. |
1926 | You should specifically @emph{not} use @code{-funroll-loops}. | 1984 | You should specifically @emph{not} use @code{-funroll-loops}. |
1927 | 1985 | ||
1928 | You may notice that the Makefile runs four tests as part of | 1986 | You may notice that the Makefile runs six tests as part of |
1929 | the build process. If the program passes all of these, it's | 1987 | the build process. If the program passes all of these, it's |
1930 | a pretty good (but not 100%) indication that the compiler has | 1988 | a pretty good (but not 100%) indication that the compiler has |
1931 | done its job correctly. | 1989 | done its job correctly. |
@@ -2000,6 +2058,7 @@ memory but gets pretty good compression, and has minimal latency, | |||
2000 | consider Jean-loup | 2058 | consider Jean-loup |
2001 | Gailly's and Mark Adler's work, @code{zlib-1.1.2} and | 2059 | Gailly'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 |
2141 | http://www.cs.arizona.edu/people/gene/PAPERS/suffix.ps | 2200 | http://www.cs.arizona.edu/people/gene/PAPERS/suffix.ps |
2142 | @end example | 2201 | @end example |
2143 | 2202 | Finally, the following paper documents some recent investigations | |
2203 | I made into the performance of sorting algorithms: | ||
2204 | @example | ||
2205 | Julian 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 |