zlib-streams.ads 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ----------------------------------------------------------------
  2. -- ZLib for Ada thick binding. --
  3. -- --
  4. -- Copyright (C) 2002-2003 Dmitriy Anisimkov --
  5. -- --
  6. -- Open source license information is in the zlib.ads file. --
  7. ----------------------------------------------------------------
  8. -- $Id: zlib-streams.ads,v 1.12 2004/05/31 10:53:40 vagul Exp $
  9. package ZLib.Streams is
  10. type Stream_Mode is (In_Stream, Out_Stream, Duplex);
  11. type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
  12. type Stream_Type is
  13. new Ada.Streams.Root_Stream_Type with private;
  14. procedure Read
  15. (Stream : in out Stream_Type;
  16. Item : out Ada.Streams.Stream_Element_Array;
  17. Last : out Ada.Streams.Stream_Element_Offset);
  18. procedure Write
  19. (Stream : in out Stream_Type;
  20. Item : in Ada.Streams.Stream_Element_Array);
  21. procedure Flush
  22. (Stream : in out Stream_Type;
  23. Mode : in Flush_Mode := Sync_Flush);
  24. -- Flush the written data to the back stream,
  25. -- all data placed to the compressor is flushing to the Back stream.
  26. -- Should not be used untill necessary, becouse it is decreasing
  27. -- compression.
  28. function Read_Total_In (Stream : in Stream_Type) return Count;
  29. pragma Inline (Read_Total_In);
  30. -- Return total number of bytes read from back stream so far.
  31. function Read_Total_Out (Stream : in Stream_Type) return Count;
  32. pragma Inline (Read_Total_Out);
  33. -- Return total number of bytes read so far.
  34. function Write_Total_In (Stream : in Stream_Type) return Count;
  35. pragma Inline (Write_Total_In);
  36. -- Return total number of bytes written so far.
  37. function Write_Total_Out (Stream : in Stream_Type) return Count;
  38. pragma Inline (Write_Total_Out);
  39. -- Return total number of bytes written to the back stream.
  40. procedure Create
  41. (Stream : out Stream_Type;
  42. Mode : in Stream_Mode;
  43. Back : in Stream_Access;
  44. Back_Compressed : in Boolean;
  45. Level : in Compression_Level := Default_Compression;
  46. Strategy : in Strategy_Type := Default_Strategy;
  47. Header : in Header_Type := Default;
  48. Read_Buffer_Size : in Ada.Streams.Stream_Element_Offset
  49. := Default_Buffer_Size;
  50. Write_Buffer_Size : in Ada.Streams.Stream_Element_Offset
  51. := Default_Buffer_Size);
  52. -- Create the Comression/Decompression stream.
  53. -- If mode is In_Stream then Write operation is disabled.
  54. -- If mode is Out_Stream then Read operation is disabled.
  55. -- If Back_Compressed is true then
  56. -- Data written to the Stream is compressing to the Back stream
  57. -- and data read from the Stream is decompressed data from the Back stream.
  58. -- If Back_Compressed is false then
  59. -- Data written to the Stream is decompressing to the Back stream
  60. -- and data read from the Stream is compressed data from the Back stream.
  61. -- !!! When the Need_Header is False ZLib-Ada is using undocumented
  62. -- ZLib 1.1.4 functionality to do not create/wait for ZLib headers.
  63. function Is_Open (Stream : Stream_Type) return Boolean;
  64. procedure Close (Stream : in out Stream_Type);
  65. private
  66. use Ada.Streams;
  67. type Buffer_Access is access all Stream_Element_Array;
  68. type Stream_Type
  69. is new Root_Stream_Type with
  70. record
  71. Mode : Stream_Mode;
  72. Buffer : Buffer_Access;
  73. Rest_First : Stream_Element_Offset;
  74. Rest_Last : Stream_Element_Offset;
  75. -- Buffer for Read operation.
  76. -- We need to have this buffer in the record
  77. -- becouse not all read data from back stream
  78. -- could be processed during the read operation.
  79. Buffer_Size : Stream_Element_Offset;
  80. -- Buffer size for write operation.
  81. -- We do not need to have this buffer
  82. -- in the record becouse all data could be
  83. -- processed in the write operation.
  84. Back : Stream_Access;
  85. Reader : Filter_Type;
  86. Writer : Filter_Type;
  87. end record;
  88. end ZLib.Streams;