text
stringlengths
0
234
(Buffer => BZ_Buffer,
check_CRC => False, -- Already done by UnZ_IO
Read => Read,
Write => Write
);
begin
My_BZip2.Decompress;
UnZ_IO.Flush (UnZ_Glob.slide_index);
end Bunzip2;
end UnZ_Meth;
procedure Process (descriptor : out Zip.Headers.Data_descriptor)
is
start : Integer;
b : Unsigned_8;
dd_buffer : Zip.Byte_Buffer (1 .. 30);
begin
UnZ_IO.Bit_buffer.Dump_to_byte_boundary;
UnZ_IO.Read_raw_byte (b);
if b = 75 then -- 'K' ('P' is before, Java/JAR bug!)
dd_buffer (1) := 80;
dd_buffer (2) := 75;
start := 3;
else
dd_buffer (1) := b; -- hopefully = 80
start := 2;
end if;
for i in start .. 16 loop
UnZ_IO.Read_raw_byte (dd_buffer (i));
end loop;
Zip.Headers.Copy_and_check (dd_buffer, descriptor);
end Process;
tolerance_wrong_password : constant := 4; -- after that, error !
work_index : Ada.Streams.Stream_IO.Positive_Count;
use Zip, UnZ_Meth;
begin -- Decompress_Data
output_memory_access := null;
-- ^ this is an 'out' parameter, we have to set it anyway
case mode is
when write_to_binary_file =>
Ada.Streams.Stream_IO.Create (UnZ_IO.out_bin_file, Ada.Streams.Stream_IO.Out_File, output_file_name,
Form => To_String (Zip.Form_For_IO_Open_N_Create));
when write_to_text_file =>
Ada.Text_IO.Create (UnZ_IO.out_txt_file, Ada.Text_IO.Out_File, output_file_name,
Form => To_String (Zip.Form_For_IO_Open_N_Create));
when write_to_memory =>
output_memory_access := new
Ada.Streams.Stream_Element_Array (
1 .. Ada.Streams.Stream_Element_Offset (hint.uncompressed_size)
);
UnZ_Glob.uncompressed_index := output_memory_access'First;
when just_test =>
null;
end case;
UnZ_Glob.compsize := hint.compressed_size;
-- 2008 : from TT's version:
-- Avoid wraparound in read_buffer, when File_size_type'Last is given
-- as hint.compressed_size (unknown size)
if UnZ_Glob.compsize > File_size_type'Last - 2 then
UnZ_Glob.compsize := File_size_type'Last - 2;
end if;
UnZ_Glob.uncompsize := hint.uncompressed_size;
UnZ_IO.Init_Buffers;
UnZ_IO.Decryption.Set_mode (encrypted);
if encrypted then
work_index := Ada.Streams.Stream_IO.Positive_Count (Zip_Streams.Index (zip_file));
password_passes : for p in 1 .. tolerance_wrong_password loop
begin
UnZ_IO.Decryption.Init (To_String (password), hint.crc_32);
exit password_passes; -- the current password fits, then go on!
exception
when Wrong_password =>
if p = tolerance_wrong_password then
raise;
end if; -- alarm!
if get_new_password /= null then
get_new_password (password); -- ask for a new one
end if;
Function Definition: procedure Decompress is
Function Body: max_groups : constant := 6;
max_alpha_size : constant := 258;
max_code_len : constant := 23;
group_size : constant := 50;
max_selectors : constant := 2 + (900_000 / group_size);
sub_block_size : constant := 100_000;
type Length_array is array (Integer range <>) of Natural;
block_randomized : Boolean := False;
block_size : Natural;
use Interfaces;
type Tcardinal_array is array (Integer range <>) of Unsigned_32;