zstdlib 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +8 -0
- data/README.md +5 -2
- data/ext/zstdlib/extconf.rb +1 -11
- data/ext/zstdlib/ruby/zlib-2.2/{zlib.c → zstdlib.c} +279 -263
- data/ext/zstdlib/ruby/zlib-2.3/{zlib.c → zstdlib.c} +281 -265
- data/ext/zstdlib/ruby/zlib-2.4/{zlib.c → zstdlib.c} +290 -274
- data/ext/zstdlib/ruby/zlib-2.5/{zlib.c → zstdlib.c} +290 -274
- data/ext/zstdlib/ruby/zlib-2.6/{zlib.c → zstdlib.c} +290 -274
- metadata +7 -7
@@ -1,3 +1,4 @@
|
|
1
|
+
#include <zstd.h>
|
1
2
|
/*
|
2
3
|
* zlib.c - An interface for zlib.
|
3
4
|
*
|
@@ -7,7 +8,7 @@
|
|
7
8
|
*/
|
8
9
|
|
9
10
|
#include <ruby.h>
|
10
|
-
#include <
|
11
|
+
#include <zstd_zlibwrapper.h>
|
11
12
|
#include <time.h>
|
12
13
|
#include <ruby/io.h>
|
13
14
|
#include <ruby/thread.h>
|
@@ -250,48 +251,48 @@ static VALUE rb_gzreader_readlines(int, VALUE*, VALUE);
|
|
250
251
|
* Using the wrapper to compress strings with default parameters is quite
|
251
252
|
* simple:
|
252
253
|
*
|
253
|
-
* require "
|
254
|
+
* require "zstdlib"
|
254
255
|
*
|
255
256
|
* data_to_compress = File.read("don_quixote.txt")
|
256
257
|
*
|
257
258
|
* puts "Input size: #{data_to_compress.size}"
|
258
259
|
* #=> Input size: 2347740
|
259
260
|
*
|
260
|
-
* data_compressed =
|
261
|
+
* data_compressed = Zstdlib::Deflate.deflate(data_to_compress)
|
261
262
|
*
|
262
263
|
* puts "Compressed size: #{data_compressed.size}"
|
263
264
|
* #=> Compressed size: 887238
|
264
265
|
*
|
265
|
-
* uncompressed_data =
|
266
|
+
* uncompressed_data = Zstdlib::Inflate.inflate(data_compressed)
|
266
267
|
*
|
267
268
|
* puts "Uncompressed data is: #{uncompressed_data}"
|
268
269
|
* #=> Uncompressed data is: The Project Gutenberg EBook of Don Quixote...
|
269
270
|
*
|
270
271
|
* == Class tree
|
271
272
|
*
|
272
|
-
* -
|
273
|
-
* -
|
274
|
-
* -
|
275
|
-
* -
|
276
|
-
* -
|
277
|
-
* -
|
278
|
-
* -
|
279
|
-
* -
|
280
|
-
* -
|
281
|
-
* -
|
282
|
-
* -
|
273
|
+
* - Zstdlib::Deflate
|
274
|
+
* - Zstdlib::Inflate
|
275
|
+
* - Zstdlib::ZStream
|
276
|
+
* - Zstdlib::Error
|
277
|
+
* - Zstdlib::StreamEnd
|
278
|
+
* - Zstdlib::NeedDict
|
279
|
+
* - Zstdlib::DataError
|
280
|
+
* - Zstdlib::StreamError
|
281
|
+
* - Zstdlib::MemError
|
282
|
+
* - Zstdlib::BufError
|
283
|
+
* - Zstdlib::VersionError
|
283
284
|
*
|
284
285
|
* (if you have GZIP_SUPPORT)
|
285
|
-
* -
|
286
|
-
* -
|
287
|
-
* -
|
288
|
-
* -
|
289
|
-
* -
|
290
|
-
* -
|
291
|
-
* -
|
286
|
+
* - Zstdlib::GzipReader
|
287
|
+
* - Zstdlib::GzipWriter
|
288
|
+
* - Zstdlib::GzipFile
|
289
|
+
* - Zstdlib::GzipFile::Error
|
290
|
+
* - Zstdlib::GzipFile::LengthError
|
291
|
+
* - Zstdlib::GzipFile::CRCError
|
292
|
+
* - Zstdlib::GzipFile::NoFooter
|
292
293
|
*
|
293
294
|
*/
|
294
|
-
void
|
295
|
+
void Init_zstdlib(void);
|
295
296
|
|
296
297
|
/*--------- Exceptions --------*/
|
297
298
|
|
@@ -351,9 +352,22 @@ finalizer_warn(const char *msg)
|
|
351
352
|
|
352
353
|
|
353
354
|
/*-------- module Zlib --------*/
|
355
|
+
/*
|
356
|
+
* Document-method: Zstdlib.zstd_version
|
357
|
+
*
|
358
|
+
* Returns the string which represents the version of zstd library.
|
359
|
+
*/
|
360
|
+
static VALUE
|
361
|
+
rb_zstd_version(VALUE klass)
|
362
|
+
{
|
363
|
+
VALUE str;
|
364
|
+
str = rb_str_new2(ZSTD_versionString());
|
365
|
+
OBJ_TAINT(str);
|
366
|
+
return str;
|
367
|
+
}
|
354
368
|
|
355
369
|
/*
|
356
|
-
* Document-method:
|
370
|
+
* Document-method: Zstdlib.zlib_version
|
357
371
|
*
|
358
372
|
* Returns the string which represents the version of zlib library.
|
359
373
|
*/
|
@@ -414,9 +428,9 @@ do_checksum(int argc, VALUE *argv, uLong (*func)(uLong, const Bytef*, uInt))
|
|
414
428
|
}
|
415
429
|
|
416
430
|
/*
|
417
|
-
* Document-method:
|
431
|
+
* Document-method: Zstdlib.adler32
|
418
432
|
*
|
419
|
-
* call-seq:
|
433
|
+
* call-seq: Zstdlib.adler32(string, adler)
|
420
434
|
*
|
421
435
|
* Calculates Adler-32 checksum for +string+, and returns updated value of
|
422
436
|
* +adler+. If +string+ is omitted, it returns the Adler-32 initial value. If
|
@@ -424,10 +438,10 @@ do_checksum(int argc, VALUE *argv, uLong (*func)(uLong, const Bytef*, uInt))
|
|
424
438
|
*
|
425
439
|
* Example usage:
|
426
440
|
*
|
427
|
-
* require "
|
441
|
+
* require "zstdlib"
|
428
442
|
*
|
429
443
|
* data = "foo"
|
430
|
-
* puts "Adler32 checksum: #{
|
444
|
+
* puts "Adler32 checksum: #{Zstdlib.adler32(data).to_s(16)}"
|
431
445
|
* #=> Adler32 checksum: 2820145
|
432
446
|
*
|
433
447
|
*/
|
@@ -439,9 +453,9 @@ rb_zlib_adler32(int argc, VALUE *argv, VALUE klass)
|
|
439
453
|
|
440
454
|
#ifdef HAVE_ADLER32_COMBINE
|
441
455
|
/*
|
442
|
-
* Document-method:
|
456
|
+
* Document-method: Zstdlib.adler32_combine
|
443
457
|
*
|
444
|
-
* call-seq:
|
458
|
+
* call-seq: Zstdlib.adler32_combine(adler1, adler2, len2)
|
445
459
|
*
|
446
460
|
* Combine two Adler-32 check values in to one. +alder1+ is the first Adler-32
|
447
461
|
* value, +adler2+ is the second Adler-32 value. +len2+ is the length of the
|
@@ -459,9 +473,9 @@ rb_zlib_adler32_combine(VALUE klass, VALUE adler1, VALUE adler2, VALUE len2)
|
|
459
473
|
#endif
|
460
474
|
|
461
475
|
/*
|
462
|
-
* Document-method:
|
476
|
+
* Document-method: Zstdlib.crc32
|
463
477
|
*
|
464
|
-
* call-seq:
|
478
|
+
* call-seq: Zstdlib.crc32(string, crc)
|
465
479
|
*
|
466
480
|
* Calculates CRC checksum for +string+, and returns updated value of +crc+. If
|
467
481
|
* +string+ is omitted, it returns the CRC initial value. If +crc+ is omitted, it
|
@@ -477,9 +491,9 @@ rb_zlib_crc32(int argc, VALUE *argv, VALUE klass)
|
|
477
491
|
|
478
492
|
#ifdef HAVE_CRC32_COMBINE
|
479
493
|
/*
|
480
|
-
* Document-method:
|
494
|
+
* Document-method: Zstdlib.crc32_combine
|
481
495
|
*
|
482
|
-
* call-seq:
|
496
|
+
* call-seq: Zstdlib.crc32_combine(crc1, crc2, len2)
|
483
497
|
*
|
484
498
|
* Combine two CRC-32 check values in to one. +crc1+ is the first CRC-32
|
485
499
|
* value, +crc2+ is the second CRC-32 value. +len2+ is the length of the
|
@@ -497,7 +511,7 @@ rb_zlib_crc32_combine(VALUE klass, VALUE crc1, VALUE crc2, VALUE len2)
|
|
497
511
|
#endif
|
498
512
|
|
499
513
|
/*
|
500
|
-
* Document-method:
|
514
|
+
* Document-method: Zstdlib.crc_table
|
501
515
|
*
|
502
516
|
* Returns the table for calculating CRC checksum as an array.
|
503
517
|
*/
|
@@ -1171,19 +1185,19 @@ get_zstream(VALUE obj)
|
|
1171
1185
|
/* ------------------------------------------------------------------------- */
|
1172
1186
|
|
1173
1187
|
/*
|
1174
|
-
* Document-class:
|
1188
|
+
* Document-class: Zstdlib::ZStream
|
1175
1189
|
*
|
1176
|
-
*
|
1190
|
+
* Zstdlib::ZStream is the abstract class for the stream which handles the
|
1177
1191
|
* compressed data. The operations are defined in the subclasses:
|
1178
|
-
*
|
1192
|
+
* Zstdlib::Deflate for compression, and Zstdlib::Inflate for decompression.
|
1179
1193
|
*
|
1180
|
-
* An instance of
|
1194
|
+
* An instance of Zstdlib::ZStream has one stream (struct zstream in the source)
|
1181
1195
|
* and two variable-length buffers which associated to the input (next_in) of
|
1182
1196
|
* the stream and the output (next_out) of the stream. In this document,
|
1183
1197
|
* "input buffer" means the buffer for input, and "output buffer" means the
|
1184
1198
|
* buffer for output.
|
1185
1199
|
*
|
1186
|
-
* Data input into an instance of
|
1200
|
+
* Data input into an instance of Zstdlib::ZStream are temporally stored into
|
1187
1201
|
* the end of input buffer, and then data in input buffer are processed from
|
1188
1202
|
* the beginning of the buffer until no more output from the stream is
|
1189
1203
|
* produced (i.e. until avail_out > 0 after processing). During processing,
|
@@ -1195,7 +1209,7 @@ get_zstream(VALUE obj)
|
|
1195
1209
|
*
|
1196
1210
|
* Here is an ascii art for describing above:
|
1197
1211
|
*
|
1198
|
-
* +================ an instance of
|
1212
|
+
* +================ an instance of Zstdlib::ZStream ================+
|
1199
1213
|
* || ||
|
1200
1214
|
* || +--------+ +-------+ +--------+ ||
|
1201
1215
|
* || +--| output |<---------|zstream|<---------| input |<--+ ||
|
@@ -1208,15 +1222,15 @@ get_zstream(VALUE obj)
|
|
1208
1222
|
* "output data" "input data"
|
1209
1223
|
*
|
1210
1224
|
* If an error occurs during processing input buffer, an exception which is a
|
1211
|
-
* subclass of
|
1225
|
+
* subclass of Zstdlib::Error is raised. At that time, both input and output
|
1212
1226
|
* buffer keep their conditions at the time when the error occurs.
|
1213
1227
|
*
|
1214
1228
|
* == Method Catalogue
|
1215
1229
|
*
|
1216
1230
|
* Many of the methods in this class are fairly low-level and unlikely to be
|
1217
1231
|
* of interest to users. In fact, users are unlikely to use this class
|
1218
|
-
* directly; rather they will be interested in
|
1219
|
-
*
|
1232
|
+
* directly; rather they will be interested in Zstdlib::Inflate and
|
1233
|
+
* Zstdlib::Deflate.
|
1220
1234
|
*
|
1221
1235
|
* The higher level methods are listed below.
|
1222
1236
|
*
|
@@ -1408,9 +1422,9 @@ rb_zstream_closed_p(VALUE obj)
|
|
1408
1422
|
/* ------------------------------------------------------------------------- */
|
1409
1423
|
|
1410
1424
|
/*
|
1411
|
-
* Document-class:
|
1425
|
+
* Document-class: Zstdlib::Deflate
|
1412
1426
|
*
|
1413
|
-
*
|
1427
|
+
* Zstdlib::Deflate is the class for compressing data. See Zstdlib::ZStream for more
|
1414
1428
|
* information.
|
1415
1429
|
*/
|
1416
1430
|
|
@@ -1418,7 +1432,7 @@ rb_zstream_closed_p(VALUE obj)
|
|
1418
1432
|
(NIL_P((val)) ? (ifnil) \
|
1419
1433
|
: (FIX2INT((val))))
|
1420
1434
|
|
1421
|
-
#define ARG_LEVEL(val) FIXNUMARG((val),
|
1435
|
+
#define ARG_LEVEL(val) FIXNUMARG((val), ZSTD_CLEVEL_DEFAULT)
|
1422
1436
|
#define ARG_WBITS(val) FIXNUMARG((val), MAX_WBITS)
|
1423
1437
|
#define ARG_MEMLEVEL(val) FIXNUMARG((val), DEF_MEM_LEVEL)
|
1424
1438
|
#define ARG_STRATEGY(val) FIXNUMARG((val), Z_DEFAULT_STRATEGY)
|
@@ -1432,10 +1446,10 @@ rb_deflate_s_allocate(VALUE klass)
|
|
1432
1446
|
}
|
1433
1447
|
|
1434
1448
|
/*
|
1435
|
-
* Document-method:
|
1449
|
+
* Document-method: Zstdlib::Deflate.new
|
1436
1450
|
*
|
1437
1451
|
* call-seq:
|
1438
|
-
*
|
1452
|
+
* Zstdlib::Deflate.new(level=DEFAULT_COMPRESSION, window_bits=MAX_WBITS, mem_level=DEF_MEM_LEVEL, strategy=DEFAULT_STRATEGY)
|
1439
1453
|
*
|
1440
1454
|
* Creates a new deflate stream for compression. If a given argument is nil,
|
1441
1455
|
* the default value of that argument is used.
|
@@ -1444,10 +1458,10 @@ rb_deflate_s_allocate(VALUE klass)
|
|
1444
1458
|
* compression) and 9 (best compression). The following constants have been
|
1445
1459
|
* defined to make code more readable:
|
1446
1460
|
*
|
1447
|
-
* *
|
1448
|
-
* *
|
1449
|
-
* *
|
1450
|
-
* *
|
1461
|
+
* * Zstdlib::DEFAULT_COMPRESSION
|
1462
|
+
* * Zstdlib::NO_COMPRESSION
|
1463
|
+
* * Zstdlib::BEST_SPEED
|
1464
|
+
* * Zstdlib::BEST_COMPRESSION
|
1451
1465
|
*
|
1452
1466
|
* See http://www.zlib.net/manual.html#Constants for further information.
|
1453
1467
|
*
|
@@ -1460,17 +1474,17 @@ rb_deflate_s_allocate(VALUE klass)
|
|
1460
1474
|
* compression ratio while 9 uses maximum memory for optimal speed. The
|
1461
1475
|
* default value is 8. Two constants are defined:
|
1462
1476
|
*
|
1463
|
-
* *
|
1464
|
-
* *
|
1477
|
+
* * Zstdlib::DEF_MEM_LEVEL
|
1478
|
+
* * Zstdlib::MAX_MEM_LEVEL
|
1465
1479
|
*
|
1466
1480
|
* The +strategy+ sets the deflate compression strategy. The following
|
1467
1481
|
* strategies are available:
|
1468
1482
|
*
|
1469
|
-
*
|
1470
|
-
*
|
1471
|
-
*
|
1472
|
-
*
|
1473
|
-
*
|
1483
|
+
* Zstdlib::DEFAULT_STRATEGY:: For normal data
|
1484
|
+
* Zstdlib::FILTERED:: For data produced by a filter or predictor
|
1485
|
+
* Zstdlib::FIXED:: Prevents dynamic Huffman codes
|
1486
|
+
* Zstdlib::HUFFMAN_ONLY:: Prevents string matching
|
1487
|
+
* Zstdlib::RLE:: Designed for better compression of PNG image data
|
1474
1488
|
*
|
1475
1489
|
* See the constants for further description.
|
1476
1490
|
*
|
@@ -1479,16 +1493,16 @@ rb_deflate_s_allocate(VALUE klass)
|
|
1479
1493
|
* === Basic
|
1480
1494
|
*
|
1481
1495
|
* open "compressed.file", "w+" do |io|
|
1482
|
-
* io <<
|
1496
|
+
* io << Zstdlib::Deflate.new.deflate(File.read("big.file"))
|
1483
1497
|
* end
|
1484
1498
|
*
|
1485
1499
|
* === Custom compression
|
1486
1500
|
*
|
1487
1501
|
* open "compressed.file", "w+" do |compressed_io|
|
1488
|
-
* deflate =
|
1489
|
-
*
|
1490
|
-
*
|
1491
|
-
*
|
1502
|
+
* deflate = Zstdlib::Deflate.new(Zstdlib::BEST_COMPRESSION,
|
1503
|
+
* Zstdlib::MAX_WBITS,
|
1504
|
+
* Zstdlib::MAX_MEM_LEVEL,
|
1505
|
+
* Zstdlib::HUFFMAN_ONLY)
|
1492
1506
|
*
|
1493
1507
|
* begin
|
1494
1508
|
* open "big.file" do |big_io|
|
@@ -1526,7 +1540,7 @@ rb_deflate_initialize(int argc, VALUE *argv, VALUE obj)
|
|
1526
1540
|
}
|
1527
1541
|
|
1528
1542
|
/*
|
1529
|
-
* Document-method:
|
1543
|
+
* Document-method: Zstdlib::Deflate#initialize_copy
|
1530
1544
|
*
|
1531
1545
|
* Duplicates the deflate stream.
|
1532
1546
|
*/
|
@@ -1562,26 +1576,26 @@ deflate_run(VALUE args)
|
|
1562
1576
|
}
|
1563
1577
|
|
1564
1578
|
/*
|
1565
|
-
* Document-method:
|
1579
|
+
* Document-method: Zstdlib::Deflate.deflate
|
1566
1580
|
*
|
1567
1581
|
* call-seq:
|
1568
|
-
*
|
1569
|
-
*
|
1582
|
+
* Zstdlib.deflate(string[, level])
|
1583
|
+
* Zstdlib::Deflate.deflate(string[, level])
|
1570
1584
|
*
|
1571
1585
|
* Compresses the given +string+. Valid values of level are
|
1572
|
-
*
|
1573
|
-
*
|
1586
|
+
* Zstdlib::NO_COMPRESSION, Zstdlib::BEST_SPEED, Zstdlib::BEST_COMPRESSION,
|
1587
|
+
* Zstdlib::DEFAULT_COMPRESSION, or an integer from 0 to 9.
|
1574
1588
|
*
|
1575
1589
|
* This method is almost equivalent to the following code:
|
1576
1590
|
*
|
1577
1591
|
* def deflate(string, level)
|
1578
|
-
* z =
|
1579
|
-
* dst = z.deflate(string,
|
1592
|
+
* z = Zstdlib::Deflate.new(level)
|
1593
|
+
* dst = z.deflate(string, Zstdlib::FINISH)
|
1580
1594
|
* z.close
|
1581
1595
|
* dst
|
1582
1596
|
* end
|
1583
1597
|
*
|
1584
|
-
* See also
|
1598
|
+
* See also Zstdlib.inflate
|
1585
1599
|
*
|
1586
1600
|
*/
|
1587
1601
|
static VALUE
|
@@ -1624,16 +1638,16 @@ do_deflate(struct zstream *z, VALUE src, int flush)
|
|
1624
1638
|
}
|
1625
1639
|
|
1626
1640
|
/*
|
1627
|
-
* Document-method:
|
1641
|
+
* Document-method: Zstdlib::Deflate#deflate
|
1628
1642
|
*
|
1629
1643
|
* call-seq:
|
1630
|
-
* z.deflate(string, flush =
|
1631
|
-
* z.deflate(string, flush =
|
1644
|
+
* z.deflate(string, flush = Zstdlib::NO_FLUSH) -> String
|
1645
|
+
* z.deflate(string, flush = Zstdlib::NO_FLUSH) { |chunk| ... } -> nil
|
1632
1646
|
*
|
1633
1647
|
* Inputs +string+ into the deflate stream and returns the output from the
|
1634
1648
|
* stream. On calling this method, both the input and the output buffers of
|
1635
1649
|
* the stream are flushed. If +string+ is nil, this method finishes the
|
1636
|
-
* stream, just like
|
1650
|
+
* stream, just like Zstdlib::ZStream#finish.
|
1637
1651
|
*
|
1638
1652
|
* If a block is given consecutive deflated chunks from the +string+ are
|
1639
1653
|
* yielded to the block and +nil+ is returned.
|
@@ -1641,10 +1655,10 @@ do_deflate(struct zstream *z, VALUE src, int flush)
|
|
1641
1655
|
* The +flush+ parameter specifies the flush mode. The following constants
|
1642
1656
|
* may be used:
|
1643
1657
|
*
|
1644
|
-
*
|
1645
|
-
*
|
1646
|
-
*
|
1647
|
-
*
|
1658
|
+
* Zstdlib::NO_FLUSH:: The default
|
1659
|
+
* Zstdlib::SYNC_FLUSH:: Flushes the output to a byte boundary
|
1660
|
+
* Zstdlib::FULL_FLUSH:: SYNC_FLUSH + resets the compression state
|
1661
|
+
* Zstdlib::FINISH:: Pending input is processed, pending output is flushed.
|
1648
1662
|
*
|
1649
1663
|
* See the constants for further description.
|
1650
1664
|
*
|
@@ -1663,12 +1677,12 @@ rb_deflate_deflate(int argc, VALUE *argv, VALUE obj)
|
|
1663
1677
|
}
|
1664
1678
|
|
1665
1679
|
/*
|
1666
|
-
* Document-method:
|
1680
|
+
* Document-method: Zstdlib::Deflate#<<
|
1667
1681
|
*
|
1668
1682
|
* call-seq: << string
|
1669
1683
|
*
|
1670
|
-
* Inputs +string+ into the deflate stream just like
|
1671
|
-
* returns the
|
1684
|
+
* Inputs +string+ into the deflate stream just like Zstdlib::Deflate#deflate, but
|
1685
|
+
* returns the Zstdlib::Deflate object itself. The output from the stream is
|
1672
1686
|
* preserved in output buffer.
|
1673
1687
|
*/
|
1674
1688
|
static VALUE
|
@@ -1680,18 +1694,18 @@ rb_deflate_addstr(VALUE obj, VALUE src)
|
|
1680
1694
|
}
|
1681
1695
|
|
1682
1696
|
/*
|
1683
|
-
* Document-method:
|
1697
|
+
* Document-method: Zstdlib::Deflate#flush
|
1684
1698
|
*
|
1685
1699
|
* call-seq:
|
1686
|
-
* flush(flush =
|
1687
|
-
* flush(flush =
|
1700
|
+
* flush(flush = Zstdlib::SYNC_FLUSH) -> String
|
1701
|
+
* flush(flush = Zstdlib::SYNC_FLUSH) { |chunk| ... } -> nil
|
1688
1702
|
*
|
1689
1703
|
* This method is equivalent to <tt>deflate('', flush)</tt>. This method is
|
1690
1704
|
* just provided to improve the readability of your Ruby program. If a block
|
1691
1705
|
* is given chunks of deflate output are yielded to the block until the buffer
|
1692
1706
|
* is flushed.
|
1693
1707
|
*
|
1694
|
-
* See
|
1708
|
+
* See Zstdlib::Deflate#deflate for detail on the +flush+ constants NO_FLUSH,
|
1695
1709
|
* SYNC_FLUSH, FULL_FLUSH and FINISH.
|
1696
1710
|
*/
|
1697
1711
|
static VALUE
|
@@ -1711,7 +1725,7 @@ rb_deflate_flush(int argc, VALUE *argv, VALUE obj)
|
|
1711
1725
|
}
|
1712
1726
|
|
1713
1727
|
/*
|
1714
|
-
* Document-method:
|
1728
|
+
* Document-method: Zstdlib::Deflate.params
|
1715
1729
|
*
|
1716
1730
|
* call-seq: params(level, strategy)
|
1717
1731
|
*
|
@@ -1719,7 +1733,7 @@ rb_deflate_flush(int argc, VALUE *argv, VALUE obj)
|
|
1719
1733
|
* different types of data that require different types of compression. Any
|
1720
1734
|
* unprocessed data is flushed before changing the params.
|
1721
1735
|
*
|
1722
|
-
* See
|
1736
|
+
* See Zstdlib::Deflate.new for a description of +level+ and +strategy+.
|
1723
1737
|
*
|
1724
1738
|
*/
|
1725
1739
|
static VALUE
|
@@ -1754,12 +1768,12 @@ rb_deflate_params(VALUE obj, VALUE v_level, VALUE v_strategy)
|
|
1754
1768
|
}
|
1755
1769
|
|
1756
1770
|
/*
|
1757
|
-
* Document-method:
|
1771
|
+
* Document-method: Zstdlib::Deflate.set_dictionary
|
1758
1772
|
*
|
1759
1773
|
* call-seq: set_dictionary(string)
|
1760
1774
|
*
|
1761
1775
|
* Sets the preset dictionary and returns +string+. This method is available
|
1762
|
-
* just only after
|
1776
|
+
* just only after Zstdlib::Deflate.new or Zstdlib::ZStream#reset method was called.
|
1763
1777
|
* See zlib.h for details.
|
1764
1778
|
*
|
1765
1779
|
* Can raise errors of Z_STREAM_ERROR if a parameter is invalid (such as
|
@@ -1789,10 +1803,10 @@ rb_deflate_set_dictionary(VALUE obj, VALUE dic)
|
|
1789
1803
|
/* ------------------------------------------------------------------------- */
|
1790
1804
|
|
1791
1805
|
/*
|
1792
|
-
* Document-class:
|
1806
|
+
* Document-class: Zstdlib::Inflate
|
1793
1807
|
*
|
1794
1808
|
* Zlib:Inflate is the class for decompressing compressed data. Unlike
|
1795
|
-
*
|
1809
|
+
* Zstdlib::Deflate, an instance of this class is not able to duplicate (clone,
|
1796
1810
|
* dup) itself.
|
1797
1811
|
*/
|
1798
1812
|
|
@@ -1805,10 +1819,10 @@ rb_inflate_s_allocate(VALUE klass)
|
|
1805
1819
|
}
|
1806
1820
|
|
1807
1821
|
/*
|
1808
|
-
* Document-method:
|
1822
|
+
* Document-method: Zstdlib::Inflate.new
|
1809
1823
|
*
|
1810
1824
|
* call-seq:
|
1811
|
-
*
|
1825
|
+
* Zstdlib::Inflate.new(window_bits = Zstdlib::MAX_WBITS)
|
1812
1826
|
*
|
1813
1827
|
* Creates a new inflate stream for decompression. +window_bits+ sets the
|
1814
1828
|
* size of the history buffer and can have the following values:
|
@@ -1825,7 +1839,7 @@ rb_inflate_s_allocate(VALUE klass)
|
|
1825
1839
|
* Greater than 15::
|
1826
1840
|
* Add 32 to window_bits to enable zlib and gzip decoding with automatic
|
1827
1841
|
* header detection, or add 16 to decode only the gzip format (a
|
1828
|
-
*
|
1842
|
+
* Zstdlib::DataError will be raised for a non-gzip stream).
|
1829
1843
|
*
|
1830
1844
|
* (-8..-15)::
|
1831
1845
|
* Enables raw deflate mode which will not generate a check value, and will
|
@@ -1837,7 +1851,7 @@ rb_inflate_s_allocate(VALUE klass)
|
|
1837
1851
|
* == Example
|
1838
1852
|
*
|
1839
1853
|
* open "compressed.file" do |compressed_io|
|
1840
|
-
* zi =
|
1854
|
+
* zi = Zstdlib::Inflate.new(Zstdlib::MAX_WBITS + 32)
|
1841
1855
|
*
|
1842
1856
|
* begin
|
1843
1857
|
* open "uncompressed.file", "w+" do |uncompressed_io|
|
@@ -1880,26 +1894,26 @@ inflate_run(VALUE args)
|
|
1880
1894
|
}
|
1881
1895
|
|
1882
1896
|
/*
|
1883
|
-
* Document-method:
|
1897
|
+
* Document-method: Zstdlib::inflate
|
1884
1898
|
*
|
1885
1899
|
* call-seq:
|
1886
|
-
*
|
1887
|
-
*
|
1900
|
+
* Zstdlib.inflate(string)
|
1901
|
+
* Zstdlib::Inflate.inflate(string)
|
1888
1902
|
*
|
1889
|
-
* Decompresses +string+. Raises a
|
1903
|
+
* Decompresses +string+. Raises a Zstdlib::NeedDict exception if a preset
|
1890
1904
|
* dictionary is needed for decompression.
|
1891
1905
|
*
|
1892
1906
|
* This method is almost equivalent to the following code:
|
1893
1907
|
*
|
1894
1908
|
* def inflate(string)
|
1895
|
-
* zstream =
|
1909
|
+
* zstream = Zstdlib::Inflate.new
|
1896
1910
|
* buf = zstream.inflate(string)
|
1897
1911
|
* zstream.finish
|
1898
1912
|
* zstream.close
|
1899
1913
|
* buf
|
1900
1914
|
* end
|
1901
1915
|
*
|
1902
|
-
* See also
|
1916
|
+
* See also Zstdlib.deflate
|
1903
1917
|
*
|
1904
1918
|
*/
|
1905
1919
|
static VALUE
|
@@ -1938,7 +1952,7 @@ do_inflate(struct zstream *z, VALUE src)
|
|
1938
1952
|
}
|
1939
1953
|
}
|
1940
1954
|
|
1941
|
-
/* Document-method:
|
1955
|
+
/* Document-method: Zstdlib::Inflate#add_dictionary
|
1942
1956
|
*
|
1943
1957
|
* call-seq: add_dictionary(string)
|
1944
1958
|
*
|
@@ -1959,7 +1973,7 @@ rb_inflate_add_dictionary(VALUE obj, VALUE dictionary)
|
|
1959
1973
|
}
|
1960
1974
|
|
1961
1975
|
/*
|
1962
|
-
* Document-method:
|
1976
|
+
* Document-method: Zstdlib::Inflate#inflate
|
1963
1977
|
*
|
1964
1978
|
* call-seq:
|
1965
1979
|
* inflate(deflate_string) -> String
|
@@ -1968,22 +1982,22 @@ rb_inflate_add_dictionary(VALUE obj, VALUE dictionary)
|
|
1968
1982
|
* Inputs +deflate_string+ into the inflate stream and returns the output from
|
1969
1983
|
* the stream. Calling this method, both the input and the output buffer of
|
1970
1984
|
* the stream are flushed. If string is +nil+, this method finishes the
|
1971
|
-
* stream, just like
|
1985
|
+
* stream, just like Zstdlib::ZStream#finish.
|
1972
1986
|
*
|
1973
1987
|
* If a block is given consecutive inflated chunks from the +deflate_string+
|
1974
1988
|
* are yielded to the block and +nil+ is returned.
|
1975
1989
|
*
|
1976
|
-
* Raises a
|
1977
|
-
* decompress. Set the dictionary by
|
1990
|
+
* Raises a Zstdlib::NeedDict exception if a preset dictionary is needed to
|
1991
|
+
* decompress. Set the dictionary by Zstdlib::Inflate#set_dictionary and then
|
1978
1992
|
* call this method again with an empty string to flush the stream:
|
1979
1993
|
*
|
1980
|
-
* inflater =
|
1994
|
+
* inflater = Zstdlib::Inflate.new
|
1981
1995
|
*
|
1982
1996
|
* begin
|
1983
1997
|
* out = inflater.inflate compressed
|
1984
|
-
* rescue
|
1998
|
+
* rescue Zstdlib::NeedDict
|
1985
1999
|
* # ensure the dictionary matches the stream's required dictionary
|
1986
|
-
* raise unless inflater.adler ==
|
2000
|
+
* raise unless inflater.adler == Zstdlib.adler32(dictionary)
|
1987
2001
|
*
|
1988
2002
|
* inflater.set_dictionary dictionary
|
1989
2003
|
* inflater.inflate ''
|
@@ -1993,7 +2007,7 @@ rb_inflate_add_dictionary(VALUE obj, VALUE dictionary)
|
|
1993
2007
|
*
|
1994
2008
|
* inflater.close
|
1995
2009
|
*
|
1996
|
-
* See also
|
2010
|
+
* See also Zstdlib::Inflate.new
|
1997
2011
|
*/
|
1998
2012
|
static VALUE
|
1999
2013
|
rb_inflate_inflate(VALUE obj, VALUE src)
|
@@ -2028,8 +2042,8 @@ rb_inflate_inflate(VALUE obj, VALUE src)
|
|
2028
2042
|
/*
|
2029
2043
|
* call-seq: << string
|
2030
2044
|
*
|
2031
|
-
* Inputs +string+ into the inflate stream just like
|
2032
|
-
* returns the
|
2045
|
+
* Inputs +string+ into the inflate stream just like Zstdlib::Inflate#inflate, but
|
2046
|
+
* returns the Zstdlib::Inflate object itself. The output from the stream is
|
2033
2047
|
* preserved in output buffer.
|
2034
2048
|
*/
|
2035
2049
|
static VALUE
|
@@ -2097,10 +2111,10 @@ rb_inflate_sync_point_p(VALUE obj)
|
|
2097
2111
|
}
|
2098
2112
|
|
2099
2113
|
/*
|
2100
|
-
* Document-method:
|
2114
|
+
* Document-method: Zstdlib::Inflate#set_dictionary
|
2101
2115
|
*
|
2102
2116
|
* Sets the preset dictionary and returns +string+. This method is available just
|
2103
|
-
* only after a
|
2117
|
+
* only after a Zstdlib::NeedDict exception was raised. See zlib.h for details.
|
2104
2118
|
*
|
2105
2119
|
*/
|
2106
2120
|
static VALUE
|
@@ -2227,7 +2241,7 @@ gzfile_free(void *p)
|
|
2227
2241
|
|
2228
2242
|
if (ZSTREAM_IS_READY(z)) {
|
2229
2243
|
if (z->func == &deflate_funcs) {
|
2230
|
-
finalizer_warn("
|
2244
|
+
finalizer_warn("Zstdlib::GzipWriter object must be closed explicitly.");
|
2231
2245
|
}
|
2232
2246
|
zstream_finalize(z);
|
2233
2247
|
}
|
@@ -2375,7 +2389,7 @@ gzfile_read_raw_ensure(struct gzfile *gz, long size)
|
|
2375
2389
|
{
|
2376
2390
|
VALUE str;
|
2377
2391
|
|
2378
|
-
if (gz->io == Qundef) { /*
|
2392
|
+
if (gz->io == Qundef) { /* Zstdlib.gunzip */
|
2379
2393
|
if (NIL_P(gz->z.input) || RSTRING_LEN(gz->z.input) < size)
|
2380
2394
|
rb_raise(cGzError, "unexpected end of string");
|
2381
2395
|
}
|
@@ -2447,7 +2461,7 @@ gzfile_raise(struct gzfile *gz, VALUE klass, const char *message)
|
|
2447
2461
|
}
|
2448
2462
|
|
2449
2463
|
/*
|
2450
|
-
* Document-method:
|
2464
|
+
* Document-method: Zstdlib::GzipFile::Error#inspect
|
2451
2465
|
*
|
2452
2466
|
* Constructs a String of the GzipFile Error
|
2453
2467
|
*/
|
@@ -2485,7 +2499,7 @@ gzfile_make_header(struct gzfile *gz)
|
|
2485
2499
|
if (gz->level == Z_BEST_SPEED) {
|
2486
2500
|
extraflags |= GZ_EXTRAFLAG_FAST;
|
2487
2501
|
}
|
2488
|
-
else if (gz->level ==
|
2502
|
+
else if (gz->level == ZSTD_maxCLevel()) {
|
2489
2503
|
extraflags |= GZ_EXTRAFLAG_SLOW;
|
2490
2504
|
}
|
2491
2505
|
|
@@ -2556,10 +2570,10 @@ gzfile_read_header(struct gzfile *gz)
|
|
2556
2570
|
gz->level = Z_BEST_SPEED;
|
2557
2571
|
}
|
2558
2572
|
else if (head[8] & GZ_EXTRAFLAG_SLOW) {
|
2559
|
-
gz->level =
|
2573
|
+
gz->level = ZSTD_maxCLevel();
|
2560
2574
|
}
|
2561
2575
|
else {
|
2562
|
-
gz->level =
|
2576
|
+
gz->level = ZSTD_CLEVEL_DEFAULT;
|
2563
2577
|
}
|
2564
2578
|
|
2565
2579
|
gz->mtime = gzfile_get32(&head[4]);
|
@@ -2948,40 +2962,40 @@ get_gzfile(VALUE obj)
|
|
2948
2962
|
/* ------------------------------------------------------------------------- */
|
2949
2963
|
|
2950
2964
|
/*
|
2951
|
-
* Document-class:
|
2965
|
+
* Document-class: Zstdlib::GzipFile
|
2952
2966
|
*
|
2953
|
-
*
|
2967
|
+
* Zstdlib::GzipFile is an abstract class for handling a gzip formatted
|
2954
2968
|
* compressed file. The operations are defined in the subclasses,
|
2955
|
-
*
|
2969
|
+
* Zstdlib::GzipReader for reading, and Zstdlib::GzipWriter for writing.
|
2956
2970
|
*
|
2957
2971
|
* GzipReader should be used by associating an IO, or IO-like, object.
|
2958
2972
|
*
|
2959
2973
|
* == Method Catalogue
|
2960
2974
|
*
|
2961
2975
|
* - ::wrap
|
2962
|
-
* - ::open (
|
2976
|
+
* - ::open (Zstdlib::GzipReader::open and Zstdlib::GzipWriter::open)
|
2963
2977
|
* - #close
|
2964
2978
|
* - #closed?
|
2965
2979
|
* - #comment
|
2966
|
-
* - comment= (
|
2980
|
+
* - comment= (Zstdlib::GzipWriter#comment=)
|
2967
2981
|
* - #crc
|
2968
|
-
* - eof? (
|
2982
|
+
* - eof? (Zstdlib::GzipReader#eof?)
|
2969
2983
|
* - #finish
|
2970
2984
|
* - #level
|
2971
|
-
* - lineno (
|
2972
|
-
* - lineno= (
|
2985
|
+
* - lineno (Zstdlib::GzipReader#lineno)
|
2986
|
+
* - lineno= (Zstdlib::GzipReader#lineno=)
|
2973
2987
|
* - #mtime
|
2974
|
-
* - mtime= (
|
2988
|
+
* - mtime= (Zstdlib::GzipWriter#mtime=)
|
2975
2989
|
* - #orig_name
|
2976
|
-
* - orig_name (
|
2990
|
+
* - orig_name (Zstdlib::GzipWriter#orig_name=)
|
2977
2991
|
* - #os_code
|
2978
2992
|
* - path (when the underlying IO supports #path)
|
2979
2993
|
* - #sync
|
2980
2994
|
* - #sync=
|
2981
2995
|
* - #to_io
|
2982
2996
|
*
|
2983
|
-
* (due to internal structure, documentation may appear under
|
2984
|
-
* or
|
2997
|
+
* (due to internal structure, documentation may appear under Zstdlib::GzipReader
|
2998
|
+
* or Zstdlib::GzipWriter)
|
2985
2999
|
*/
|
2986
3000
|
|
2987
3001
|
|
@@ -3040,11 +3054,11 @@ gzfile_wrap(int argc, VALUE *argv, VALUE klass, int close_io_on_error)
|
|
3040
3054
|
}
|
3041
3055
|
|
3042
3056
|
/*
|
3043
|
-
* Document-method:
|
3057
|
+
* Document-method: Zstdlib::GzipFile.wrap
|
3044
3058
|
*
|
3045
3059
|
* call-seq:
|
3046
|
-
*
|
3047
|
-
*
|
3060
|
+
* Zstdlib::GzipReader.wrap(io, ...) { |gz| ... }
|
3061
|
+
* Zstdlib::GzipWriter.wrap(io, ...) { |gz| ... }
|
3048
3062
|
*
|
3049
3063
|
* Creates a GzipReader or GzipWriter associated with +io+, passing in any
|
3050
3064
|
* necessary extra options, and executes the block with the newly created
|
@@ -3052,7 +3066,7 @@ gzfile_wrap(int argc, VALUE *argv, VALUE klass, int close_io_on_error)
|
|
3052
3066
|
*
|
3053
3067
|
* The GzipFile object will be closed automatically after executing the block.
|
3054
3068
|
* If you want to keep the associated IO object open, you may call
|
3055
|
-
*
|
3069
|
+
* Zstdlib::GzipFile#finish method in the block.
|
3056
3070
|
*/
|
3057
3071
|
static VALUE
|
3058
3072
|
rb_gzfile_s_wrap(int argc, VALUE *argv, VALUE klass)
|
@@ -3061,9 +3075,9 @@ rb_gzfile_s_wrap(int argc, VALUE *argv, VALUE klass)
|
|
3061
3075
|
}
|
3062
3076
|
|
3063
3077
|
/*
|
3064
|
-
* Document-method:
|
3078
|
+
* Document-method: Zstdlib::GzipFile.open
|
3065
3079
|
*
|
3066
|
-
* See
|
3080
|
+
* See Zstdlib::GzipReader#open and Zstdlib::GzipWriter#open.
|
3067
3081
|
*/
|
3068
3082
|
static VALUE
|
3069
3083
|
gzfile_s_open(int argc, VALUE *argv, VALUE klass, const char *mode)
|
@@ -3078,7 +3092,7 @@ gzfile_s_open(int argc, VALUE *argv, VALUE klass, const char *mode)
|
|
3078
3092
|
}
|
3079
3093
|
|
3080
3094
|
/*
|
3081
|
-
* Document-method:
|
3095
|
+
* Document-method: Zstdlib::GzipFile#to_io
|
3082
3096
|
*
|
3083
3097
|
* Same as IO.
|
3084
3098
|
*/
|
@@ -3089,7 +3103,7 @@ rb_gzfile_to_io(VALUE obj)
|
|
3089
3103
|
}
|
3090
3104
|
|
3091
3105
|
/*
|
3092
|
-
* Document-method:
|
3106
|
+
* Document-method: Zstdlib::GzipFile#crc
|
3093
3107
|
*
|
3094
3108
|
* Returns CRC value of the uncompressed data.
|
3095
3109
|
*/
|
@@ -3100,7 +3114,7 @@ rb_gzfile_crc(VALUE obj)
|
|
3100
3114
|
}
|
3101
3115
|
|
3102
3116
|
/*
|
3103
|
-
* Document-method:
|
3117
|
+
* Document-method: Zstdlib::GzipFile#mtime
|
3104
3118
|
*
|
3105
3119
|
* Returns last modification time recorded in the gzip file header.
|
3106
3120
|
*/
|
@@ -3111,7 +3125,7 @@ rb_gzfile_mtime(VALUE obj)
|
|
3111
3125
|
}
|
3112
3126
|
|
3113
3127
|
/*
|
3114
|
-
* Document-method:
|
3128
|
+
* Document-method: Zstdlib::GzipFile#level
|
3115
3129
|
*
|
3116
3130
|
* Returns compression level.
|
3117
3131
|
*/
|
@@ -3122,7 +3136,7 @@ rb_gzfile_level(VALUE obj)
|
|
3122
3136
|
}
|
3123
3137
|
|
3124
3138
|
/*
|
3125
|
-
* Document-method:
|
3139
|
+
* Document-method: Zstdlib::GzipFile#os_code
|
3126
3140
|
*
|
3127
3141
|
* Returns OS code number recorded in the gzip file header.
|
3128
3142
|
*/
|
@@ -3133,7 +3147,7 @@ rb_gzfile_os_code(VALUE obj)
|
|
3133
3147
|
}
|
3134
3148
|
|
3135
3149
|
/*
|
3136
|
-
* Document-method:
|
3150
|
+
* Document-method: Zstdlib::GzipFile#orig_name
|
3137
3151
|
*
|
3138
3152
|
* Returns original filename recorded in the gzip file header, or +nil+ if
|
3139
3153
|
* original filename is not present.
|
@@ -3150,7 +3164,7 @@ rb_gzfile_orig_name(VALUE obj)
|
|
3150
3164
|
}
|
3151
3165
|
|
3152
3166
|
/*
|
3153
|
-
* Document-method:
|
3167
|
+
* Document-method: Zstdlib::GzipFile#comment
|
3154
3168
|
*
|
3155
3169
|
* Returns comments recorded in the gzip file header, or nil if the comments
|
3156
3170
|
* is not present.
|
@@ -3167,7 +3181,7 @@ rb_gzfile_comment(VALUE obj)
|
|
3167
3181
|
}
|
3168
3182
|
|
3169
3183
|
/*
|
3170
|
-
* Document-method:
|
3184
|
+
* Document-method: Zstdlib::GzipFile#lineno
|
3171
3185
|
*
|
3172
3186
|
* The line number of the last row read from this file.
|
3173
3187
|
*/
|
@@ -3178,7 +3192,7 @@ rb_gzfile_lineno(VALUE obj)
|
|
3178
3192
|
}
|
3179
3193
|
|
3180
3194
|
/*
|
3181
|
-
* Document-method:
|
3195
|
+
* Document-method: Zstdlib::GzipReader#lineno=
|
3182
3196
|
*
|
3183
3197
|
* Specify line number of the last row read from this file.
|
3184
3198
|
*/
|
@@ -3191,7 +3205,7 @@ rb_gzfile_set_lineno(VALUE obj, VALUE lineno)
|
|
3191
3205
|
}
|
3192
3206
|
|
3193
3207
|
/*
|
3194
|
-
* Document-method:
|
3208
|
+
* Document-method: Zstdlib::GzipWriter#mtime=
|
3195
3209
|
*
|
3196
3210
|
* Specify the modification time (+mtime+) in the gzip header.
|
3197
3211
|
* Using an Integer.
|
@@ -3226,7 +3240,7 @@ rb_gzfile_set_mtime(VALUE obj, VALUE mtime)
|
|
3226
3240
|
}
|
3227
3241
|
|
3228
3242
|
/*
|
3229
|
-
* Document-method:
|
3243
|
+
* Document-method: Zstdlib::GzipFile#orig_name=
|
3230
3244
|
*
|
3231
3245
|
* Specify the original name (+str+) in the gzip header.
|
3232
3246
|
*/
|
@@ -3250,7 +3264,7 @@ rb_gzfile_set_orig_name(VALUE obj, VALUE str)
|
|
3250
3264
|
}
|
3251
3265
|
|
3252
3266
|
/*
|
3253
|
-
* Document-method:
|
3267
|
+
* Document-method: Zstdlib::GzipFile#comment=
|
3254
3268
|
*
|
3255
3269
|
* Specify the comment (+str+) in the gzip header.
|
3256
3270
|
*/
|
@@ -3274,7 +3288,7 @@ rb_gzfile_set_comment(VALUE obj, VALUE str)
|
|
3274
3288
|
}
|
3275
3289
|
|
3276
3290
|
/*
|
3277
|
-
* Document-method:
|
3291
|
+
* Document-method: Zstdlib::GzipFile#close
|
3278
3292
|
*
|
3279
3293
|
* Closes the GzipFile object. This method calls close method of the
|
3280
3294
|
* associated IO object. Returns the associated IO object.
|
@@ -3295,9 +3309,9 @@ rb_gzfile_close(VALUE obj)
|
|
3295
3309
|
}
|
3296
3310
|
|
3297
3311
|
/*
|
3298
|
-
* Document-method:
|
3312
|
+
* Document-method: Zstdlib::GzipFile#finish
|
3299
3313
|
*
|
3300
|
-
* Closes the GzipFile object. Unlike
|
3314
|
+
* Closes the GzipFile object. Unlike Zstdlib::GzipFile#close, this method never
|
3301
3315
|
* calls the close method of the associated IO object. Returns the associated IO
|
3302
3316
|
* object.
|
3303
3317
|
*/
|
@@ -3313,7 +3327,7 @@ rb_gzfile_finish(VALUE obj)
|
|
3313
3327
|
}
|
3314
3328
|
|
3315
3329
|
/*
|
3316
|
-
* Document-method:
|
3330
|
+
* Document-method: Zstdlib::GzipFile#closed?
|
3317
3331
|
*
|
3318
3332
|
* Same as IO#closed?
|
3319
3333
|
*
|
@@ -3327,7 +3341,7 @@ rb_gzfile_closed_p(VALUE obj)
|
|
3327
3341
|
}
|
3328
3342
|
|
3329
3343
|
/*
|
3330
|
-
* Document-method:
|
3344
|
+
* Document-method: Zstdlib::GzipFile#eof?
|
3331
3345
|
*
|
3332
3346
|
* Returns +true+ or +false+ whether the stream has reached the end.
|
3333
3347
|
*/
|
@@ -3339,7 +3353,7 @@ rb_gzfile_eof_p(VALUE obj)
|
|
3339
3353
|
}
|
3340
3354
|
|
3341
3355
|
/*
|
3342
|
-
* Document-method:
|
3356
|
+
* Document-method: Zstdlib::GzipFile#sync
|
3343
3357
|
*
|
3344
3358
|
* Same as IO#sync
|
3345
3359
|
*
|
@@ -3351,7 +3365,7 @@ rb_gzfile_sync(VALUE obj)
|
|
3351
3365
|
}
|
3352
3366
|
|
3353
3367
|
/*
|
3354
|
-
* Document-method:
|
3368
|
+
* Document-method: Zstdlib::GzipFile#sync=
|
3355
3369
|
*
|
3356
3370
|
* call-seq: sync = flag
|
3357
3371
|
*
|
@@ -3374,7 +3388,7 @@ rb_gzfile_set_sync(VALUE obj, VALUE mode)
|
|
3374
3388
|
}
|
3375
3389
|
|
3376
3390
|
/*
|
3377
|
-
* Document-method:
|
3391
|
+
* Document-method: Zstdlib::GzipFile#total_in
|
3378
3392
|
*
|
3379
3393
|
* Total number of input bytes read so far.
|
3380
3394
|
*/
|
@@ -3385,7 +3399,7 @@ rb_gzfile_total_in(VALUE obj)
|
|
3385
3399
|
}
|
3386
3400
|
|
3387
3401
|
/*
|
3388
|
-
* Document-method:
|
3402
|
+
* Document-method: Zstdlib::GzipFile#total_out
|
3389
3403
|
*
|
3390
3404
|
* Total number of output bytes output so far.
|
3391
3405
|
*/
|
@@ -3404,7 +3418,7 @@ rb_gzfile_total_out(VALUE obj)
|
|
3404
3418
|
}
|
3405
3419
|
|
3406
3420
|
/*
|
3407
|
-
* Document-method:
|
3421
|
+
* Document-method: Zstdlib::GzipFile#path
|
3408
3422
|
*
|
3409
3423
|
* call-seq: path
|
3410
3424
|
*
|
@@ -3436,19 +3450,19 @@ rb_gzfile_ecopts(struct gzfile *gz, VALUE opts)
|
|
3436
3450
|
/* ------------------------------------------------------------------------- */
|
3437
3451
|
|
3438
3452
|
/*
|
3439
|
-
* Document-class:
|
3453
|
+
* Document-class: Zstdlib::GzipWriter
|
3440
3454
|
*
|
3441
|
-
*
|
3455
|
+
* Zstdlib::GzipWriter is a class for writing gzipped files. GzipWriter should
|
3442
3456
|
* be used with an instance of IO, or IO-like, object.
|
3443
3457
|
*
|
3444
3458
|
* Following two example generate the same result.
|
3445
3459
|
*
|
3446
|
-
*
|
3460
|
+
* Zstdlib::GzipWriter.open('hoge.gz') do |gz|
|
3447
3461
|
* gz.write 'jugemu jugemu gokou no surikire...'
|
3448
3462
|
* end
|
3449
3463
|
*
|
3450
3464
|
* File.open('hoge.gz', 'w') do |f|
|
3451
|
-
* gz =
|
3465
|
+
* gz = Zstdlib::GzipWriter.new(f)
|
3452
3466
|
* gz.write 'jugemu jugemu gokou no surikire...'
|
3453
3467
|
* gz.close
|
3454
3468
|
* end
|
@@ -3456,14 +3470,14 @@ rb_gzfile_ecopts(struct gzfile *gz, VALUE opts)
|
|
3456
3470
|
* To make like gzip(1) does, run following:
|
3457
3471
|
*
|
3458
3472
|
* orig = 'hoge.txt'
|
3459
|
-
*
|
3473
|
+
* Zstdlib::GzipWriter.open('hoge.gz') do |gz|
|
3460
3474
|
* gz.mtime = File.mtime(orig)
|
3461
3475
|
* gz.orig_name = orig
|
3462
3476
|
* gz.write IO.binread(orig)
|
3463
3477
|
* end
|
3464
3478
|
*
|
3465
3479
|
* NOTE: Due to the limitation of Ruby's finalizer, you must explicitly close
|
3466
|
-
* GzipWriter objects by
|
3480
|
+
* GzipWriter objects by Zstdlib::GzipWriter#close etc. Otherwise, GzipWriter
|
3467
3481
|
* will be not able to write the gzip footer and will generate a broken gzip
|
3468
3482
|
* file.
|
3469
3483
|
*/
|
@@ -3475,11 +3489,11 @@ rb_gzwriter_s_allocate(VALUE klass)
|
|
3475
3489
|
}
|
3476
3490
|
|
3477
3491
|
/*
|
3478
|
-
* call-seq:
|
3492
|
+
* call-seq: Zstdlib::GzipWriter.open(filename, level=nil, strategy=nil) { |gz| ... }
|
3479
3493
|
*
|
3480
3494
|
* Opens a file specified by +filename+ for writing gzip compressed data, and
|
3481
3495
|
* returns a GzipWriter object associated with that file. Further details of
|
3482
|
-
* this method are found in
|
3496
|
+
* this method are found in Zstdlib::GzipWriter.new and Zstdlib::GzipFile.wrap.
|
3483
3497
|
*/
|
3484
3498
|
static VALUE
|
3485
3499
|
rb_gzwriter_s_open(int argc, VALUE *argv, VALUE klass)
|
@@ -3489,10 +3503,10 @@ rb_gzwriter_s_open(int argc, VALUE *argv, VALUE klass)
|
|
3489
3503
|
|
3490
3504
|
/*
|
3491
3505
|
* call-seq:
|
3492
|
-
*
|
3506
|
+
* Zstdlib::GzipWriter.new(io, level = nil, strategy = nil, options = {})
|
3493
3507
|
*
|
3494
3508
|
* Creates a GzipWriter object associated with +io+. +level+ and +strategy+
|
3495
|
-
* should be the same as the arguments of
|
3509
|
+
* should be the same as the arguments of Zstdlib::Deflate.new. The GzipWriter
|
3496
3510
|
* object writes gzipped data to +io+. +io+ must respond to the
|
3497
3511
|
* +write+ method that behaves the same as IO#write.
|
3498
3512
|
*
|
@@ -3538,8 +3552,8 @@ rb_gzwriter_initialize(int argc, VALUE *argv, VALUE obj)
|
|
3538
3552
|
* call-seq: flush(flush=nil)
|
3539
3553
|
*
|
3540
3554
|
* Flushes all the internal buffers of the GzipWriter object. The meaning of
|
3541
|
-
* +flush+ is same as in
|
3542
|
-
* +flush+ is omitted. It is no use giving flush <tt>
|
3555
|
+
* +flush+ is same as in Zstdlib::Deflate#deflate. <tt>Zstdlib::SYNC_FLUSH</tt> is used if
|
3556
|
+
* +flush+ is omitted. It is no use giving flush <tt>Zstdlib::NO_FLUSH</tt>.
|
3543
3557
|
*/
|
3544
3558
|
static VALUE
|
3545
3559
|
rb_gzwriter_flush(int argc, VALUE *argv, VALUE obj)
|
@@ -3620,25 +3634,25 @@ rb_gzwriter_putc(VALUE obj, VALUE ch)
|
|
3620
3634
|
/* ------------------------------------------------------------------------- */
|
3621
3635
|
|
3622
3636
|
/*
|
3623
|
-
* Document-class:
|
3637
|
+
* Document-class: Zstdlib::GzipReader
|
3624
3638
|
*
|
3625
|
-
*
|
3639
|
+
* Zstdlib::GzipReader is the class for reading a gzipped file. GzipReader should
|
3626
3640
|
* be used as an IO, or -IO-like, object.
|
3627
3641
|
*
|
3628
|
-
*
|
3642
|
+
* Zstdlib::GzipReader.open('hoge.gz') {|gz|
|
3629
3643
|
* print gz.read
|
3630
3644
|
* }
|
3631
3645
|
*
|
3632
3646
|
* File.open('hoge.gz') do |f|
|
3633
|
-
* gz =
|
3647
|
+
* gz = Zstdlib::GzipReader.new(f)
|
3634
3648
|
* print gz.read
|
3635
3649
|
* gz.close
|
3636
3650
|
* end
|
3637
3651
|
*
|
3638
3652
|
* == Method Catalogue
|
3639
3653
|
*
|
3640
|
-
* The following methods in
|
3641
|
-
* in IO, but they raise
|
3654
|
+
* The following methods in Zstdlib::GzipReader are just like their counterparts
|
3655
|
+
* in IO, but they raise Zstdlib::Error or Zstdlib::GzipFile::Error exception if an
|
3642
3656
|
* error was found in the gzip file.
|
3643
3657
|
* - #each
|
3644
3658
|
* - #each_line
|
@@ -3656,15 +3670,15 @@ rb_gzwriter_putc(VALUE obj, VALUE ch)
|
|
3656
3670
|
* Be careful of the footer of the gzip file. A gzip file has the checksum of
|
3657
3671
|
* pre-compressed data in its footer. GzipReader checks all uncompressed data
|
3658
3672
|
* against that checksum at the following cases, and if it fails, raises
|
3659
|
-
* <tt>
|
3660
|
-
* <tt>
|
3673
|
+
* <tt>Zstdlib::GzipFile::NoFooter</tt>, <tt>Zstdlib::GzipFile::CRCError</tt>, or
|
3674
|
+
* <tt>Zstdlib::GzipFile::LengthError</tt> exception.
|
3661
3675
|
*
|
3662
3676
|
* - When an reading request is received beyond the end of file (the end of
|
3663
|
-
* compressed data). That is, when
|
3664
|
-
*
|
3665
|
-
* - When
|
3677
|
+
* compressed data). That is, when Zstdlib::GzipReader#read,
|
3678
|
+
* Zstdlib::GzipReader#gets, or some other methods for reading returns nil.
|
3679
|
+
* - When Zstdlib::GzipFile#close method is called after the object reaches the
|
3666
3680
|
* end of file.
|
3667
|
-
* - When
|
3681
|
+
* - When Zstdlib::GzipReader#unused method is called after the object reaches
|
3668
3682
|
* the end of file.
|
3669
3683
|
*
|
3670
3684
|
* The rest of the methods are adequately described in their own
|
@@ -3678,13 +3692,13 @@ rb_gzreader_s_allocate(VALUE klass)
|
|
3678
3692
|
}
|
3679
3693
|
|
3680
3694
|
/*
|
3681
|
-
* Document-method:
|
3695
|
+
* Document-method: Zstdlib::GzipReader.open
|
3682
3696
|
*
|
3683
|
-
* call-seq:
|
3697
|
+
* call-seq: Zstdlib::GzipReader.open(filename) {|gz| ... }
|
3684
3698
|
*
|
3685
3699
|
* Opens a file specified by +filename+ as a gzipped file, and returns a
|
3686
3700
|
* GzipReader object associated with that file. Further details of this method
|
3687
|
-
* are in
|
3701
|
+
* are in Zstdlib::GzipReader.new and ZLib::GzipFile.wrap.
|
3688
3702
|
*/
|
3689
3703
|
static VALUE
|
3690
3704
|
rb_gzreader_s_open(int argc, VALUE *argv, VALUE klass)
|
@@ -3693,10 +3707,10 @@ rb_gzreader_s_open(int argc, VALUE *argv, VALUE klass)
|
|
3693
3707
|
}
|
3694
3708
|
|
3695
3709
|
/*
|
3696
|
-
* Document-method:
|
3710
|
+
* Document-method: Zstdlib::GzipReader.new
|
3697
3711
|
*
|
3698
3712
|
* call-seq:
|
3699
|
-
*
|
3713
|
+
* Zstdlib::GzipReader.new(io, options = {})
|
3700
3714
|
*
|
3701
3715
|
* Creates a GzipReader object associated with +io+. The GzipReader object reads
|
3702
3716
|
* gzipped data from +io+, and parses/decompresses it. The +io+ must
|
@@ -3706,7 +3720,7 @@ rb_gzreader_s_open(int argc, VALUE *argv, VALUE klass)
|
|
3706
3720
|
* +:external_encoding+, +:internal_encoding+ and +:encoding+ may be set as in
|
3707
3721
|
* IO::new.
|
3708
3722
|
*
|
3709
|
-
* If the gzip file header is incorrect, raises an
|
3723
|
+
* If the gzip file header is incorrect, raises an Zstdlib::GzipFile::Error
|
3710
3724
|
* exception.
|
3711
3725
|
*/
|
3712
3726
|
static VALUE
|
@@ -3738,7 +3752,7 @@ rb_gzreader_initialize(int argc, VALUE *argv, VALUE obj)
|
|
3738
3752
|
}
|
3739
3753
|
|
3740
3754
|
/*
|
3741
|
-
* Document-method:
|
3755
|
+
* Document-method: Zstdlib::GzipReader#rewind
|
3742
3756
|
*
|
3743
3757
|
* Resets the position of the file pointer to the point created the GzipReader
|
3744
3758
|
* object. The associated IO object needs to respond to the +seek+ method.
|
@@ -3752,7 +3766,7 @@ rb_gzreader_rewind(VALUE obj)
|
|
3752
3766
|
}
|
3753
3767
|
|
3754
3768
|
/*
|
3755
|
-
* Document-method:
|
3769
|
+
* Document-method: Zstdlib::GzipReader#unused
|
3756
3770
|
*
|
3757
3771
|
* Returns the rest of the data which had read for parsing gzip format, or
|
3758
3772
|
* +nil+ if the whole gzip file is not parsed yet.
|
@@ -3766,9 +3780,9 @@ rb_gzreader_unused(VALUE obj)
|
|
3766
3780
|
}
|
3767
3781
|
|
3768
3782
|
/*
|
3769
|
-
* Document-method:
|
3783
|
+
* Document-method: Zstdlib::GzipReader#read
|
3770
3784
|
*
|
3771
|
-
* See
|
3785
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3772
3786
|
*/
|
3773
3787
|
static VALUE
|
3774
3788
|
rb_gzreader_read(int argc, VALUE *argv, VALUE obj)
|
@@ -3790,7 +3804,7 @@ rb_gzreader_read(int argc, VALUE *argv, VALUE obj)
|
|
3790
3804
|
}
|
3791
3805
|
|
3792
3806
|
/*
|
3793
|
-
* Document-method:
|
3807
|
+
* Document-method: Zstdlib::GzipReader#readpartial
|
3794
3808
|
*
|
3795
3809
|
* call-seq:
|
3796
3810
|
* gzipreader.readpartial(maxlen [, outbuf]) => string, outbuf
|
@@ -3820,9 +3834,9 @@ rb_gzreader_readpartial(int argc, VALUE *argv, VALUE obj)
|
|
3820
3834
|
}
|
3821
3835
|
|
3822
3836
|
/*
|
3823
|
-
* Document-method:
|
3837
|
+
* Document-method: Zstdlib::GzipReader#getc
|
3824
3838
|
*
|
3825
|
-
* See
|
3839
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3826
3840
|
*/
|
3827
3841
|
static VALUE
|
3828
3842
|
rb_gzreader_getc(VALUE obj)
|
@@ -3833,9 +3847,9 @@ rb_gzreader_getc(VALUE obj)
|
|
3833
3847
|
}
|
3834
3848
|
|
3835
3849
|
/*
|
3836
|
-
* Document-method:
|
3850
|
+
* Document-method: Zstdlib::GzipReader#readchar
|
3837
3851
|
*
|
3838
|
-
* See
|
3852
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3839
3853
|
*/
|
3840
3854
|
static VALUE
|
3841
3855
|
rb_gzreader_readchar(VALUE obj)
|
@@ -3849,9 +3863,9 @@ rb_gzreader_readchar(VALUE obj)
|
|
3849
3863
|
}
|
3850
3864
|
|
3851
3865
|
/*
|
3852
|
-
* Document-method:
|
3866
|
+
* Document-method: Zstdlib::GzipReader#getbyte
|
3853
3867
|
*
|
3854
|
-
* See
|
3868
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3855
3869
|
*/
|
3856
3870
|
static VALUE
|
3857
3871
|
rb_gzreader_getbyte(VALUE obj)
|
@@ -3867,9 +3881,9 @@ rb_gzreader_getbyte(VALUE obj)
|
|
3867
3881
|
}
|
3868
3882
|
|
3869
3883
|
/*
|
3870
|
-
* Document-method:
|
3884
|
+
* Document-method: Zstdlib::GzipReader#readbyte
|
3871
3885
|
*
|
3872
|
-
* See
|
3886
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3873
3887
|
*/
|
3874
3888
|
static VALUE
|
3875
3889
|
rb_gzreader_readbyte(VALUE obj)
|
@@ -3883,9 +3897,9 @@ rb_gzreader_readbyte(VALUE obj)
|
|
3883
3897
|
}
|
3884
3898
|
|
3885
3899
|
/*
|
3886
|
-
* Document-method:
|
3900
|
+
* Document-method: Zstdlib::GzipReader#each_char
|
3887
3901
|
*
|
3888
|
-
* See
|
3902
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3889
3903
|
*/
|
3890
3904
|
static VALUE
|
3891
3905
|
rb_gzreader_each_char(VALUE obj)
|
@@ -3901,9 +3915,9 @@ rb_gzreader_each_char(VALUE obj)
|
|
3901
3915
|
}
|
3902
3916
|
|
3903
3917
|
/*
|
3904
|
-
* Document-method:
|
3918
|
+
* Document-method: Zstdlib::GzipReader#each_byte
|
3905
3919
|
*
|
3906
|
-
* See
|
3920
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3907
3921
|
*/
|
3908
3922
|
static VALUE
|
3909
3923
|
rb_gzreader_each_byte(VALUE obj)
|
@@ -3919,23 +3933,23 @@ rb_gzreader_each_byte(VALUE obj)
|
|
3919
3933
|
}
|
3920
3934
|
|
3921
3935
|
/*
|
3922
|
-
* Document-method:
|
3936
|
+
* Document-method: Zstdlib::GzipReader#bytes
|
3923
3937
|
*
|
3924
3938
|
* This is a deprecated alias for <code>each_byte</code>.
|
3925
3939
|
*/
|
3926
3940
|
static VALUE
|
3927
3941
|
rb_gzreader_bytes(VALUE obj)
|
3928
3942
|
{
|
3929
|
-
rb_warn("
|
3943
|
+
rb_warn("Zstdlib::GzipReader#bytes is deprecated; use #each_byte instead");
|
3930
3944
|
if (!rb_block_given_p())
|
3931
3945
|
return rb_enumeratorize(obj, ID2SYM(rb_intern("each_byte")), 0, 0);
|
3932
3946
|
return rb_gzreader_each_byte(obj);
|
3933
3947
|
}
|
3934
3948
|
|
3935
3949
|
/*
|
3936
|
-
* Document-method:
|
3950
|
+
* Document-method: Zstdlib::GzipReader#ungetc
|
3937
3951
|
*
|
3938
|
-
* See
|
3952
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3939
3953
|
*/
|
3940
3954
|
static VALUE
|
3941
3955
|
rb_gzreader_ungetc(VALUE obj, VALUE s)
|
@@ -3955,9 +3969,9 @@ rb_gzreader_ungetc(VALUE obj, VALUE s)
|
|
3955
3969
|
}
|
3956
3970
|
|
3957
3971
|
/*
|
3958
|
-
* Document-method:
|
3972
|
+
* Document-method: Zstdlib::GzipReader#ungetbyte
|
3959
3973
|
*
|
3960
|
-
* See
|
3974
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3961
3975
|
*/
|
3962
3976
|
static VALUE
|
3963
3977
|
rb_gzreader_ungetbyte(VALUE obj, VALUE ch)
|
@@ -4155,9 +4169,9 @@ gzreader_gets(int argc, VALUE *argv, VALUE obj)
|
|
4155
4169
|
}
|
4156
4170
|
|
4157
4171
|
/*
|
4158
|
-
* Document-method:
|
4172
|
+
* Document-method: Zstdlib::GzipReader#gets
|
4159
4173
|
*
|
4160
|
-
* See
|
4174
|
+
* See Zstdlib::GzipReader documentation for a description.
|
4161
4175
|
*/
|
4162
4176
|
static VALUE
|
4163
4177
|
rb_gzreader_gets(int argc, VALUE *argv, VALUE obj)
|
@@ -4171,9 +4185,9 @@ rb_gzreader_gets(int argc, VALUE *argv, VALUE obj)
|
|
4171
4185
|
}
|
4172
4186
|
|
4173
4187
|
/*
|
4174
|
-
* Document-method:
|
4188
|
+
* Document-method: Zstdlib::GzipReader#readline
|
4175
4189
|
*
|
4176
|
-
* See
|
4190
|
+
* See Zstdlib::GzipReader documentation for a description.
|
4177
4191
|
*/
|
4178
4192
|
static VALUE
|
4179
4193
|
rb_gzreader_readline(int argc, VALUE *argv, VALUE obj)
|
@@ -4187,9 +4201,9 @@ rb_gzreader_readline(int argc, VALUE *argv, VALUE obj)
|
|
4187
4201
|
}
|
4188
4202
|
|
4189
4203
|
/*
|
4190
|
-
* Document-method:
|
4204
|
+
* Document-method: Zstdlib::GzipReader#each
|
4191
4205
|
*
|
4192
|
-
* See
|
4206
|
+
* See Zstdlib::GzipReader documentation for a description.
|
4193
4207
|
*/
|
4194
4208
|
static VALUE
|
4195
4209
|
rb_gzreader_each(int argc, VALUE *argv, VALUE obj)
|
@@ -4205,23 +4219,23 @@ rb_gzreader_each(int argc, VALUE *argv, VALUE obj)
|
|
4205
4219
|
}
|
4206
4220
|
|
4207
4221
|
/*
|
4208
|
-
* Document-method:
|
4222
|
+
* Document-method: Zstdlib::GzipReader#lines
|
4209
4223
|
*
|
4210
4224
|
* This is a deprecated alias for <code>each_line</code>.
|
4211
4225
|
*/
|
4212
4226
|
static VALUE
|
4213
4227
|
rb_gzreader_lines(int argc, VALUE *argv, VALUE obj)
|
4214
4228
|
{
|
4215
|
-
rb_warn("
|
4229
|
+
rb_warn("Zstdlib::GzipReader#lines is deprecated; use #each_line instead");
|
4216
4230
|
if (!rb_block_given_p())
|
4217
4231
|
return rb_enumeratorize(obj, ID2SYM(rb_intern("each_line")), argc, argv);
|
4218
4232
|
return rb_gzreader_each(argc, argv, obj);
|
4219
4233
|
}
|
4220
4234
|
|
4221
4235
|
/*
|
4222
|
-
* Document-method:
|
4236
|
+
* Document-method: Zstdlib::GzipReader#readlines
|
4223
4237
|
*
|
4224
|
-
* See
|
4238
|
+
* See Zstdlib::GzipReader documentation for a description.
|
4225
4239
|
*/
|
4226
4240
|
static VALUE
|
4227
4241
|
rb_gzreader_readlines(int argc, VALUE *argv, VALUE obj)
|
@@ -4235,9 +4249,9 @@ rb_gzreader_readlines(int argc, VALUE *argv, VALUE obj)
|
|
4235
4249
|
}
|
4236
4250
|
|
4237
4251
|
/*
|
4238
|
-
* Document-method:
|
4252
|
+
* Document-method: Zstdlib::GzipReader#external_encoding
|
4239
4253
|
*
|
4240
|
-
* See
|
4254
|
+
* See Zstdlib::GzipReader documentation for a description.
|
4241
4255
|
*/
|
4242
4256
|
static VALUE
|
4243
4257
|
rb_gzreader_external_encoding(VALUE self)
|
@@ -4269,24 +4283,24 @@ static VALUE zlib_gzip_run(VALUE arg);
|
|
4269
4283
|
|
4270
4284
|
/*
|
4271
4285
|
* call-seq:
|
4272
|
-
*
|
4286
|
+
* Zstdlib.gzip(src, level: nil, strategy: nil) -> String
|
4273
4287
|
*
|
4274
4288
|
* Gzip the given +string+. Valid values of level are
|
4275
|
-
*
|
4276
|
-
*
|
4289
|
+
* Zstdlib::NO_COMPRESSION, Zstdlib::BEST_SPEED, Zstdlib::BEST_COMPRESSION,
|
4290
|
+
* Zstdlib::DEFAULT_COMPRESSION (default), or an integer from 0 to 9.
|
4277
4291
|
*
|
4278
4292
|
* This method is almost equivalent to the following code:
|
4279
4293
|
*
|
4280
4294
|
* def gzip(string, level: nil, strategy: nil)
|
4281
4295
|
* sio = StringIO.new
|
4282
4296
|
* sio.binmode
|
4283
|
-
* gz =
|
4297
|
+
* gz = Zstdlib::GzipWriter.new(sio, level, strategy)
|
4284
4298
|
* gz.write(string)
|
4285
4299
|
* gz.close
|
4286
4300
|
* sio.string
|
4287
4301
|
* end
|
4288
4302
|
*
|
4289
|
-
* See also
|
4303
|
+
* See also Zstdlib.gunzip
|
4290
4304
|
*
|
4291
4305
|
*/
|
4292
4306
|
static VALUE
|
@@ -4356,7 +4370,7 @@ static VALUE zlib_gunzip_run(VALUE arg);
|
|
4356
4370
|
|
4357
4371
|
/*
|
4358
4372
|
* call-seq:
|
4359
|
-
*
|
4373
|
+
* Zstdlib.gunzip(src) -> String
|
4360
4374
|
*
|
4361
4375
|
* Decode the given gzipped +string+.
|
4362
4376
|
*
|
@@ -4364,13 +4378,13 @@ static VALUE zlib_gunzip_run(VALUE arg);
|
|
4364
4378
|
*
|
4365
4379
|
* def gunzip(string)
|
4366
4380
|
* sio = StringIO.new(string)
|
4367
|
-
* gz =
|
4381
|
+
* gz = Zstdlib::GzipReader.new(sio, encoding: Encoding::ASCII_8BIT)
|
4368
4382
|
* gz.read
|
4369
4383
|
* ensure
|
4370
4384
|
* gz&.close
|
4371
4385
|
* end
|
4372
4386
|
*
|
4373
|
-
* See also
|
4387
|
+
* See also Zstdlib.gzip
|
4374
4388
|
*/
|
4375
4389
|
static VALUE
|
4376
4390
|
zlib_gunzip(VALUE klass, VALUE src)
|
@@ -4414,14 +4428,14 @@ zlib_gunzip_run(VALUE arg)
|
|
4414
4428
|
#endif /* GZIP_SUPPORT */
|
4415
4429
|
|
4416
4430
|
void
|
4417
|
-
|
4431
|
+
Init_zstdlib(void)
|
4418
4432
|
{
|
4419
4433
|
VALUE mZlib, cZStream, cDeflate, cInflate;
|
4420
4434
|
#if GZIP_SUPPORT
|
4421
4435
|
VALUE cGzipFile, cGzipWriter, cGzipReader;
|
4422
4436
|
#endif
|
4423
4437
|
|
4424
|
-
mZlib = rb_define_module("
|
4438
|
+
mZlib = rb_define_module("Zstdlib");
|
4425
4439
|
|
4426
4440
|
id_dictionaries = rb_intern("@dictionaries");
|
4427
4441
|
|
@@ -4445,6 +4459,8 @@ Init_zlib(void)
|
|
4445
4459
|
rb_define_const(mZlib, "VERSION", rb_str_new2(RUBY_ZLIB_VERSION));
|
4446
4460
|
/* The string which represents the version of zlib.h */
|
4447
4461
|
rb_define_const(mZlib, "ZLIB_VERSION", rb_str_new2(ZLIB_VERSION));
|
4462
|
+
rb_define_const(mZlib, "ZSTD_VERSION", rb_str_new2(ZSTD_versionString()));
|
4463
|
+
rb_define_module_function(mZlib, "zstd_version", rb_zstd_version, 0);
|
4448
4464
|
|
4449
4465
|
cZStream = rb_define_class_under(mZlib, "ZStream", rb_cObject);
|
4450
4466
|
rb_undef_alloc_func(cZStream);
|
@@ -4468,7 +4484,7 @@ Init_zlib(void)
|
|
4468
4484
|
|
4469
4485
|
/* Represents binary data as guessed by deflate.
|
4470
4486
|
*
|
4471
|
-
* See
|
4487
|
+
* See Zstdlib::Deflate#data_type. */
|
4472
4488
|
rb_define_const(mZlib, "BINARY", INT2FIX(Z_BINARY));
|
4473
4489
|
|
4474
4490
|
/* Represents text data as guessed by deflate.
|
@@ -4476,19 +4492,19 @@ Init_zlib(void)
|
|
4476
4492
|
* NOTE: The underlying constant Z_ASCII was deprecated in favor of Z_TEXT
|
4477
4493
|
* in zlib 1.2.2. New applications should not use this constant.
|
4478
4494
|
*
|
4479
|
-
* See
|
4495
|
+
* See Zstdlib::Deflate#data_type. */
|
4480
4496
|
rb_define_const(mZlib, "ASCII", INT2FIX(Z_ASCII));
|
4481
4497
|
|
4482
4498
|
#ifdef Z_TEXT
|
4483
4499
|
/* Represents text data as guessed by deflate.
|
4484
4500
|
*
|
4485
|
-
* See
|
4501
|
+
* See Zstdlib::Deflate#data_type. */
|
4486
4502
|
rb_define_const(mZlib, "TEXT", INT2FIX(Z_TEXT));
|
4487
4503
|
#endif
|
4488
4504
|
|
4489
4505
|
/* Represents an unknown data type as guessed by deflate.
|
4490
4506
|
*
|
4491
|
-
* See
|
4507
|
+
* See Zstdlib::Deflate#data_type. */
|
4492
4508
|
rb_define_const(mZlib, "UNKNOWN", INT2FIX(Z_UNKNOWN));
|
4493
4509
|
|
4494
4510
|
cDeflate = rb_define_class_under(mZlib, "Deflate", cZStream);
|
@@ -4522,12 +4538,12 @@ Init_zlib(void)
|
|
4522
4538
|
/* Fastest compression level, but with the lowest space savings. */
|
4523
4539
|
rb_define_const(mZlib, "BEST_SPEED", INT2FIX(Z_BEST_SPEED));
|
4524
4540
|
/* Slowest compression level, but with the best space savings. */
|
4525
|
-
rb_define_const(mZlib, "BEST_COMPRESSION", INT2FIX(
|
4541
|
+
rb_define_const(mZlib, "BEST_COMPRESSION", INT2FIX(ZSTD_maxCLevel()));
|
4526
4542
|
/* Default compression level which is a good trade-off between space and
|
4527
4543
|
* time
|
4528
4544
|
*/
|
4529
4545
|
rb_define_const(mZlib, "DEFAULT_COMPRESSION",
|
4530
|
-
INT2FIX(
|
4546
|
+
INT2FIX(ZSTD_CLEVEL_DEFAULT));
|
4531
4547
|
|
4532
4548
|
/* Deflate strategy for data produced by a filter (or predictor). The
|
4533
4549
|
* effect of FILTERED is to force more Huffman codes and less string
|
@@ -4558,7 +4574,7 @@ Init_zlib(void)
|
|
4558
4574
|
rb_define_const(mZlib, "DEFAULT_STRATEGY", INT2FIX(Z_DEFAULT_STRATEGY));
|
4559
4575
|
|
4560
4576
|
/* The maximum size of the zlib history buffer. Note that zlib allows
|
4561
|
-
* larger values to enable different inflate modes. See
|
4577
|
+
* larger values to enable different inflate modes. See Zstdlib::Inflate.new
|
4562
4578
|
* for details.
|
4563
4579
|
*/
|
4564
4580
|
rb_define_const(mZlib, "MAX_WBITS", INT2FIX(MAX_WBITS));
|
@@ -4725,28 +4741,28 @@ Init_zlib(void)
|
|
4725
4741
|
/* Document error classes. */
|
4726
4742
|
|
4727
4743
|
/*
|
4728
|
-
* Document-class:
|
4744
|
+
* Document-class: Zstdlib::Error
|
4729
4745
|
*
|
4730
4746
|
* The superclass for all exceptions raised by Ruby/zlib.
|
4731
4747
|
*
|
4732
|
-
* The following exceptions are defined as subclasses of
|
4748
|
+
* The following exceptions are defined as subclasses of Zstdlib::Error. These
|
4733
4749
|
* exceptions are raised when zlib library functions return with an error
|
4734
4750
|
* status.
|
4735
4751
|
*
|
4736
|
-
* -
|
4737
|
-
* -
|
4738
|
-
* -
|
4739
|
-
* -
|
4740
|
-
* -
|
4741
|
-
* -
|
4742
|
-
* -
|
4752
|
+
* - Zstdlib::StreamEnd
|
4753
|
+
* - Zstdlib::NeedDict
|
4754
|
+
* - Zstdlib::DataError
|
4755
|
+
* - Zstdlib::StreamError
|
4756
|
+
* - Zstdlib::MemError
|
4757
|
+
* - Zstdlib::BufError
|
4758
|
+
* - Zstdlib::VersionError
|
4743
4759
|
*
|
4744
4760
|
*/
|
4745
4761
|
|
4746
4762
|
/*
|
4747
|
-
* Document-class:
|
4763
|
+
* Document-class: Zstdlib::StreamEnd
|
4748
4764
|
*
|
4749
|
-
* Subclass of
|
4765
|
+
* Subclass of Zstdlib::Error
|
4750
4766
|
*
|
4751
4767
|
* When zlib returns a Z_STREAM_END
|
4752
4768
|
* is return if the end of the compressed data has been reached
|
@@ -4755,20 +4771,20 @@ Init_zlib(void)
|
|
4755
4771
|
*/
|
4756
4772
|
|
4757
4773
|
/*
|
4758
|
-
* Document-class:
|
4774
|
+
* Document-class: Zstdlib::NeedDict
|
4759
4775
|
*
|
4760
|
-
* Subclass of
|
4776
|
+
* Subclass of Zstdlib::Error
|
4761
4777
|
*
|
4762
4778
|
* When zlib returns a Z_NEED_DICT
|
4763
4779
|
* if a preset dictionary is needed at this point.
|
4764
4780
|
*
|
4765
|
-
* Used by
|
4781
|
+
* Used by Zstdlib::Inflate.inflate and <tt>Zstdlib.inflate</tt>
|
4766
4782
|
*/
|
4767
4783
|
|
4768
4784
|
/*
|
4769
|
-
* Document-class:
|
4785
|
+
* Document-class: Zstdlib::VersionError
|
4770
4786
|
*
|
4771
|
-
* Subclass of
|
4787
|
+
* Subclass of Zstdlib::Error
|
4772
4788
|
*
|
4773
4789
|
* When zlib returns a Z_VERSION_ERROR,
|
4774
4790
|
* usually if the zlib library version is incompatible with the
|
@@ -4777,9 +4793,9 @@ Init_zlib(void)
|
|
4777
4793
|
*/
|
4778
4794
|
|
4779
4795
|
/*
|
4780
|
-
* Document-class:
|
4796
|
+
* Document-class: Zstdlib::MemError
|
4781
4797
|
*
|
4782
|
-
* Subclass of
|
4798
|
+
* Subclass of Zstdlib::Error
|
4783
4799
|
*
|
4784
4800
|
* When zlib returns a Z_MEM_ERROR,
|
4785
4801
|
* usually if there was not enough memory.
|
@@ -4787,9 +4803,9 @@ Init_zlib(void)
|
|
4787
4803
|
*/
|
4788
4804
|
|
4789
4805
|
/*
|
4790
|
-
* Document-class:
|
4806
|
+
* Document-class: Zstdlib::StreamError
|
4791
4807
|
*
|
4792
|
-
* Subclass of
|
4808
|
+
* Subclass of Zstdlib::Error
|
4793
4809
|
*
|
4794
4810
|
* When zlib returns a Z_STREAM_ERROR,
|
4795
4811
|
* usually if the stream state was inconsistent.
|
@@ -4797,44 +4813,44 @@ Init_zlib(void)
|
|
4797
4813
|
*/
|
4798
4814
|
|
4799
4815
|
/*
|
4800
|
-
* Document-class:
|
4816
|
+
* Document-class: Zstdlib::BufError
|
4801
4817
|
*
|
4802
|
-
* Subclass of
|
4818
|
+
* Subclass of Zstdlib::Error when zlib returns a Z_BUF_ERROR.
|
4803
4819
|
*
|
4804
4820
|
* Usually if no progress is possible.
|
4805
4821
|
*
|
4806
4822
|
*/
|
4807
4823
|
|
4808
4824
|
/*
|
4809
|
-
* Document-class:
|
4825
|
+
* Document-class: Zstdlib::DataError
|
4810
4826
|
*
|
4811
|
-
* Subclass of
|
4827
|
+
* Subclass of Zstdlib::Error when zlib returns a Z_DATA_ERROR.
|
4812
4828
|
*
|
4813
4829
|
* Usually if a stream was prematurely freed.
|
4814
4830
|
*
|
4815
4831
|
*/
|
4816
4832
|
|
4817
4833
|
/*
|
4818
|
-
* Document-class:
|
4834
|
+
* Document-class: Zstdlib::GzipFile::Error
|
4819
4835
|
*
|
4820
4836
|
* Base class of errors that occur when processing GZIP files.
|
4821
4837
|
*/
|
4822
4838
|
|
4823
4839
|
/*
|
4824
|
-
* Document-class:
|
4840
|
+
* Document-class: Zstdlib::GzipFile::NoFooter
|
4825
4841
|
*
|
4826
4842
|
* Raised when gzip file footer is not found.
|
4827
4843
|
*/
|
4828
4844
|
|
4829
4845
|
/*
|
4830
|
-
* Document-class:
|
4846
|
+
* Document-class: Zstdlib::GzipFile::CRCError
|
4831
4847
|
*
|
4832
4848
|
* Raised when the CRC checksum recorded in gzip file footer is not equivalent
|
4833
4849
|
* to the CRC checksum of the actual uncompressed data.
|
4834
4850
|
*/
|
4835
4851
|
|
4836
4852
|
/*
|
4837
|
-
* Document-class:
|
4853
|
+
* Document-class: Zstdlib::GzipFile::LengthError
|
4838
4854
|
*
|
4839
4855
|
* Raised when the data length recorded in the gzip file footer is not equivalent
|
4840
4856
|
* to the length of the actual uncompressed data.
|