with Allegro.Files; use Allegro.Files;
-- This package is a high-level API for streaming to and from standard Allegro
-- packfiles using standard Ada streams.
package Streams.Packfiles is
-- A Packfile_Stream is a stream implementation backed by an Allegro
-- packfile. The stream can own the packfile and close it automatically if
-- the stream is constructed with Open_Stream, or the stream can be wrapped
-- around an existing packfile for streaming by using the Stream function.
-- Both reading and writing is supported.
type Packfile_Stream is new Root_Stream_Type with private;
type A_Packfile_Stream is access all Packfile_Stream'Class;
----------------------------------------------------------------------------
-- Opens a packfile on disk for streaming operations. The underlying
-- packfile will be automatically opened and closed by the stream.
function Open_Stream( filename, mode : String ) return A_Packfile_Stream;
-- Creates a stream using an open packfile. 'f' remains owned by the caller
-- and should not be freed until the stream has been closed.
function Stream( f : not null A_Packfile ) return A_Packfile_Stream;
-- Returns True of the stream reading has reached end-of-file.
function EOF( stream : not null access Packfile_Stream'Class ) return Boolean;
-- Returns True if the stream encountered an error. This is a wrapper around
-- Pack_FError.
function Error( stream : not null access Packfile_Stream'Class ) return Boolean;
-- Closes the stream. If the stream was constructed with the Stream function,
-- its packfile reference will simply be discarded because the stream does
-- not own it.
procedure Close( stream : in out A_Packfile_Stream );
private
type Packfile_Stream is new Root_Stream_Type with record
packfile : A_Packfile := null;
doClose : Boolean := False; -- True if the stream's underlying
-- packfile was opened by the packfile
-- stream (Open_Stream) and should be
-- closed when the stream is closed.
end record;
procedure Read( stream : in out Packfile_Stream;
item : out Stream_Element_Array;
last : out Stream_Element_Offset );
procedure Write( stream : in out Packfile_Stream;
item : Stream_Element_Array );
end Streams.Packfiles;