Class: Zlib::ZStream
- Inherits:
-
Object
- Object
- Zlib::ZStream
- Defined in:
- zlib.c,
zlib.c
Overview
Zlib::ZStream is the abstract class for the stream which handles the compressed data. The operations are defined in the subclasses: Zlib::Deflate for compression, and Zlib::Inflate for decompression.
An instance of Zlib::ZStream has one stream (struct zstream in the source) and two variable-length buffers which associated to the input (next_in) of the stream and the output (next_out) of the stream. In this document, “input buffer” means the buffer for input, and “output buffer” means the buffer for output.
Data input into an instance of Zlib::ZStream are temporally stored into the end of input buffer, and then data in input buffer are processed from the beginning of the buffer until no more output from the stream is produced (i.e. until avail_out > 0 after processing). During processing, output buffer is allocated and expanded automatically to hold all output data.
Some particular instance methods consume the data in output buffer and return them as a String.
Here is an ascii art for describing above:
+================ an instance of Zlib::ZStream ================+
|| ||
|| +--------+ +-------+ +--------+ ||
|| +--| output |<---------|zstream|<---------| input |<--+ ||
|| | | buffer | next_out+-------+next_in | buffer | | ||
|| | +--------+ +--------+ | ||
|| | | ||
+===|======================================================|===+
| |
v |
"output data" "input data"
If an error occurs during processing input buffer, an exception which is a subclass of Zlib::Error is raised. At that time, both input and output buffer keep their conditions at the time when the error occurs.
Method Catalogue
Many of the methods in this class are fairly low-level and unlikely to be of interest to users. In fact, users are unlikely to use this class directly; rather they will be interested in Zlib::Inflate and Zlib::Deflate.
The higher level methods are listed below.
-
#total_in
-
#total_out
-
#data_type
-
#adler
-
#reset
-
#finish
-
#finished?
-
#close
-
#closed?
Instance Method Summary collapse
-
#adler ⇒ Object
Returns the adler-32 checksum.
-
#avail_in ⇒ Object
Returns bytes of data in the input buffer.
-
#avail_out ⇒ Object
Returns number of bytes of free spaces in output buffer.
-
#avail_out= ⇒ Object
Allocates
sizebytes of free space in the output buffer. -
#close ⇒ Object
Closes the stream.
-
#closed? ⇒ Boolean
Returns true if the stream is closed.
-
#data_type ⇒ Object
Guesses the type of the data which have been inputed into the stream.
-
#end ⇒ Object
Closes the stream.
-
#ended? ⇒ Boolean
Returns true if the stream is closed.
-
#finish ⇒ Object
Finishes the stream and flushes output buffer.
-
#finished? ⇒ Boolean
Returns true if the stream is finished.
-
#flush_next_in ⇒ Object
Flushes input buffer and returns all data in that buffer.
-
#flush_next_out ⇒ Object
Flushes output buffer and returns all data in that buffer.
-
#reset ⇒ Object
Resets and initializes the stream.
-
#stream_end? ⇒ Boolean
Returns true if the stream is finished.
-
#total_in ⇒ Object
Returns the total bytes of the input data to the stream.
-
#total_out ⇒ Object
Returns the total bytes of the output data from the stream.
Instance Method Details
#adler ⇒ Object
Returns the adler-32 checksum.
1088 1089 1090 |
# File 'zlib.c', line 1088 static VALUE rb_zstream_adler(obj) VALUE obj; |
#avail_in ⇒ Object
Returns bytes of data in the input buffer. Normally, returns 0.
1044 1045 1046 |
# File 'zlib.c', line 1044 static VALUE rb_zstream_avail_in(obj) VALUE obj; |
#avail_out ⇒ Object
Returns number of bytes of free spaces in output buffer. Because the free space is allocated automatically, this method returns 0 normally.
1015 1016 1017 |
# File 'zlib.c', line 1015 static VALUE rb_zstream_avail_out(obj) VALUE obj; |
#avail_out= ⇒ Object
Allocates size bytes of free space in the output buffer. If there are more than size bytes already in the buffer, the buffer is truncated. Because free space is allocated automatically, you usually don’t need to use this method.
1030 1031 1032 |
# File 'zlib.c', line 1030 static VALUE rb_zstream_set_avail_out(obj, size) VALUE obj, size; |
#close ⇒ Object
Closes the stream. All operations on the closed stream will raise an exception.
941 942 943 |
# File 'zlib.c', line 941 static VALUE rb_zstream_end(obj) VALUE obj; |
#closed? ⇒ Boolean
Returns true if the stream is closed.
1108 1109 1110 |
# File 'zlib.c', line 1108 static VALUE rb_zstream_closed_p(obj) VALUE obj; |
#data_type ⇒ Object
Guesses the type of the data which have been inputed into the stream. The returned value is either Zlib::BINARY, Zlib::ASCII, or Zlib::UNKNOWN.
1078 1079 1080 |
# File 'zlib.c', line 1078 static VALUE rb_zstream_data_type(obj) VALUE obj; |
#end ⇒ Object
Closes the stream. All operations on the closed stream will raise an exception.
941 942 943 |
# File 'zlib.c', line 941 static VALUE rb_zstream_end(obj) VALUE obj; |
#ended? ⇒ Boolean
Returns true if the stream is closed.
1108 1109 1110 |
# File 'zlib.c', line 1108 static VALUE rb_zstream_closed_p(obj) VALUE obj; |
#finish ⇒ Object
Finishes the stream and flushes output buffer. See Zlib::Deflate#finish and Zlib::Inflate#finish for details of this behavior.
965 966 967 |
# File 'zlib.c', line 965 static VALUE rb_zstream_finish(obj) VALUE obj; |
#finished? ⇒ Boolean
Returns true if the stream is finished.
1098 1099 1100 |
# File 'zlib.c', line 1098 static VALUE rb_zstream_finished_p(obj) VALUE obj; |
#flush_next_in ⇒ Object
Flushes input buffer and returns all data in that buffer.
982 983 984 |
# File 'zlib.c', line 982 static VALUE rb_zstream_flush_next_in(obj) VALUE obj; |
#flush_next_out ⇒ Object
Flushes output buffer and returns all data in that buffer.
998 999 1000 |
# File 'zlib.c', line 998 static VALUE rb_zstream_flush_next_out(obj) VALUE obj; |
#reset ⇒ Object
Resets and initializes the stream. All data in both input and output buffer are discarded.
953 954 955 |
# File 'zlib.c', line 953 static VALUE rb_zstream_reset(obj) VALUE obj; |
#stream_end? ⇒ Boolean
Returns true if the stream is finished.
1098 1099 1100 |
# File 'zlib.c', line 1098 static VALUE rb_zstream_finished_p(obj) VALUE obj; |
#total_in ⇒ Object
Returns the total bytes of the input data to the stream. FIXME
1056 1057 1058 |
# File 'zlib.c', line 1056 static VALUE rb_zstream_total_in(obj) VALUE obj; |
#total_out ⇒ Object
Returns the total bytes of the output data from the stream. FIXME
1066 1067 1068 |
# File 'zlib.c', line 1066 static VALUE rb_zstream_total_out(obj) VALUE obj; |