Class: Zlib::ZStream

Inherits:
Object
  • Object
show all
Defined in:
ext/rubysl/zlib/zlib.c,
ext/rubysl/zlib/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?

Direct Known Subclasses

Deflate, Inflate

Instance Method Summary collapse

Instance Method Details

#adlerObject

Returns the adler-32 checksum.



1091
1092
1093
# File 'ext/rubysl/zlib/zlib.c', line 1091

static VALUE
rb_zstream_adler(obj)
VALUE obj;

#avail_inObject

Returns bytes of data in the input buffer. Normally, returns 0.



1047
1048
1049
# File 'ext/rubysl/zlib/zlib.c', line 1047

static VALUE
rb_zstream_avail_in(obj)
VALUE obj;

#avail_outObject

Returns number of bytes of free spaces in output buffer. Because the free space is allocated automatically, this method returns 0 normally.



1018
1019
1020
# File 'ext/rubysl/zlib/zlib.c', line 1018

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.



1033
1034
1035
# File 'ext/rubysl/zlib/zlib.c', line 1033

static VALUE
rb_zstream_set_avail_out(obj, size)
VALUE obj, size;

#closeObject

Closes the stream. All operations on the closed stream will raise an exception.



944
945
946
# File 'ext/rubysl/zlib/zlib.c', line 944

static VALUE
rb_zstream_end(obj)
VALUE obj;

#closed?Boolean

Returns true if the stream is closed.

Returns:

  • (Boolean)


1111
1112
1113
# File 'ext/rubysl/zlib/zlib.c', line 1111

static VALUE
rb_zstream_closed_p(obj)
VALUE obj;

#data_typeObject

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.



1081
1082
1083
# File 'ext/rubysl/zlib/zlib.c', line 1081

static VALUE
rb_zstream_data_type(obj)
VALUE obj;

#endObject

Closes the stream. All operations on the closed stream will raise an exception.



944
945
946
# File 'ext/rubysl/zlib/zlib.c', line 944

static VALUE
rb_zstream_end(obj)
VALUE obj;

#ended?Boolean

Returns true if the stream is closed.

Returns:

  • (Boolean)


1111
1112
1113
# File 'ext/rubysl/zlib/zlib.c', line 1111

static VALUE
rb_zstream_closed_p(obj)
VALUE obj;

#finishObject

Finishes the stream and flushes output buffer. See Zlib::Deflate#finish and Zlib::Inflate#finish for details of this behavior.



968
969
970
# File 'ext/rubysl/zlib/zlib.c', line 968

static VALUE
rb_zstream_finish(obj)
VALUE obj;

#finished?Boolean

Returns true if the stream is finished.

Returns:

  • (Boolean)


1101
1102
1103
# File 'ext/rubysl/zlib/zlib.c', line 1101

static VALUE
rb_zstream_finished_p(obj)
VALUE obj;

#flush_next_inObject

Flushes input buffer and returns all data in that buffer.



985
986
987
# File 'ext/rubysl/zlib/zlib.c', line 985

static VALUE
rb_zstream_flush_next_in(obj)
VALUE obj;

#flush_next_outObject

Flushes output buffer and returns all data in that buffer.



1001
1002
1003
# File 'ext/rubysl/zlib/zlib.c', line 1001

static VALUE
rb_zstream_flush_next_out(obj)
VALUE obj;

#resetObject

Resets and initializes the stream. All data in both input and output buffer are discarded.



956
957
958
# File 'ext/rubysl/zlib/zlib.c', line 956

static VALUE
rb_zstream_reset(obj)
VALUE obj;

#stream_end?Boolean

Returns true if the stream is finished.

Returns:

  • (Boolean)


1101
1102
1103
# File 'ext/rubysl/zlib/zlib.c', line 1101

static VALUE
rb_zstream_finished_p(obj)
VALUE obj;

#total_inObject

Returns the total bytes of the input data to the stream. FIXME



1059
1060
1061
# File 'ext/rubysl/zlib/zlib.c', line 1059

static VALUE
rb_zstream_total_in(obj)
VALUE obj;

#total_outObject

Returns the total bytes of the output data from the stream. FIXME



1069
1070
1071
# File 'ext/rubysl/zlib/zlib.c', line 1069

static VALUE
rb_zstream_total_out(obj)
VALUE obj;