Source file : bzip2_dec.adb
1 -- Standalone BZip2 decoder (for .bz2 files)
2
3 with BZip2.Decoding;
4
5 with Ada.Text_IO,
6 Ada.Streams.Stream_IO,
7 Ada.Command_Line;
8
9 procedure BZip2_Dec is
10
11 use Ada.Streams.Stream_IO, BZip2;
12
13 f_in, f_out : Ada.Streams.Stream_IO.File_Type;
14
15 -- NB: The Byte I/O below is not buffered, so it is very slow.
16 -- You need to implement a circular buffer of type Stream_Element_Array for a fast I/O.
17 -- For instance, see the BlockRead in the Zip package for how to do it.
18
19 function Demo_Read_Byte return Byte is
20 b : Byte;
21 begin
22 Byte'Read (Stream (f_in), b);
23 return b;
24 end Demo_Read_Byte;
25
26 procedure Demo_Write_Byte (b : Byte) is
27 begin
28 Byte'Write (Stream (f_out), b);
29 end Demo_Write_Byte;
30
31 package My_BZip2 is new BZip2.Decoding
32 (Demo_Read_Byte, Demo_Write_Byte, check_CRC => True);
33
34 use Ada.Command_Line, Ada.Text_IO;
35
36 default : constant String := "bunzip.out";
37
38 begin
39 if Argument_Count = 0 then
40 Put_Line ("BZip2_Dec: a standalone BZip2 decoder.");
41 New_Line;
42 Put_Line ("Usage: bzip2_dec infile.bz2 {outfile}");
43 New_Line;
44 Put_Line ("Decompresses a bzip2 compressed file (.bz2)");
45 Put_Line ("Output: if outfile is not given, the name """ & default & """ will be used");
46 New_Line;
47 Put ("Press Return");
48 Skip_Line;
49 else
50 Open (f_in, In_File, Argument (1));
51 Create (f_out, Out_File, (if Argument_Count > 1 then Argument (2) else default));
52 My_BZip2.Decompress;
53 Close (f_out);
54 end if;
55 end BZip2_Dec;
Web view of Ada source code generated by GNATHTML, project: ALI_Parse version 1.0.
Zip-Ada: Ada library for zip archive files (.zip).
Ada programming.
Some news about Zip-Ada and other Ada projects
on Gautier's blog.