text
stringlengths 0
234
|
|---|
pragma Inline (Dump);
|
procedure Dump_To_Byte_Boundary;
|
function Read_And_Dump (N : Natural) return Integer;
|
pragma Inline (Read_And_Dump);
|
function Read_And_Dump_U32 (N : Natural) return Unsigned_32;
|
pragma Inline (Read_And_Dump_U32);
|
end Bit_Buffer;
|
procedure Flush (X : Natural); -- directly from slide to output stream
|
procedure Flush_If_Full (W : in out Integer);
|
pragma Inline (Flush_If_Full);
|
procedure Copy (Distance, Length : Natural; Index : in out Natural);
|
pragma Inline (Copy);
|
end Unz_Io;
|
package Unz_Meth is
|
procedure Copy_Stored (Size : Ada.Streams.Stream_Element_Offset);
|
procedure Inflate;
|
end Unz_Meth;
|
------------------------------
|
-- Bodies of UnZ_* packages --
|
------------------------------
|
package body Unz_Io is
|
procedure Init_Buffers is
|
begin
|
Unz_Glob.Inpos := 0; -- Input buffer position
|
Unz_Glob.Readpos := -1; -- Nothing read
|
Unz_Glob.Slide_Index := 0;
|
Unz_Glob.Reachedsize := 0;
|
Zip_Eof := False;
|
Zip.CRC.Init (CRC_Value);
|
Bit_Buffer.Init;
|
end Init_Buffers;
|
procedure Process_Compressed_End_Reached is
|
begin
|
if Zip_Eof then -- We came already here once
|
raise Zip.Archive_Corrupted with
|
"Decoding went past compressed data size plus one buffer length";
|
-- Avoid infinite loop on data with exactly buffer's length and no end marker
|
else
|
Unz_Glob.Readpos := Unz_Glob.Inbuf'Length;
|
-- Simulates reading -> no blocking.
|
-- The buffer is full of "random" data and we hope for a wrong code or a CRC error
|
Zip_Eof := True;
|
end if;
|
end Process_Compressed_End_Reached;
|
procedure Read_Buffer is
|
begin
|
if Unz_Glob.Reachedsize > Compressed_Size + 2 then
|
-- +2: last code is smaller than requested!
|
Process_Compressed_End_Reached;
|
else
|
begin
|
Zip.Blockread
|
(Stream => Zip_File,
|
Buffer => Unz_Glob.Inbuf,
|
Actually_Read => Unz_Glob.Readpos);
|
exception
|
when others => -- I/O error
|
Process_Compressed_End_Reached;
|
Function Definition: procedure Init is
|
Function Body: begin
|
B := 0;
|
K := 0;
|
end Init;
|
procedure Need (N : Natural) is
|
pragma Inline (Need);
|
begin
|
while K < N loop
|
B := B or Shift_Left (Unsigned_32 (Read_Byte_Decrypted), K);
|
K := K + 8;
|
end loop;
|
end Need;
|
procedure Dump (N : Natural) is
|
begin
|
B := Shift_Right (B, N);
|
K := K - N;
|
end Dump;
|
procedure Dump_To_Byte_Boundary is
|
begin
|
Dump (K mod 8);
|
end Dump_To_Byte_Boundary;
|
function Read_U32 (N : Natural) return Unsigned_32 is
|
begin
|
Need (N);
|
return B and (Shift_Left (1, N) - 1);
|
end Read_U32;
|
function Read (N : Natural) return Integer is
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.