1. with Allegro.Files;                     use Allegro.Files; 
  2.  
  3. -- This package is a high-level API for streaming to and from standard Allegro 
  4. -- packfiles using standard Ada streams. 
  5.  
  6. package Streams.Packfiles is 
  7.  
  8.     -- A Packfile_Stream is a stream implementation backed by an Allegro 
  9.     -- packfile. The stream can own the packfile and close it automatically if 
  10.     -- the stream is constructed with Open_Stream, or the stream can be wrapped 
  11.     -- around an existing packfile for streaming by using the Stream function. 
  12.     -- Both reading and writing is supported. 
  13.     type Packfile_Stream is new Root_Stream_Type with private; 
  14.     type A_Packfile_Stream is access all Packfile_Stream'Class; 
  15.  
  16.     ---------------------------------------------------------------------------- 
  17.  
  18.     -- Opens a packfile on disk for streaming operations. The underlying 
  19.     -- packfile will be automatically opened and closed by the stream. 
  20.     function Open_Stream( filename, mode : String ) return A_Packfile_Stream; 
  21.  
  22.     -- Creates a stream using an open packfile. 'f' remains owned by the caller 
  23.     -- and should not be freed until the stream has been closed. 
  24.     function Stream( f : not null A_Packfile ) return A_Packfile_Stream; 
  25.  
  26.     -- Returns True of the stream reading has reached end-of-file. 
  27.     function EOF( stream : not null access Packfile_Stream'Class ) return Boolean; 
  28.  
  29.     -- Returns True if the stream encountered an error. This is a wrapper around 
  30.     -- Pack_FError. 
  31.     function Error( stream : not null access Packfile_Stream'Class ) return Boolean; 
  32.  
  33.     -- Closes the stream. If the stream was constructed with the Stream function, 
  34.     -- its packfile reference will simply be discarded because the stream does 
  35.     -- not own it. 
  36.     procedure Close( stream : in out A_Packfile_Stream ); 
  37.  
  38. private 
  39.  
  40.     type Packfile_Stream is new Root_Stream_Type with record 
  41.         packfile : A_Packfile := null; 
  42.         doClose  : Boolean := False;  -- True if the stream's underlying 
  43.                                       -- packfile was opened by the packfile 
  44.                                       -- stream (Open_Stream) and should be 
  45.                                       -- closed when the stream is closed. 
  46.     end record; 
  47.  
  48.     procedure Read( stream : in out Packfile_Stream; 
  49.                     item   : out Stream_Element_Array; 
  50.                     last   : out Stream_Element_Offset ); 
  51.  
  52.     procedure Write( stream : in out Packfile_Stream; 
  53.                      item   : Stream_Element_Array ); 
  54.  
  55. end Streams.Packfiles;