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