1. -- 
  2.  -- BZip2.Decompress - decompression of bzip2 data streams. 
  3.  -- 
  4.  -- bzip2 compresses files using the Burrows - Wheeler block - sorting text 
  5.  -- compression algorithm, and Huffman coding. Compression is generally 
  6.  -- considerably better than that achieved by more conventional 
  7.  -- LZ77/LZ78 - based compressors, and approaches the performance of the 
  8.  -- PPM family of statistical compressors. 
  9.  -- 
  10.  -- This Ada code (a) is a reworked translation of a Pascal version (b) 
  11.  -- by Daniel Mantione of the decompression code of libbzip2 (c) 
  12.  -- by Julian Seward. 
  13.  -- Both (a) and (b) refer to (c)'s license which follows here, as in 
  14.  -- bzip version 1.0.5, from http://www.bzip.org : 
  15.  -- 
  16.  --*************************************************************************** 
  17.  --  bzip2 and libbzip2, version 1.0.5 : A program and library for data 
  18.  --   compression by Julian Seward 
  19.  --  Copyright (c) 1996 - 2007 Julian Seward 
  20.  --  This program, bzip2, the associated library libbzip2, and all 
  21.  --   documentation, are copyright (c) 1996 - 2007 Julian Seward. 
  22.  --  All rights reserved. 
  23.  --  Redistribution and use in source and binary forms, with or without 
  24.  --  modification, are permitted provided that the following conditions 
  25.  --  are met: 
  26.  --  * Redistributions of source code must retain the above copyright notice, 
  27.  --     this list of conditions and the following disclaimer. 
  28.  --  * The origin of this software must not be misrepresented; you must not 
  29.  --     claim that you wrote the original software. If you use this software 
  30.  --     in a product, an acknowledgment in the product documentation would be 
  31.  --     appreciated but is not required. 
  32.  --  * Altered source versions must be plainly marked as such, and must not be 
  33.  --     misrepresented as being the original software. 
  34.  --  * The name of the author may not be used to endorse or promote products 
  35.  --     derived from this software without specific prior written permission. 
  36.  --  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 
  37.  --  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
  38.  --  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
  39.  --  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 
  40.  --  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
  41.  --  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
  42.  --  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
  43.  --  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
  44.  --  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
  45.  --  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  46.  --  PATENTS : To the best of my knowledge, bzip2 and libbzip2 do not use any 
  47.  --  patented algorithms. However, I do not have the resources to 
  48.  --  carry out a patent search. 
  49.  --  Therefore I cannot give any guarantee of the above statement. 
  50.  --*************************************************************************** 
  51.  -- 
  52.  -- Translated on 20 - Oct - 2009 by (New) P2Ada v. 15 - Nov - 2006 
  53.  -- Rework by G. de Montmollin 
  54.  -- 
  55.  -- Main difference over the FreePascal version : there is no more pointer 
  56.  -- arithmetics. The only pointer is tt, for dynamically allocating the biggest 
  57.  -- decoding array. 
  58.  -- With the appropriate options, the performance is very close to 
  59.  -- the bzip2 tool in C : it takes around 7% - 11% more time according to data 
  60.  -- to be decompressed. Add 5% when CRC checking is enabled. 
  61.  -- These timings are obtained with bunzip.adb compiled on GNAT 2008, Win32, 
  62.  -- with the - O2 - gnatpn - fpeel - loops - funroll - loops - fweb - frename - registers 
  63.  -- options, average on several runs (see bz_test.cmd). 
  64.  
  65. with Interfaces; 
  66.  
  67. generic 
  68.  
  69.   input_buffer_size  : Integer := 1024; 
  70.   output_buffer_size : Integer := 4096; 
  71.  
  72.   type Buffer is array (Natural range <>) of Interfaces.Unsigned_8; 
  73.  
  74.   check_CRC : Boolean; 
  75.   -- ^ useless if the whole bzip stream is in 
  76.   -- another CRC - checked stream, like a Zip archive 
  77.  
  78.   with procedure Read  (buf : out Buffer); -- Input 
  79.   with procedure Write (buf :     Buffer); -- Output 
  80.  
  81. package BZip2 is 
  82.  
  83.   bad_header_magic, 
  84.   bad_block_magic, 
  85.   data_error, 
  86.   block_crc_check_failed, 
  87.   randomized_not_yet_implemented : exception; 
  88.  
  89.   procedure Decompress; 
  90.  
  91. end BZip2;