text stringlengths 0 234 |
|---|
Header.Needed_Extract_Version := Intel_Nb (Lhb (5 .. 6)); |
Header.Bit_Flag := Intel_Nb (Lhb (7 .. 8)); |
Header.Zip_Type := Intel_Nb (Lhb (9 .. 10)); |
Header.File_Timedate := |
DCF.Streams.Convert (Unsigned_32'(Intel_Nb (Lhb (11 .. 14)))); |
Header.Dd.Crc_32 := Intel_Nb (Lhb (15 .. 18)); |
Header.Dd.Compressed_Size := Intel_Nb (Lhb (19 .. 22)); |
Header.Dd.Uncompressed_Size := Intel_Nb (Lhb (23 .. 26)); |
Header.Filename_Length := Intel_Nb (Lhb (27 .. 28)); |
Header.Extra_Field_Length := Intel_Nb (Lhb (29 .. 30)); |
if not Valid_Version (Header) then |
raise Bad_Local_Header with "Archived file needs invalid version to extract"; |
end if; |
if not Valid_Bitflag (Header) then |
raise Bad_Local_Header with "Archived file uses prohibited features"; |
end if; |
end Read_And_Check; |
procedure Write (Stream : in out Root_Zipstream_Type'Class; Header : in Local_File_Header) is |
Lhb : Stream_Element_Array (1 .. 30); |
begin |
Pk_Signature (Lhb, 3); |
Lhb (5 .. 6) := Intel_Bf (Header.Needed_Extract_Version); |
Lhb (7 .. 8) := Intel_Bf (Header.Bit_Flag); |
Lhb (9 .. 10) := Intel_Bf (Header.Zip_Type); |
Lhb (11 .. 14) := Intel_Bf (DCF.Streams.Convert (Header.File_Timedate)); |
Lhb (15 .. 18) := Intel_Bf (Header.Dd.Crc_32); |
Lhb (19 .. 22) := Intel_Bf (Header.Dd.Compressed_Size); |
Lhb (23 .. 26) := Intel_Bf (Header.Dd.Uncompressed_Size); |
Lhb (27 .. 28) := Intel_Bf (Header.Filename_Length); |
Lhb (29 .. 30) := Intel_Bf (Header.Extra_Field_Length); |
Stream.Write (Lhb); |
end Write; |
--------------------------------------------- |
-- PKZIP end-of-central-directory - PK56 -- |
--------------------------------------------- |
procedure Copy_And_Check (Buffer : in Stream_Element_Array; The_End : out End_Of_Central_Dir) is |
O : constant Stream_Element_Offset := Buffer'First - 1; |
begin |
if not Pk_Signature (Buffer, 5) then |
raise Bad_End; |
end if; |
The_End.Disknum := Intel_Nb (Buffer (O + 5 .. O + 6)); |
The_End.Disknum_With_Start := Intel_Nb (Buffer (O + 7 .. O + 8)); |
The_End.Disk_Total_Entries := Intel_Nb (Buffer (O + 9 .. O + 10)); |
The_End.Total_Entries := Intel_Nb (Buffer (O + 11 .. O + 12)); |
The_End.Central_Dir_Size := Intel_Nb (Buffer (O + 13 .. O + 16)); |
The_End.Central_Dir_Offset := Intel_Nb (Buffer (O + 17 .. O + 20)); |
The_End.Main_Comment_Length := Intel_Nb (Buffer (O + 21 .. O + 22)); |
end Copy_And_Check; |
procedure Read_And_Check |
(Stream : in out Root_Zipstream_Type'Class; |
The_End : out End_Of_Central_Dir) |
is |
Buffer : Stream_Element_Array (1 .. 22); |
begin |
Blockread (Stream, Buffer); |
Copy_And_Check (Buffer, The_End); |
end Read_And_Check; |
procedure Load (Stream : in out Root_Zipstream_Type'Class; The_End : out End_Of_Central_Dir) is |
Min_End_Start : Zs_Index_Type; -- min_end_start >= 1 |
Max_Comment : constant := 65_535; |
-- In appnote.txt : |
-- .ZIP file comment length 2 bytes |
begin |
if Size (Stream) < 22 then |
raise Bad_End; |
end if; |
-- 20-Jun-2001: abandon search below min_end_start. |
if Size (Stream) <= Max_Comment then |
Min_End_Start := 1; |
else |
Min_End_Start := Size (Stream) - Max_Comment; |
end if; |
Set_Index (Stream, Min_End_Start); |
declare |
-- We copy a large chunk of the zip stream's tail into a buffer. |
Large_Buffer : Stream_Element_Array |
(0 .. Stream_Element_Count (Size (Stream) - Min_End_Start)); |
Ilb : Stream_Element_Offset; |
X : Zs_Size_Type; |
begin |
Blockread (Stream, Large_Buffer); |
for I in reverse Min_End_Start .. Size (Stream) - 21 loop |
-- Yes, we must _search_ for the header... |
-- because PKWARE put a variable-size comment _after_ it 8-( |
Ilb := Stream_Element_Offset (I - Min_End_Start); |
if Pk_Signature (Large_Buffer (Ilb .. Ilb + 3), 5) then |
Copy_And_Check (Large_Buffer (Ilb .. Ilb + 21), The_End); |
-- At this point, the buffer was successfully read, the_end is |
-- is set with its standard contents. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.