Class: Zstdlib::ZStream
- Inherits:
-
Object
- Object
- Zstdlib::ZStream
- Defined in:
- ext/zstdlib/ruby/zlib-2.7/zstdlib.c,
ext/zstdlib/ruby/zlib-2.7/zstdlib.c,
ext/zstdlib/ruby/zlib-2.6/zstdlib.c,
ext/zstdlib/ruby/zlib-2.6/zstdlib.c,
ext/zstdlib/ruby/zlib-2.5/zstdlib.c,
ext/zstdlib/ruby/zlib-2.5/zstdlib.c,
ext/zstdlib/ruby/zlib-2.4/zstdlib.c,
ext/zstdlib/ruby/zlib-2.4/zstdlib.c,
ext/zstdlib/ruby/zlib-2.3/zstdlib.c,
ext/zstdlib/ruby/zlib-2.3/zstdlib.c,
ext/zstdlib/ruby/zlib-2.2/zstdlib.c,
ext/zstdlib/ruby/zlib-2.2/zstdlib.c
Overview
Zstdlib::ZStream is the abstract class for the stream which handles the compressed data. The operations are defined in the subclasses: Zstdlib::Deflate for compression, and Zstdlib::Inflate for decompression.
An instance of Zstdlib::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 Zstdlib::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 Zstdlib::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 Zstdlib::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 Zstdlib::Inflate and Zstdlib::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=(size) ⇒ Object
Allocates +size+ bytes 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
-
#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.
1438 1439 1440 1441 1442 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1438 static VALUE rb_zstream_adler(VALUE obj) { return rb_uint2inum(get_zstream(obj)->stream.adler); } |
#avail_in ⇒ Object
Returns bytes of data in the input buffer. Normally, returns 0.
1398 1399 1400 1401 1402 1403 1404 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1398 static VALUE rb_zstream_avail_in(VALUE obj) { struct zstream *z; TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z); return INT2FIX(NIL_P(z->input) ? 0 : (int)(RSTRING_LEN(z->input))); } |
#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.
1372 1373 1374 1375 1376 1377 1378 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1372 static VALUE rb_zstream_avail_out(VALUE obj) { struct zstream *z; TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z); return rb_uint2inum(z->stream.avail_out); } |
#avail_out=(size) ⇒ 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.
1386 1387 1388 1389 1390 1391 1392 1393 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1386 static VALUE rb_zstream_set_avail_out(VALUE obj, VALUE size) { struct zstream *z = get_zstream(obj); (z, FIX2INT(size)); return size; } |
#close ⇒ Object
Closes the stream. All operations on the closed stream will raise an exception.
1296 1297 1298 1299 1300 1301 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1296 static VALUE rb_zstream_end(VALUE obj) { zstream_end(get_zstream(obj)); return Qnil; } |
#closed? ⇒ Boolean
Returns true if the stream is closed.
1456 1457 1458 1459 1460 1461 1462 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1456 static VALUE rb_zstream_closed_p(VALUE obj) { struct zstream *z; TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z); return ZSTREAM_IS_READY(z) ? Qfalse : Qtrue; } |
#data_type ⇒ Object
Guesses the type of the data which have been inputed into the stream. The returned value is either BINARY, ASCII, or UNKNOWN.
1429 1430 1431 1432 1433 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1429 static VALUE rb_zstream_data_type(VALUE obj) { return INT2FIX(get_zstream(obj)->stream.data_type); } |
#end ⇒ Object
Closes the stream. All operations on the closed stream will raise an exception.
1296 1297 1298 1299 1300 1301 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1296 static VALUE rb_zstream_end(VALUE obj) { zstream_end(get_zstream(obj)); return Qnil; } |
#ended? ⇒ Boolean
Returns true if the stream is closed.
1456 1457 1458 1459 1460 1461 1462 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1456 static VALUE rb_zstream_closed_p(VALUE obj) { struct zstream *z; TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z); return ZSTREAM_IS_READY(z) ? Qfalse : Qtrue; } |
#finish ⇒ String #finish {|chunk| ... } ⇒ nil
Finishes the stream and flushes output buffer. If a block is given each chunk is yielded to the block until the input buffer has been flushed to the output buffer.
1323 1324 1325 1326 1327 1328 1329 1330 1331 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1323 static VALUE rb_zstream_finish(VALUE obj) { struct zstream *z = get_zstream(obj); zstream_run(z, (Bytef*)"", 0, Z_FINISH); return zstream_detach_buffer(z); } |
#finished? ⇒ Boolean
Returns true if the stream is finished.
1447 1448 1449 1450 1451 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1447 static VALUE rb_zstream_finished_p(VALUE obj) { return ZSTREAM_IS_FINISHED(get_zstream(obj)) ? Qtrue : Qfalse; } |
#flush_next_in ⇒ Object
1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1338 static VALUE rb_zstream_flush_next_in(VALUE obj) { struct zstream *z; VALUE dst; TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z); dst = zstream_detach_input(z); return dst; } |
#flush_next_out ⇒ String #flush_next_out {|chunk| ... } ⇒ nil
Flushes output buffer and returns all data in that buffer. If a block is given each chunk is yielded to the block until the current output buffer has been flushed.
1358 1359 1360 1361 1362 1363 1364 1365 1366 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1358 static VALUE rb_zstream_flush_next_out(VALUE obj) { struct zstream *z; TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z); return zstream_detach_buffer(z); } |
#reset ⇒ Object
Resets and initializes the stream. All data in both input and output buffer are discarded.
1307 1308 1309 1310 1311 1312 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1307 static VALUE rb_zstream_reset(VALUE obj) { zstream_reset(get_zstream(obj)); return Qnil; } |
#stream_end? ⇒ Boolean
Returns true if the stream is finished.
1447 1448 1449 1450 1451 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1447 static VALUE rb_zstream_finished_p(VALUE obj) { return ZSTREAM_IS_FINISHED(get_zstream(obj)) ? Qtrue : Qfalse; } |
#total_in ⇒ Object
Returns the total bytes of the input data to the stream. FIXME
1409 1410 1411 1412 1413 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1409 static VALUE rb_zstream_total_in(VALUE obj) { return rb_uint2inum(get_zstream(obj)->stream.total_in); } |
#total_out ⇒ Object
Returns the total bytes of the output data from the stream. FIXME
1418 1419 1420 1421 1422 |
# File 'ext/zstdlib/ruby/zlib-2.7/zstdlib.c', line 1418 static VALUE rb_zstream_total_out(VALUE obj) { return rb_uint2inum(get_zstream(obj)->stream.total_out); } |