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
|
*/
|
@@ -1205,19 +1219,19 @@ get_zstream(VALUE obj)
|
|
1205
1219
|
/* ------------------------------------------------------------------------- */
|
1206
1220
|
|
1207
1221
|
/*
|
1208
|
-
* Document-class:
|
1222
|
+
* Document-class: Zstdlib::ZStream
|
1209
1223
|
*
|
1210
|
-
*
|
1224
|
+
* Zstdlib::ZStream is the abstract class for the stream which handles the
|
1211
1225
|
* compressed data. The operations are defined in the subclasses:
|
1212
|
-
*
|
1226
|
+
* Zstdlib::Deflate for compression, and Zstdlib::Inflate for decompression.
|
1213
1227
|
*
|
1214
|
-
* An instance of
|
1228
|
+
* An instance of Zstdlib::ZStream has one stream (struct zstream in the source)
|
1215
1229
|
* and two variable-length buffers which associated to the input (next_in) of
|
1216
1230
|
* the stream and the output (next_out) of the stream. In this document,
|
1217
1231
|
* "input buffer" means the buffer for input, and "output buffer" means the
|
1218
1232
|
* buffer for output.
|
1219
1233
|
*
|
1220
|
-
* Data input into an instance of
|
1234
|
+
* Data input into an instance of Zstdlib::ZStream are temporally stored into
|
1221
1235
|
* the end of input buffer, and then data in input buffer are processed from
|
1222
1236
|
* the beginning of the buffer until no more output from the stream is
|
1223
1237
|
* produced (i.e. until avail_out > 0 after processing). During processing,
|
@@ -1229,7 +1243,7 @@ get_zstream(VALUE obj)
|
|
1229
1243
|
*
|
1230
1244
|
* Here is an ascii art for describing above:
|
1231
1245
|
*
|
1232
|
-
* +================ an instance of
|
1246
|
+
* +================ an instance of Zstdlib::ZStream ================+
|
1233
1247
|
* || ||
|
1234
1248
|
* || +--------+ +-------+ +--------+ ||
|
1235
1249
|
* || +--| output |<---------|zstream|<---------| input |<--+ ||
|
@@ -1242,15 +1256,15 @@ get_zstream(VALUE obj)
|
|
1242
1256
|
* "output data" "input data"
|
1243
1257
|
*
|
1244
1258
|
* If an error occurs during processing input buffer, an exception which is a
|
1245
|
-
* subclass of
|
1259
|
+
* subclass of Zstdlib::Error is raised. At that time, both input and output
|
1246
1260
|
* buffer keep their conditions at the time when the error occurs.
|
1247
1261
|
*
|
1248
1262
|
* == Method Catalogue
|
1249
1263
|
*
|
1250
1264
|
* Many of the methods in this class are fairly low-level and unlikely to be
|
1251
1265
|
* of interest to users. In fact, users are unlikely to use this class
|
1252
|
-
* directly; rather they will be interested in
|
1253
|
-
*
|
1266
|
+
* directly; rather they will be interested in Zstdlib::Inflate and
|
1267
|
+
* Zstdlib::Deflate.
|
1254
1268
|
*
|
1255
1269
|
* The higher level methods are listed below.
|
1256
1270
|
*
|
@@ -1442,9 +1456,9 @@ rb_zstream_closed_p(VALUE obj)
|
|
1442
1456
|
/* ------------------------------------------------------------------------- */
|
1443
1457
|
|
1444
1458
|
/*
|
1445
|
-
* Document-class:
|
1459
|
+
* Document-class: Zstdlib::Deflate
|
1446
1460
|
*
|
1447
|
-
*
|
1461
|
+
* Zstdlib::Deflate is the class for compressing data. See Zstdlib::ZStream for more
|
1448
1462
|
* information.
|
1449
1463
|
*/
|
1450
1464
|
|
@@ -1452,7 +1466,7 @@ rb_zstream_closed_p(VALUE obj)
|
|
1452
1466
|
(NIL_P((val)) ? (ifnil) \
|
1453
1467
|
: (FIX2INT((val))))
|
1454
1468
|
|
1455
|
-
#define ARG_LEVEL(val) FIXNUMARG((val),
|
1469
|
+
#define ARG_LEVEL(val) FIXNUMARG((val), ZSTD_CLEVEL_DEFAULT)
|
1456
1470
|
#define ARG_WBITS(val) FIXNUMARG((val), MAX_WBITS)
|
1457
1471
|
#define ARG_MEMLEVEL(val) FIXNUMARG((val), DEF_MEM_LEVEL)
|
1458
1472
|
#define ARG_STRATEGY(val) FIXNUMARG((val), Z_DEFAULT_STRATEGY)
|
@@ -1466,10 +1480,10 @@ rb_deflate_s_allocate(VALUE klass)
|
|
1466
1480
|
}
|
1467
1481
|
|
1468
1482
|
/*
|
1469
|
-
* Document-method:
|
1483
|
+
* Document-method: Zstdlib::Deflate.new
|
1470
1484
|
*
|
1471
1485
|
* call-seq:
|
1472
|
-
*
|
1486
|
+
* Zstdlib::Deflate.new(level=DEFAULT_COMPRESSION, window_bits=MAX_WBITS, mem_level=DEF_MEM_LEVEL, strategy=DEFAULT_STRATEGY)
|
1473
1487
|
*
|
1474
1488
|
* Creates a new deflate stream for compression. If a given argument is nil,
|
1475
1489
|
* the default value of that argument is used.
|
@@ -1478,10 +1492,10 @@ rb_deflate_s_allocate(VALUE klass)
|
|
1478
1492
|
* compression) and 9 (best compression). The following constants have been
|
1479
1493
|
* defined to make code more readable:
|
1480
1494
|
*
|
1481
|
-
* *
|
1482
|
-
* *
|
1483
|
-
* *
|
1484
|
-
* *
|
1495
|
+
* * Zstdlib::DEFAULT_COMPRESSION
|
1496
|
+
* * Zstdlib::NO_COMPRESSION
|
1497
|
+
* * Zstdlib::BEST_SPEED
|
1498
|
+
* * Zstdlib::BEST_COMPRESSION
|
1485
1499
|
*
|
1486
1500
|
* See http://www.zlib.net/manual.html#Constants for further information.
|
1487
1501
|
*
|
@@ -1494,17 +1508,17 @@ rb_deflate_s_allocate(VALUE klass)
|
|
1494
1508
|
* compression ratio while 9 uses maximum memory for optimal speed. The
|
1495
1509
|
* default value is 8. Two constants are defined:
|
1496
1510
|
*
|
1497
|
-
* *
|
1498
|
-
* *
|
1511
|
+
* * Zstdlib::DEF_MEM_LEVEL
|
1512
|
+
* * Zstdlib::MAX_MEM_LEVEL
|
1499
1513
|
*
|
1500
1514
|
* The +strategy+ sets the deflate compression strategy. The following
|
1501
1515
|
* strategies are available:
|
1502
1516
|
*
|
1503
|
-
*
|
1504
|
-
*
|
1505
|
-
*
|
1506
|
-
*
|
1507
|
-
*
|
1517
|
+
* Zstdlib::DEFAULT_STRATEGY:: For normal data
|
1518
|
+
* Zstdlib::FILTERED:: For data produced by a filter or predictor
|
1519
|
+
* Zstdlib::FIXED:: Prevents dynamic Huffman codes
|
1520
|
+
* Zstdlib::HUFFMAN_ONLY:: Prevents string matching
|
1521
|
+
* Zstdlib::RLE:: Designed for better compression of PNG image data
|
1508
1522
|
*
|
1509
1523
|
* See the constants for further description.
|
1510
1524
|
*
|
@@ -1513,16 +1527,16 @@ rb_deflate_s_allocate(VALUE klass)
|
|
1513
1527
|
* === Basic
|
1514
1528
|
*
|
1515
1529
|
* open "compressed.file", "w+" do |io|
|
1516
|
-
* io <<
|
1530
|
+
* io << Zstdlib::Deflate.new.deflate(File.read("big.file"))
|
1517
1531
|
* end
|
1518
1532
|
*
|
1519
1533
|
* === Custom compression
|
1520
1534
|
*
|
1521
1535
|
* open "compressed.file", "w+" do |compressed_io|
|
1522
|
-
* deflate =
|
1523
|
-
*
|
1524
|
-
*
|
1525
|
-
*
|
1536
|
+
* deflate = Zstdlib::Deflate.new(Zstdlib::BEST_COMPRESSION,
|
1537
|
+
* Zstdlib::MAX_WBITS,
|
1538
|
+
* Zstdlib::MAX_MEM_LEVEL,
|
1539
|
+
* Zstdlib::HUFFMAN_ONLY)
|
1526
1540
|
*
|
1527
1541
|
* begin
|
1528
1542
|
* open "big.file" do |big_io|
|
@@ -1560,7 +1574,7 @@ rb_deflate_initialize(int argc, VALUE *argv, VALUE obj)
|
|
1560
1574
|
}
|
1561
1575
|
|
1562
1576
|
/*
|
1563
|
-
* Document-method:
|
1577
|
+
* Document-method: Zstdlib::Deflate#initialize_copy
|
1564
1578
|
*
|
1565
1579
|
* Duplicates the deflate stream.
|
1566
1580
|
*/
|
@@ -1596,26 +1610,26 @@ deflate_run(VALUE args)
|
|
1596
1610
|
}
|
1597
1611
|
|
1598
1612
|
/*
|
1599
|
-
* Document-method:
|
1613
|
+
* Document-method: Zstdlib::Deflate.deflate
|
1600
1614
|
*
|
1601
1615
|
* call-seq:
|
1602
|
-
*
|
1603
|
-
*
|
1616
|
+
* Zstdlib.deflate(string[, level])
|
1617
|
+
* Zstdlib::Deflate.deflate(string[, level])
|
1604
1618
|
*
|
1605
1619
|
* Compresses the given +string+. Valid values of level are
|
1606
|
-
*
|
1607
|
-
*
|
1620
|
+
* Zstdlib::NO_COMPRESSION, Zstdlib::BEST_SPEED, Zstdlib::BEST_COMPRESSION,
|
1621
|
+
* Zstdlib::DEFAULT_COMPRESSION, or an integer from 0 to 9.
|
1608
1622
|
*
|
1609
1623
|
* This method is almost equivalent to the following code:
|
1610
1624
|
*
|
1611
1625
|
* def deflate(string, level)
|
1612
|
-
* z =
|
1613
|
-
* dst = z.deflate(string,
|
1626
|
+
* z = Zstdlib::Deflate.new(level)
|
1627
|
+
* dst = z.deflate(string, Zstdlib::FINISH)
|
1614
1628
|
* z.close
|
1615
1629
|
* dst
|
1616
1630
|
* end
|
1617
1631
|
*
|
1618
|
-
* See also
|
1632
|
+
* See also Zstdlib.inflate
|
1619
1633
|
*
|
1620
1634
|
*/
|
1621
1635
|
static VALUE
|
@@ -1658,16 +1672,16 @@ do_deflate(struct zstream *z, VALUE src, int flush)
|
|
1658
1672
|
}
|
1659
1673
|
|
1660
1674
|
/*
|
1661
|
-
* Document-method:
|
1675
|
+
* Document-method: Zstdlib::Deflate#deflate
|
1662
1676
|
*
|
1663
1677
|
* call-seq:
|
1664
|
-
* z.deflate(string, flush =
|
1665
|
-
* z.deflate(string, flush =
|
1678
|
+
* z.deflate(string, flush = Zstdlib::NO_FLUSH) -> String
|
1679
|
+
* z.deflate(string, flush = Zstdlib::NO_FLUSH) { |chunk| ... } -> nil
|
1666
1680
|
*
|
1667
1681
|
* Inputs +string+ into the deflate stream and returns the output from the
|
1668
1682
|
* stream. On calling this method, both the input and the output buffers of
|
1669
1683
|
* the stream are flushed. If +string+ is nil, this method finishes the
|
1670
|
-
* stream, just like
|
1684
|
+
* stream, just like Zstdlib::ZStream#finish.
|
1671
1685
|
*
|
1672
1686
|
* If a block is given consecutive deflated chunks from the +string+ are
|
1673
1687
|
* yielded to the block and +nil+ is returned.
|
@@ -1675,10 +1689,10 @@ do_deflate(struct zstream *z, VALUE src, int flush)
|
|
1675
1689
|
* The +flush+ parameter specifies the flush mode. The following constants
|
1676
1690
|
* may be used:
|
1677
1691
|
*
|
1678
|
-
*
|
1679
|
-
*
|
1680
|
-
*
|
1681
|
-
*
|
1692
|
+
* Zstdlib::NO_FLUSH:: The default
|
1693
|
+
* Zstdlib::SYNC_FLUSH:: Flushes the output to a byte boundary
|
1694
|
+
* Zstdlib::FULL_FLUSH:: SYNC_FLUSH + resets the compression state
|
1695
|
+
* Zstdlib::FINISH:: Pending input is processed, pending output is flushed.
|
1682
1696
|
*
|
1683
1697
|
* See the constants for further description.
|
1684
1698
|
*
|
@@ -1697,12 +1711,12 @@ rb_deflate_deflate(int argc, VALUE *argv, VALUE obj)
|
|
1697
1711
|
}
|
1698
1712
|
|
1699
1713
|
/*
|
1700
|
-
* Document-method:
|
1714
|
+
* Document-method: Zstdlib::Deflate#<<
|
1701
1715
|
*
|
1702
1716
|
* call-seq: << string
|
1703
1717
|
*
|
1704
|
-
* Inputs +string+ into the deflate stream just like
|
1705
|
-
* returns the
|
1718
|
+
* Inputs +string+ into the deflate stream just like Zstdlib::Deflate#deflate, but
|
1719
|
+
* returns the Zstdlib::Deflate object itself. The output from the stream is
|
1706
1720
|
* preserved in output buffer.
|
1707
1721
|
*/
|
1708
1722
|
static VALUE
|
@@ -1714,18 +1728,18 @@ rb_deflate_addstr(VALUE obj, VALUE src)
|
|
1714
1728
|
}
|
1715
1729
|
|
1716
1730
|
/*
|
1717
|
-
* Document-method:
|
1731
|
+
* Document-method: Zstdlib::Deflate#flush
|
1718
1732
|
*
|
1719
1733
|
* call-seq:
|
1720
|
-
* flush(flush =
|
1721
|
-
* flush(flush =
|
1734
|
+
* flush(flush = Zstdlib::SYNC_FLUSH) -> String
|
1735
|
+
* flush(flush = Zstdlib::SYNC_FLUSH) { |chunk| ... } -> nil
|
1722
1736
|
*
|
1723
1737
|
* This method is equivalent to <tt>deflate('', flush)</tt>. This method is
|
1724
1738
|
* just provided to improve the readability of your Ruby program. If a block
|
1725
1739
|
* is given chunks of deflate output are yielded to the block until the buffer
|
1726
1740
|
* is flushed.
|
1727
1741
|
*
|
1728
|
-
* See
|
1742
|
+
* See Zstdlib::Deflate#deflate for detail on the +flush+ constants NO_FLUSH,
|
1729
1743
|
* SYNC_FLUSH, FULL_FLUSH and FINISH.
|
1730
1744
|
*/
|
1731
1745
|
static VALUE
|
@@ -1745,7 +1759,7 @@ rb_deflate_flush(int argc, VALUE *argv, VALUE obj)
|
|
1745
1759
|
}
|
1746
1760
|
|
1747
1761
|
/*
|
1748
|
-
* Document-method:
|
1762
|
+
* Document-method: Zstdlib::Deflate.params
|
1749
1763
|
*
|
1750
1764
|
* call-seq: params(level, strategy)
|
1751
1765
|
*
|
@@ -1753,7 +1767,7 @@ rb_deflate_flush(int argc, VALUE *argv, VALUE obj)
|
|
1753
1767
|
* different types of data that require different types of compression. Any
|
1754
1768
|
* unprocessed data is flushed before changing the params.
|
1755
1769
|
*
|
1756
|
-
* See
|
1770
|
+
* See Zstdlib::Deflate.new for a description of +level+ and +strategy+.
|
1757
1771
|
*
|
1758
1772
|
*/
|
1759
1773
|
static VALUE
|
@@ -1788,12 +1802,12 @@ rb_deflate_params(VALUE obj, VALUE v_level, VALUE v_strategy)
|
|
1788
1802
|
}
|
1789
1803
|
|
1790
1804
|
/*
|
1791
|
-
* Document-method:
|
1805
|
+
* Document-method: Zstdlib::Deflate.set_dictionary
|
1792
1806
|
*
|
1793
1807
|
* call-seq: set_dictionary(string)
|
1794
1808
|
*
|
1795
1809
|
* Sets the preset dictionary and returns +string+. This method is available
|
1796
|
-
* just only after
|
1810
|
+
* just only after Zstdlib::Deflate.new or Zstdlib::ZStream#reset method was called.
|
1797
1811
|
* See zlib.h for details.
|
1798
1812
|
*
|
1799
1813
|
* Can raise errors of Z_STREAM_ERROR if a parameter is invalid (such as
|
@@ -1823,10 +1837,10 @@ rb_deflate_set_dictionary(VALUE obj, VALUE dic)
|
|
1823
1837
|
/* ------------------------------------------------------------------------- */
|
1824
1838
|
|
1825
1839
|
/*
|
1826
|
-
* Document-class:
|
1840
|
+
* Document-class: Zstdlib::Inflate
|
1827
1841
|
*
|
1828
1842
|
* Zlib:Inflate is the class for decompressing compressed data. Unlike
|
1829
|
-
*
|
1843
|
+
* Zstdlib::Deflate, an instance of this class is not able to duplicate (clone,
|
1830
1844
|
* dup) itself.
|
1831
1845
|
*/
|
1832
1846
|
|
@@ -1839,10 +1853,10 @@ rb_inflate_s_allocate(VALUE klass)
|
|
1839
1853
|
}
|
1840
1854
|
|
1841
1855
|
/*
|
1842
|
-
* Document-method:
|
1856
|
+
* Document-method: Zstdlib::Inflate.new
|
1843
1857
|
*
|
1844
1858
|
* call-seq:
|
1845
|
-
*
|
1859
|
+
* Zstdlib::Inflate.new(window_bits = Zstdlib::MAX_WBITS)
|
1846
1860
|
*
|
1847
1861
|
* Creates a new inflate stream for decompression. +window_bits+ sets the
|
1848
1862
|
* size of the history buffer and can have the following values:
|
@@ -1859,7 +1873,7 @@ rb_inflate_s_allocate(VALUE klass)
|
|
1859
1873
|
* Greater than 15::
|
1860
1874
|
* Add 32 to window_bits to enable zlib and gzip decoding with automatic
|
1861
1875
|
* header detection, or add 16 to decode only the gzip format (a
|
1862
|
-
*
|
1876
|
+
* Zstdlib::DataError will be raised for a non-gzip stream).
|
1863
1877
|
*
|
1864
1878
|
* (-8..-15)::
|
1865
1879
|
* Enables raw deflate mode which will not generate a check value, and will
|
@@ -1871,7 +1885,7 @@ rb_inflate_s_allocate(VALUE klass)
|
|
1871
1885
|
* == Example
|
1872
1886
|
*
|
1873
1887
|
* open "compressed.file" do |compressed_io|
|
1874
|
-
* zi =
|
1888
|
+
* zi = Zstdlib::Inflate.new(Zstdlib::MAX_WBITS + 32)
|
1875
1889
|
*
|
1876
1890
|
* begin
|
1877
1891
|
* open "uncompressed.file", "w+" do |uncompressed_io|
|
@@ -1914,26 +1928,26 @@ inflate_run(VALUE args)
|
|
1914
1928
|
}
|
1915
1929
|
|
1916
1930
|
/*
|
1917
|
-
* Document-method:
|
1931
|
+
* Document-method: Zstdlib::inflate
|
1918
1932
|
*
|
1919
1933
|
* call-seq:
|
1920
|
-
*
|
1921
|
-
*
|
1934
|
+
* Zstdlib.inflate(string)
|
1935
|
+
* Zstdlib::Inflate.inflate(string)
|
1922
1936
|
*
|
1923
|
-
* Decompresses +string+. Raises a
|
1937
|
+
* Decompresses +string+. Raises a Zstdlib::NeedDict exception if a preset
|
1924
1938
|
* dictionary is needed for decompression.
|
1925
1939
|
*
|
1926
1940
|
* This method is almost equivalent to the following code:
|
1927
1941
|
*
|
1928
1942
|
* def inflate(string)
|
1929
|
-
* zstream =
|
1943
|
+
* zstream = Zstdlib::Inflate.new
|
1930
1944
|
* buf = zstream.inflate(string)
|
1931
1945
|
* zstream.finish
|
1932
1946
|
* zstream.close
|
1933
1947
|
* buf
|
1934
1948
|
* end
|
1935
1949
|
*
|
1936
|
-
* See also
|
1950
|
+
* See also Zstdlib.deflate
|
1937
1951
|
*
|
1938
1952
|
*/
|
1939
1953
|
static VALUE
|
@@ -1972,7 +1986,7 @@ do_inflate(struct zstream *z, VALUE src)
|
|
1972
1986
|
}
|
1973
1987
|
}
|
1974
1988
|
|
1975
|
-
/* Document-method:
|
1989
|
+
/* Document-method: Zstdlib::Inflate#add_dictionary
|
1976
1990
|
*
|
1977
1991
|
* call-seq: add_dictionary(string)
|
1978
1992
|
*
|
@@ -1993,7 +2007,7 @@ rb_inflate_add_dictionary(VALUE obj, VALUE dictionary)
|
|
1993
2007
|
}
|
1994
2008
|
|
1995
2009
|
/*
|
1996
|
-
* Document-method:
|
2010
|
+
* Document-method: Zstdlib::Inflate#inflate
|
1997
2011
|
*
|
1998
2012
|
* call-seq:
|
1999
2013
|
* inflate(deflate_string) -> String
|
@@ -2002,22 +2016,22 @@ rb_inflate_add_dictionary(VALUE obj, VALUE dictionary)
|
|
2002
2016
|
* Inputs +deflate_string+ into the inflate stream and returns the output from
|
2003
2017
|
* the stream. Calling this method, both the input and the output buffer of
|
2004
2018
|
* the stream are flushed. If string is +nil+, this method finishes the
|
2005
|
-
* stream, just like
|
2019
|
+
* stream, just like Zstdlib::ZStream#finish.
|
2006
2020
|
*
|
2007
2021
|
* If a block is given consecutive inflated chunks from the +deflate_string+
|
2008
2022
|
* are yielded to the block and +nil+ is returned.
|
2009
2023
|
*
|
2010
|
-
* Raises a
|
2011
|
-
* decompress. Set the dictionary by
|
2024
|
+
* Raises a Zstdlib::NeedDict exception if a preset dictionary is needed to
|
2025
|
+
* decompress. Set the dictionary by Zstdlib::Inflate#set_dictionary and then
|
2012
2026
|
* call this method again with an empty string to flush the stream:
|
2013
2027
|
*
|
2014
|
-
* inflater =
|
2028
|
+
* inflater = Zstdlib::Inflate.new
|
2015
2029
|
*
|
2016
2030
|
* begin
|
2017
2031
|
* out = inflater.inflate compressed
|
2018
|
-
* rescue
|
2032
|
+
* rescue Zstdlib::NeedDict
|
2019
2033
|
* # ensure the dictionary matches the stream's required dictionary
|
2020
|
-
* raise unless inflater.adler ==
|
2034
|
+
* raise unless inflater.adler == Zstdlib.adler32(dictionary)
|
2021
2035
|
*
|
2022
2036
|
* inflater.set_dictionary dictionary
|
2023
2037
|
* inflater.inflate ''
|
@@ -2027,7 +2041,7 @@ rb_inflate_add_dictionary(VALUE obj, VALUE dictionary)
|
|
2027
2041
|
*
|
2028
2042
|
* inflater.close
|
2029
2043
|
*
|
2030
|
-
* See also
|
2044
|
+
* See also Zstdlib::Inflate.new
|
2031
2045
|
*/
|
2032
2046
|
static VALUE
|
2033
2047
|
rb_inflate_inflate(VALUE obj, VALUE src)
|
@@ -2062,8 +2076,8 @@ rb_inflate_inflate(VALUE obj, VALUE src)
|
|
2062
2076
|
/*
|
2063
2077
|
* call-seq: << string
|
2064
2078
|
*
|
2065
|
-
* Inputs +string+ into the inflate stream just like
|
2066
|
-
* returns the
|
2079
|
+
* Inputs +string+ into the inflate stream just like Zstdlib::Inflate#inflate, but
|
2080
|
+
* returns the Zstdlib::Inflate object itself. The output from the stream is
|
2067
2081
|
* preserved in output buffer.
|
2068
2082
|
*/
|
2069
2083
|
static VALUE
|
@@ -2131,10 +2145,10 @@ rb_inflate_sync_point_p(VALUE obj)
|
|
2131
2145
|
}
|
2132
2146
|
|
2133
2147
|
/*
|
2134
|
-
* Document-method:
|
2148
|
+
* Document-method: Zstdlib::Inflate#set_dictionary
|
2135
2149
|
*
|
2136
2150
|
* Sets the preset dictionary and returns +string+. This method is available just
|
2137
|
-
* only after a
|
2151
|
+
* only after a Zstdlib::NeedDict exception was raised. See zlib.h for details.
|
2138
2152
|
*
|
2139
2153
|
*/
|
2140
2154
|
static VALUE
|
@@ -2270,7 +2284,7 @@ gzfile_free(void *p)
|
|
2270
2284
|
|
2271
2285
|
if (ZSTREAM_IS_READY(z)) {
|
2272
2286
|
if (z->func == &deflate_funcs) {
|
2273
|
-
finalizer_warn("
|
2287
|
+
finalizer_warn("Zstdlib::GzipWriter object must be closed explicitly.");
|
2274
2288
|
}
|
2275
2289
|
zstream_finalize(z);
|
2276
2290
|
}
|
@@ -2416,7 +2430,7 @@ gzfile_read_raw_ensure(struct gzfile *gz, long size, VALUE outbuf)
|
|
2416
2430
|
{
|
2417
2431
|
VALUE str;
|
2418
2432
|
|
2419
|
-
if (gz->io == Qundef) { /*
|
2433
|
+
if (gz->io == Qundef) { /* Zstdlib.gunzip */
|
2420
2434
|
if (NIL_P(gz->z.input) || RSTRING_LEN(gz->z.input) < size)
|
2421
2435
|
rb_raise(cGzError, "unexpected end of string");
|
2422
2436
|
}
|
@@ -2488,7 +2502,7 @@ gzfile_raise(struct gzfile *gz, VALUE klass, const char *message)
|
|
2488
2502
|
}
|
2489
2503
|
|
2490
2504
|
/*
|
2491
|
-
* Document-method:
|
2505
|
+
* Document-method: Zstdlib::GzipFile::Error#inspect
|
2492
2506
|
*
|
2493
2507
|
* Constructs a String of the GzipFile Error
|
2494
2508
|
*/
|
@@ -2526,7 +2540,7 @@ gzfile_make_header(struct gzfile *gz)
|
|
2526
2540
|
if (gz->level == Z_BEST_SPEED) {
|
2527
2541
|
extraflags |= GZ_EXTRAFLAG_FAST;
|
2528
2542
|
}
|
2529
|
-
else if (gz->level ==
|
2543
|
+
else if (gz->level == ZSTD_maxCLevel()) {
|
2530
2544
|
extraflags |= GZ_EXTRAFLAG_SLOW;
|
2531
2545
|
}
|
2532
2546
|
|
@@ -2598,10 +2612,10 @@ gzfile_read_header(struct gzfile *gz, VALUE outbuf)
|
|
2598
2612
|
gz->level = Z_BEST_SPEED;
|
2599
2613
|
}
|
2600
2614
|
else if (head[8] & GZ_EXTRAFLAG_SLOW) {
|
2601
|
-
gz->level =
|
2615
|
+
gz->level = ZSTD_maxCLevel();
|
2602
2616
|
}
|
2603
2617
|
else {
|
2604
|
-
gz->level =
|
2618
|
+
gz->level = ZSTD_CLEVEL_DEFAULT;
|
2605
2619
|
}
|
2606
2620
|
|
2607
2621
|
gz->mtime = gzfile_get32(&head[4]);
|
@@ -2989,40 +3003,40 @@ get_gzfile(VALUE obj)
|
|
2989
3003
|
/* ------------------------------------------------------------------------- */
|
2990
3004
|
|
2991
3005
|
/*
|
2992
|
-
* Document-class:
|
3006
|
+
* Document-class: Zstdlib::GzipFile
|
2993
3007
|
*
|
2994
|
-
*
|
3008
|
+
* Zstdlib::GzipFile is an abstract class for handling a gzip formatted
|
2995
3009
|
* compressed file. The operations are defined in the subclasses,
|
2996
|
-
*
|
3010
|
+
* Zstdlib::GzipReader for reading, and Zstdlib::GzipWriter for writing.
|
2997
3011
|
*
|
2998
3012
|
* GzipReader should be used by associating an IO, or IO-like, object.
|
2999
3013
|
*
|
3000
3014
|
* == Method Catalogue
|
3001
3015
|
*
|
3002
3016
|
* - ::wrap
|
3003
|
-
* - ::open (
|
3017
|
+
* - ::open (Zstdlib::GzipReader::open and Zstdlib::GzipWriter::open)
|
3004
3018
|
* - #close
|
3005
3019
|
* - #closed?
|
3006
3020
|
* - #comment
|
3007
|
-
* - comment= (
|
3021
|
+
* - comment= (Zstdlib::GzipWriter#comment=)
|
3008
3022
|
* - #crc
|
3009
|
-
* - eof? (
|
3023
|
+
* - eof? (Zstdlib::GzipReader#eof?)
|
3010
3024
|
* - #finish
|
3011
3025
|
* - #level
|
3012
|
-
* - lineno (
|
3013
|
-
* - lineno= (
|
3026
|
+
* - lineno (Zstdlib::GzipReader#lineno)
|
3027
|
+
* - lineno= (Zstdlib::GzipReader#lineno=)
|
3014
3028
|
* - #mtime
|
3015
|
-
* - mtime= (
|
3029
|
+
* - mtime= (Zstdlib::GzipWriter#mtime=)
|
3016
3030
|
* - #orig_name
|
3017
|
-
* - orig_name (
|
3031
|
+
* - orig_name (Zstdlib::GzipWriter#orig_name=)
|
3018
3032
|
* - #os_code
|
3019
3033
|
* - path (when the underlying IO supports #path)
|
3020
3034
|
* - #sync
|
3021
3035
|
* - #sync=
|
3022
3036
|
* - #to_io
|
3023
3037
|
*
|
3024
|
-
* (due to internal structure, documentation may appear under
|
3025
|
-
* or
|
3038
|
+
* (due to internal structure, documentation may appear under Zstdlib::GzipReader
|
3039
|
+
* or Zstdlib::GzipWriter)
|
3026
3040
|
*/
|
3027
3041
|
|
3028
3042
|
|
@@ -3081,11 +3095,11 @@ gzfile_wrap(int argc, VALUE *argv, VALUE klass, int close_io_on_error)
|
|
3081
3095
|
}
|
3082
3096
|
|
3083
3097
|
/*
|
3084
|
-
* Document-method:
|
3098
|
+
* Document-method: Zstdlib::GzipFile.wrap
|
3085
3099
|
*
|
3086
3100
|
* call-seq:
|
3087
|
-
*
|
3088
|
-
*
|
3101
|
+
* Zstdlib::GzipReader.wrap(io, ...) { |gz| ... }
|
3102
|
+
* Zstdlib::GzipWriter.wrap(io, ...) { |gz| ... }
|
3089
3103
|
*
|
3090
3104
|
* Creates a GzipReader or GzipWriter associated with +io+, passing in any
|
3091
3105
|
* necessary extra options, and executes the block with the newly created
|
@@ -3093,7 +3107,7 @@ gzfile_wrap(int argc, VALUE *argv, VALUE klass, int close_io_on_error)
|
|
3093
3107
|
*
|
3094
3108
|
* The GzipFile object will be closed automatically after executing the block.
|
3095
3109
|
* If you want to keep the associated IO object open, you may call
|
3096
|
-
*
|
3110
|
+
* Zstdlib::GzipFile#finish method in the block.
|
3097
3111
|
*/
|
3098
3112
|
static VALUE
|
3099
3113
|
rb_gzfile_s_wrap(int argc, VALUE *argv, VALUE klass)
|
@@ -3102,9 +3116,9 @@ rb_gzfile_s_wrap(int argc, VALUE *argv, VALUE klass)
|
|
3102
3116
|
}
|
3103
3117
|
|
3104
3118
|
/*
|
3105
|
-
* Document-method:
|
3119
|
+
* Document-method: Zstdlib::GzipFile.open
|
3106
3120
|
*
|
3107
|
-
* See
|
3121
|
+
* See Zstdlib::GzipReader#open and Zstdlib::GzipWriter#open.
|
3108
3122
|
*/
|
3109
3123
|
static VALUE
|
3110
3124
|
gzfile_s_open(int argc, VALUE *argv, VALUE klass, const char *mode)
|
@@ -3119,7 +3133,7 @@ gzfile_s_open(int argc, VALUE *argv, VALUE klass, const char *mode)
|
|
3119
3133
|
}
|
3120
3134
|
|
3121
3135
|
/*
|
3122
|
-
* Document-method:
|
3136
|
+
* Document-method: Zstdlib::GzipFile#to_io
|
3123
3137
|
*
|
3124
3138
|
* Same as IO.
|
3125
3139
|
*/
|
@@ -3130,7 +3144,7 @@ rb_gzfile_to_io(VALUE obj)
|
|
3130
3144
|
}
|
3131
3145
|
|
3132
3146
|
/*
|
3133
|
-
* Document-method:
|
3147
|
+
* Document-method: Zstdlib::GzipFile#crc
|
3134
3148
|
*
|
3135
3149
|
* Returns CRC value of the uncompressed data.
|
3136
3150
|
*/
|
@@ -3141,7 +3155,7 @@ rb_gzfile_crc(VALUE obj)
|
|
3141
3155
|
}
|
3142
3156
|
|
3143
3157
|
/*
|
3144
|
-
* Document-method:
|
3158
|
+
* Document-method: Zstdlib::GzipFile#mtime
|
3145
3159
|
*
|
3146
3160
|
* Returns last modification time recorded in the gzip file header.
|
3147
3161
|
*/
|
@@ -3152,7 +3166,7 @@ rb_gzfile_mtime(VALUE obj)
|
|
3152
3166
|
}
|
3153
3167
|
|
3154
3168
|
/*
|
3155
|
-
* Document-method:
|
3169
|
+
* Document-method: Zstdlib::GzipFile#level
|
3156
3170
|
*
|
3157
3171
|
* Returns compression level.
|
3158
3172
|
*/
|
@@ -3163,7 +3177,7 @@ rb_gzfile_level(VALUE obj)
|
|
3163
3177
|
}
|
3164
3178
|
|
3165
3179
|
/*
|
3166
|
-
* Document-method:
|
3180
|
+
* Document-method: Zstdlib::GzipFile#os_code
|
3167
3181
|
*
|
3168
3182
|
* Returns OS code number recorded in the gzip file header.
|
3169
3183
|
*/
|
@@ -3174,7 +3188,7 @@ rb_gzfile_os_code(VALUE obj)
|
|
3174
3188
|
}
|
3175
3189
|
|
3176
3190
|
/*
|
3177
|
-
* Document-method:
|
3191
|
+
* Document-method: Zstdlib::GzipFile#orig_name
|
3178
3192
|
*
|
3179
3193
|
* Returns original filename recorded in the gzip file header, or +nil+ if
|
3180
3194
|
* original filename is not present.
|
@@ -3191,7 +3205,7 @@ rb_gzfile_orig_name(VALUE obj)
|
|
3191
3205
|
}
|
3192
3206
|
|
3193
3207
|
/*
|
3194
|
-
* Document-method:
|
3208
|
+
* Document-method: Zstdlib::GzipFile#comment
|
3195
3209
|
*
|
3196
3210
|
* Returns comments recorded in the gzip file header, or nil if the comments
|
3197
3211
|
* is not present.
|
@@ -3208,7 +3222,7 @@ rb_gzfile_comment(VALUE obj)
|
|
3208
3222
|
}
|
3209
3223
|
|
3210
3224
|
/*
|
3211
|
-
* Document-method:
|
3225
|
+
* Document-method: Zstdlib::GzipFile#lineno
|
3212
3226
|
*
|
3213
3227
|
* The line number of the last row read from this file.
|
3214
3228
|
*/
|
@@ -3219,7 +3233,7 @@ rb_gzfile_lineno(VALUE obj)
|
|
3219
3233
|
}
|
3220
3234
|
|
3221
3235
|
/*
|
3222
|
-
* Document-method:
|
3236
|
+
* Document-method: Zstdlib::GzipReader#lineno=
|
3223
3237
|
*
|
3224
3238
|
* Specify line number of the last row read from this file.
|
3225
3239
|
*/
|
@@ -3232,7 +3246,7 @@ rb_gzfile_set_lineno(VALUE obj, VALUE lineno)
|
|
3232
3246
|
}
|
3233
3247
|
|
3234
3248
|
/*
|
3235
|
-
* Document-method:
|
3249
|
+
* Document-method: Zstdlib::GzipWriter#mtime=
|
3236
3250
|
*
|
3237
3251
|
* Specify the modification time (+mtime+) in the gzip header.
|
3238
3252
|
* Using an Integer.
|
@@ -3267,7 +3281,7 @@ rb_gzfile_set_mtime(VALUE obj, VALUE mtime)
|
|
3267
3281
|
}
|
3268
3282
|
|
3269
3283
|
/*
|
3270
|
-
* Document-method:
|
3284
|
+
* Document-method: Zstdlib::GzipFile#orig_name=
|
3271
3285
|
*
|
3272
3286
|
* Specify the original name (+str+) in the gzip header.
|
3273
3287
|
*/
|
@@ -3291,7 +3305,7 @@ rb_gzfile_set_orig_name(VALUE obj, VALUE str)
|
|
3291
3305
|
}
|
3292
3306
|
|
3293
3307
|
/*
|
3294
|
-
* Document-method:
|
3308
|
+
* Document-method: Zstdlib::GzipFile#comment=
|
3295
3309
|
*
|
3296
3310
|
* Specify the comment (+str+) in the gzip header.
|
3297
3311
|
*/
|
@@ -3315,7 +3329,7 @@ rb_gzfile_set_comment(VALUE obj, VALUE str)
|
|
3315
3329
|
}
|
3316
3330
|
|
3317
3331
|
/*
|
3318
|
-
* Document-method:
|
3332
|
+
* Document-method: Zstdlib::GzipFile#close
|
3319
3333
|
*
|
3320
3334
|
* Closes the GzipFile object. This method calls close method of the
|
3321
3335
|
* associated IO object. Returns the associated IO object.
|
@@ -3336,9 +3350,9 @@ rb_gzfile_close(VALUE obj)
|
|
3336
3350
|
}
|
3337
3351
|
|
3338
3352
|
/*
|
3339
|
-
* Document-method:
|
3353
|
+
* Document-method: Zstdlib::GzipFile#finish
|
3340
3354
|
*
|
3341
|
-
* Closes the GzipFile object. Unlike
|
3355
|
+
* Closes the GzipFile object. Unlike Zstdlib::GzipFile#close, this method never
|
3342
3356
|
* calls the close method of the associated IO object. Returns the associated IO
|
3343
3357
|
* object.
|
3344
3358
|
*/
|
@@ -3354,7 +3368,7 @@ rb_gzfile_finish(VALUE obj)
|
|
3354
3368
|
}
|
3355
3369
|
|
3356
3370
|
/*
|
3357
|
-
* Document-method:
|
3371
|
+
* Document-method: Zstdlib::GzipFile#closed?
|
3358
3372
|
*
|
3359
3373
|
* Same as IO#closed?
|
3360
3374
|
*
|
@@ -3368,7 +3382,7 @@ rb_gzfile_closed_p(VALUE obj)
|
|
3368
3382
|
}
|
3369
3383
|
|
3370
3384
|
/*
|
3371
|
-
* Document-method:
|
3385
|
+
* Document-method: Zstdlib::GzipFile#eof?
|
3372
3386
|
*
|
3373
3387
|
* Returns +true+ or +false+ whether the stream has reached the end.
|
3374
3388
|
*/
|
@@ -3380,7 +3394,7 @@ rb_gzfile_eof_p(VALUE obj)
|
|
3380
3394
|
}
|
3381
3395
|
|
3382
3396
|
/*
|
3383
|
-
* Document-method:
|
3397
|
+
* Document-method: Zstdlib::GzipFile#sync
|
3384
3398
|
*
|
3385
3399
|
* Same as IO#sync
|
3386
3400
|
*
|
@@ -3392,7 +3406,7 @@ rb_gzfile_sync(VALUE obj)
|
|
3392
3406
|
}
|
3393
3407
|
|
3394
3408
|
/*
|
3395
|
-
* Document-method:
|
3409
|
+
* Document-method: Zstdlib::GzipFile#sync=
|
3396
3410
|
*
|
3397
3411
|
* call-seq: sync = flag
|
3398
3412
|
*
|
@@ -3415,7 +3429,7 @@ rb_gzfile_set_sync(VALUE obj, VALUE mode)
|
|
3415
3429
|
}
|
3416
3430
|
|
3417
3431
|
/*
|
3418
|
-
* Document-method:
|
3432
|
+
* Document-method: Zstdlib::GzipFile#total_in
|
3419
3433
|
*
|
3420
3434
|
* Total number of input bytes read so far.
|
3421
3435
|
*/
|
@@ -3426,7 +3440,7 @@ rb_gzfile_total_in(VALUE obj)
|
|
3426
3440
|
}
|
3427
3441
|
|
3428
3442
|
/*
|
3429
|
-
* Document-method:
|
3443
|
+
* Document-method: Zstdlib::GzipFile#total_out
|
3430
3444
|
*
|
3431
3445
|
* Total number of output bytes output so far.
|
3432
3446
|
*/
|
@@ -3445,7 +3459,7 @@ rb_gzfile_total_out(VALUE obj)
|
|
3445
3459
|
}
|
3446
3460
|
|
3447
3461
|
/*
|
3448
|
-
* Document-method:
|
3462
|
+
* Document-method: Zstdlib::GzipFile#path
|
3449
3463
|
*
|
3450
3464
|
* call-seq: path
|
3451
3465
|
*
|
@@ -3477,19 +3491,19 @@ rb_gzfile_ecopts(struct gzfile *gz, VALUE opts)
|
|
3477
3491
|
/* ------------------------------------------------------------------------- */
|
3478
3492
|
|
3479
3493
|
/*
|
3480
|
-
* Document-class:
|
3494
|
+
* Document-class: Zstdlib::GzipWriter
|
3481
3495
|
*
|
3482
|
-
*
|
3496
|
+
* Zstdlib::GzipWriter is a class for writing gzipped files. GzipWriter should
|
3483
3497
|
* be used with an instance of IO, or IO-like, object.
|
3484
3498
|
*
|
3485
3499
|
* Following two example generate the same result.
|
3486
3500
|
*
|
3487
|
-
*
|
3501
|
+
* Zstdlib::GzipWriter.open('hoge.gz') do |gz|
|
3488
3502
|
* gz.write 'jugemu jugemu gokou no surikire...'
|
3489
3503
|
* end
|
3490
3504
|
*
|
3491
3505
|
* File.open('hoge.gz', 'w') do |f|
|
3492
|
-
* gz =
|
3506
|
+
* gz = Zstdlib::GzipWriter.new(f)
|
3493
3507
|
* gz.write 'jugemu jugemu gokou no surikire...'
|
3494
3508
|
* gz.close
|
3495
3509
|
* end
|
@@ -3497,14 +3511,14 @@ rb_gzfile_ecopts(struct gzfile *gz, VALUE opts)
|
|
3497
3511
|
* To make like gzip(1) does, run following:
|
3498
3512
|
*
|
3499
3513
|
* orig = 'hoge.txt'
|
3500
|
-
*
|
3514
|
+
* Zstdlib::GzipWriter.open('hoge.gz') do |gz|
|
3501
3515
|
* gz.mtime = File.mtime(orig)
|
3502
3516
|
* gz.orig_name = orig
|
3503
3517
|
* gz.write IO.binread(orig)
|
3504
3518
|
* end
|
3505
3519
|
*
|
3506
3520
|
* NOTE: Due to the limitation of Ruby's finalizer, you must explicitly close
|
3507
|
-
* GzipWriter objects by
|
3521
|
+
* GzipWriter objects by Zstdlib::GzipWriter#close etc. Otherwise, GzipWriter
|
3508
3522
|
* will be not able to write the gzip footer and will generate a broken gzip
|
3509
3523
|
* file.
|
3510
3524
|
*/
|
@@ -3516,11 +3530,11 @@ rb_gzwriter_s_allocate(VALUE klass)
|
|
3516
3530
|
}
|
3517
3531
|
|
3518
3532
|
/*
|
3519
|
-
* call-seq:
|
3533
|
+
* call-seq: Zstdlib::GzipWriter.open(filename, level=nil, strategy=nil) { |gz| ... }
|
3520
3534
|
*
|
3521
3535
|
* Opens a file specified by +filename+ for writing gzip compressed data, and
|
3522
3536
|
* returns a GzipWriter object associated with that file. Further details of
|
3523
|
-
* this method are found in
|
3537
|
+
* this method are found in Zstdlib::GzipWriter.new and Zstdlib::GzipFile.wrap.
|
3524
3538
|
*/
|
3525
3539
|
static VALUE
|
3526
3540
|
rb_gzwriter_s_open(int argc, VALUE *argv, VALUE klass)
|
@@ -3530,10 +3544,10 @@ rb_gzwriter_s_open(int argc, VALUE *argv, VALUE klass)
|
|
3530
3544
|
|
3531
3545
|
/*
|
3532
3546
|
* call-seq:
|
3533
|
-
*
|
3547
|
+
* Zstdlib::GzipWriter.new(io, level = nil, strategy = nil, options = {})
|
3534
3548
|
*
|
3535
3549
|
* Creates a GzipWriter object associated with +io+. +level+ and +strategy+
|
3536
|
-
* should be the same as the arguments of
|
3550
|
+
* should be the same as the arguments of Zstdlib::Deflate.new. The GzipWriter
|
3537
3551
|
* object writes gzipped data to +io+. +io+ must respond to the
|
3538
3552
|
* +write+ method that behaves the same as IO#write.
|
3539
3553
|
*
|
@@ -3579,8 +3593,8 @@ rb_gzwriter_initialize(int argc, VALUE *argv, VALUE obj)
|
|
3579
3593
|
* call-seq: flush(flush=nil)
|
3580
3594
|
*
|
3581
3595
|
* Flushes all the internal buffers of the GzipWriter object. The meaning of
|
3582
|
-
* +flush+ is same as in
|
3583
|
-
* +flush+ is omitted. It is no use giving flush <tt>
|
3596
|
+
* +flush+ is same as in Zstdlib::Deflate#deflate. <tt>Zstdlib::SYNC_FLUSH</tt> is used if
|
3597
|
+
* +flush+ is omitted. It is no use giving flush <tt>Zstdlib::NO_FLUSH</tt>.
|
3584
3598
|
*/
|
3585
3599
|
static VALUE
|
3586
3600
|
rb_gzwriter_flush(int argc, VALUE *argv, VALUE obj)
|
@@ -3666,25 +3680,25 @@ rb_gzwriter_putc(VALUE obj, VALUE ch)
|
|
3666
3680
|
/* ------------------------------------------------------------------------- */
|
3667
3681
|
|
3668
3682
|
/*
|
3669
|
-
* Document-class:
|
3683
|
+
* Document-class: Zstdlib::GzipReader
|
3670
3684
|
*
|
3671
|
-
*
|
3685
|
+
* Zstdlib::GzipReader is the class for reading a gzipped file. GzipReader should
|
3672
3686
|
* be used as an IO, or -IO-like, object.
|
3673
3687
|
*
|
3674
|
-
*
|
3688
|
+
* Zstdlib::GzipReader.open('hoge.gz') {|gz|
|
3675
3689
|
* print gz.read
|
3676
3690
|
* }
|
3677
3691
|
*
|
3678
3692
|
* File.open('hoge.gz') do |f|
|
3679
|
-
* gz =
|
3693
|
+
* gz = Zstdlib::GzipReader.new(f)
|
3680
3694
|
* print gz.read
|
3681
3695
|
* gz.close
|
3682
3696
|
* end
|
3683
3697
|
*
|
3684
3698
|
* == Method Catalogue
|
3685
3699
|
*
|
3686
|
-
* The following methods in
|
3687
|
-
* in IO, but they raise
|
3700
|
+
* The following methods in Zstdlib::GzipReader are just like their counterparts
|
3701
|
+
* in IO, but they raise Zstdlib::Error or Zstdlib::GzipFile::Error exception if an
|
3688
3702
|
* error was found in the gzip file.
|
3689
3703
|
* - #each
|
3690
3704
|
* - #each_line
|
@@ -3702,15 +3716,15 @@ rb_gzwriter_putc(VALUE obj, VALUE ch)
|
|
3702
3716
|
* Be careful of the footer of the gzip file. A gzip file has the checksum of
|
3703
3717
|
* pre-compressed data in its footer. GzipReader checks all uncompressed data
|
3704
3718
|
* against that checksum at the following cases, and if it fails, raises
|
3705
|
-
* <tt>
|
3706
|
-
* <tt>
|
3719
|
+
* <tt>Zstdlib::GzipFile::NoFooter</tt>, <tt>Zstdlib::GzipFile::CRCError</tt>, or
|
3720
|
+
* <tt>Zstdlib::GzipFile::LengthError</tt> exception.
|
3707
3721
|
*
|
3708
3722
|
* - When an reading request is received beyond the end of file (the end of
|
3709
|
-
* compressed data). That is, when
|
3710
|
-
*
|
3711
|
-
* - When
|
3723
|
+
* compressed data). That is, when Zstdlib::GzipReader#read,
|
3724
|
+
* Zstdlib::GzipReader#gets, or some other methods for reading returns nil.
|
3725
|
+
* - When Zstdlib::GzipFile#close method is called after the object reaches the
|
3712
3726
|
* end of file.
|
3713
|
-
* - When
|
3727
|
+
* - When Zstdlib::GzipReader#unused method is called after the object reaches
|
3714
3728
|
* the end of file.
|
3715
3729
|
*
|
3716
3730
|
* The rest of the methods are adequately described in their own
|
@@ -3724,13 +3738,13 @@ rb_gzreader_s_allocate(VALUE klass)
|
|
3724
3738
|
}
|
3725
3739
|
|
3726
3740
|
/*
|
3727
|
-
* Document-method:
|
3741
|
+
* Document-method: Zstdlib::GzipReader.open
|
3728
3742
|
*
|
3729
|
-
* call-seq:
|
3743
|
+
* call-seq: Zstdlib::GzipReader.open(filename) {|gz| ... }
|
3730
3744
|
*
|
3731
3745
|
* Opens a file specified by +filename+ as a gzipped file, and returns a
|
3732
3746
|
* GzipReader object associated with that file. Further details of this method
|
3733
|
-
* are in
|
3747
|
+
* are in Zstdlib::GzipReader.new and ZLib::GzipFile.wrap.
|
3734
3748
|
*/
|
3735
3749
|
static VALUE
|
3736
3750
|
rb_gzreader_s_open(int argc, VALUE *argv, VALUE klass)
|
@@ -3739,10 +3753,10 @@ rb_gzreader_s_open(int argc, VALUE *argv, VALUE klass)
|
|
3739
3753
|
}
|
3740
3754
|
|
3741
3755
|
/*
|
3742
|
-
* Document-method:
|
3756
|
+
* Document-method: Zstdlib::GzipReader.new
|
3743
3757
|
*
|
3744
3758
|
* call-seq:
|
3745
|
-
*
|
3759
|
+
* Zstdlib::GzipReader.new(io, options = {})
|
3746
3760
|
*
|
3747
3761
|
* Creates a GzipReader object associated with +io+. The GzipReader object reads
|
3748
3762
|
* gzipped data from +io+, and parses/decompresses it. The +io+ must
|
@@ -3752,7 +3766,7 @@ rb_gzreader_s_open(int argc, VALUE *argv, VALUE klass)
|
|
3752
3766
|
* +:external_encoding+, +:internal_encoding+ and +:encoding+ may be set as in
|
3753
3767
|
* IO::new.
|
3754
3768
|
*
|
3755
|
-
* If the gzip file header is incorrect, raises an
|
3769
|
+
* If the gzip file header is incorrect, raises an Zstdlib::GzipFile::Error
|
3756
3770
|
* exception.
|
3757
3771
|
*/
|
3758
3772
|
static VALUE
|
@@ -3784,7 +3798,7 @@ rb_gzreader_initialize(int argc, VALUE *argv, VALUE obj)
|
|
3784
3798
|
}
|
3785
3799
|
|
3786
3800
|
/*
|
3787
|
-
* Document-method:
|
3801
|
+
* Document-method: Zstdlib::GzipReader#rewind
|
3788
3802
|
*
|
3789
3803
|
* Resets the position of the file pointer to the point created the GzipReader
|
3790
3804
|
* object. The associated IO object needs to respond to the +seek+ method.
|
@@ -3798,7 +3812,7 @@ rb_gzreader_rewind(VALUE obj)
|
|
3798
3812
|
}
|
3799
3813
|
|
3800
3814
|
/*
|
3801
|
-
* Document-method:
|
3815
|
+
* Document-method: Zstdlib::GzipReader#unused
|
3802
3816
|
*
|
3803
3817
|
* Returns the rest of the data which had read for parsing gzip format, or
|
3804
3818
|
* +nil+ if the whole gzip file is not parsed yet.
|
@@ -3812,9 +3826,9 @@ rb_gzreader_unused(VALUE obj)
|
|
3812
3826
|
}
|
3813
3827
|
|
3814
3828
|
/*
|
3815
|
-
* Document-method:
|
3829
|
+
* Document-method: Zstdlib::GzipReader#read
|
3816
3830
|
*
|
3817
|
-
* See
|
3831
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3818
3832
|
*/
|
3819
3833
|
static VALUE
|
3820
3834
|
rb_gzreader_read(int argc, VALUE *argv, VALUE obj)
|
@@ -3836,7 +3850,7 @@ rb_gzreader_read(int argc, VALUE *argv, VALUE obj)
|
|
3836
3850
|
}
|
3837
3851
|
|
3838
3852
|
/*
|
3839
|
-
* Document-method:
|
3853
|
+
* Document-method: Zstdlib::GzipReader#readpartial
|
3840
3854
|
*
|
3841
3855
|
* call-seq:
|
3842
3856
|
* gzipreader.readpartial(maxlen [, outbuf]) => string, outbuf
|
@@ -3866,9 +3880,9 @@ rb_gzreader_readpartial(int argc, VALUE *argv, VALUE obj)
|
|
3866
3880
|
}
|
3867
3881
|
|
3868
3882
|
/*
|
3869
|
-
* Document-method:
|
3883
|
+
* Document-method: Zstdlib::GzipReader#getc
|
3870
3884
|
*
|
3871
|
-
* See
|
3885
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3872
3886
|
*/
|
3873
3887
|
static VALUE
|
3874
3888
|
rb_gzreader_getc(VALUE obj)
|
@@ -3879,9 +3893,9 @@ rb_gzreader_getc(VALUE obj)
|
|
3879
3893
|
}
|
3880
3894
|
|
3881
3895
|
/*
|
3882
|
-
* Document-method:
|
3896
|
+
* Document-method: Zstdlib::GzipReader#readchar
|
3883
3897
|
*
|
3884
|
-
* See
|
3898
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3885
3899
|
*/
|
3886
3900
|
static VALUE
|
3887
3901
|
rb_gzreader_readchar(VALUE obj)
|
@@ -3895,9 +3909,9 @@ rb_gzreader_readchar(VALUE obj)
|
|
3895
3909
|
}
|
3896
3910
|
|
3897
3911
|
/*
|
3898
|
-
* Document-method:
|
3912
|
+
* Document-method: Zstdlib::GzipReader#getbyte
|
3899
3913
|
*
|
3900
|
-
* See
|
3914
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3901
3915
|
*/
|
3902
3916
|
static VALUE
|
3903
3917
|
rb_gzreader_getbyte(VALUE obj)
|
@@ -3913,9 +3927,9 @@ rb_gzreader_getbyte(VALUE obj)
|
|
3913
3927
|
}
|
3914
3928
|
|
3915
3929
|
/*
|
3916
|
-
* Document-method:
|
3930
|
+
* Document-method: Zstdlib::GzipReader#readbyte
|
3917
3931
|
*
|
3918
|
-
* See
|
3932
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3919
3933
|
*/
|
3920
3934
|
static VALUE
|
3921
3935
|
rb_gzreader_readbyte(VALUE obj)
|
@@ -3929,9 +3943,9 @@ rb_gzreader_readbyte(VALUE obj)
|
|
3929
3943
|
}
|
3930
3944
|
|
3931
3945
|
/*
|
3932
|
-
* Document-method:
|
3946
|
+
* Document-method: Zstdlib::GzipReader#each_char
|
3933
3947
|
*
|
3934
|
-
* See
|
3948
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3935
3949
|
*/
|
3936
3950
|
static VALUE
|
3937
3951
|
rb_gzreader_each_char(VALUE obj)
|
@@ -3947,9 +3961,9 @@ rb_gzreader_each_char(VALUE obj)
|
|
3947
3961
|
}
|
3948
3962
|
|
3949
3963
|
/*
|
3950
|
-
* Document-method:
|
3964
|
+
* Document-method: Zstdlib::GzipReader#each_byte
|
3951
3965
|
*
|
3952
|
-
* See
|
3966
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3953
3967
|
*/
|
3954
3968
|
static VALUE
|
3955
3969
|
rb_gzreader_each_byte(VALUE obj)
|
@@ -3965,23 +3979,23 @@ rb_gzreader_each_byte(VALUE obj)
|
|
3965
3979
|
}
|
3966
3980
|
|
3967
3981
|
/*
|
3968
|
-
* Document-method:
|
3982
|
+
* Document-method: Zstdlib::GzipReader#bytes
|
3969
3983
|
*
|
3970
3984
|
* This is a deprecated alias for <code>each_byte</code>.
|
3971
3985
|
*/
|
3972
3986
|
static VALUE
|
3973
3987
|
rb_gzreader_bytes(VALUE obj)
|
3974
3988
|
{
|
3975
|
-
rb_warn("
|
3989
|
+
rb_warn("Zstdlib::GzipReader#bytes is deprecated; use #each_byte instead");
|
3976
3990
|
if (!rb_block_given_p())
|
3977
3991
|
return rb_enumeratorize(obj, ID2SYM(rb_intern("each_byte")), 0, 0);
|
3978
3992
|
return rb_gzreader_each_byte(obj);
|
3979
3993
|
}
|
3980
3994
|
|
3981
3995
|
/*
|
3982
|
-
* Document-method:
|
3996
|
+
* Document-method: Zstdlib::GzipReader#ungetc
|
3983
3997
|
*
|
3984
|
-
* See
|
3998
|
+
* See Zstdlib::GzipReader documentation for a description.
|
3985
3999
|
*/
|
3986
4000
|
static VALUE
|
3987
4001
|
rb_gzreader_ungetc(VALUE obj, VALUE s)
|
@@ -4001,9 +4015,9 @@ rb_gzreader_ungetc(VALUE obj, VALUE s)
|
|
4001
4015
|
}
|
4002
4016
|
|
4003
4017
|
/*
|
4004
|
-
* Document-method:
|
4018
|
+
* Document-method: Zstdlib::GzipReader#ungetbyte
|
4005
4019
|
*
|
4006
|
-
* See
|
4020
|
+
* See Zstdlib::GzipReader documentation for a description.
|
4007
4021
|
*/
|
4008
4022
|
static VALUE
|
4009
4023
|
rb_gzreader_ungetbyte(VALUE obj, VALUE ch)
|
@@ -4201,9 +4215,9 @@ gzreader_gets(int argc, VALUE *argv, VALUE obj)
|
|
4201
4215
|
}
|
4202
4216
|
|
4203
4217
|
/*
|
4204
|
-
* Document-method:
|
4218
|
+
* Document-method: Zstdlib::GzipReader#gets
|
4205
4219
|
*
|
4206
|
-
* See
|
4220
|
+
* See Zstdlib::GzipReader documentation for a description.
|
4207
4221
|
*/
|
4208
4222
|
static VALUE
|
4209
4223
|
rb_gzreader_gets(int argc, VALUE *argv, VALUE obj)
|
@@ -4217,9 +4231,9 @@ rb_gzreader_gets(int argc, VALUE *argv, VALUE obj)
|
|
4217
4231
|
}
|
4218
4232
|
|
4219
4233
|
/*
|
4220
|
-
* Document-method:
|
4234
|
+
* Document-method: Zstdlib::GzipReader#readline
|
4221
4235
|
*
|
4222
|
-
* See
|
4236
|
+
* See Zstdlib::GzipReader documentation for a description.
|
4223
4237
|
*/
|
4224
4238
|
static VALUE
|
4225
4239
|
rb_gzreader_readline(int argc, VALUE *argv, VALUE obj)
|
@@ -4233,9 +4247,9 @@ rb_gzreader_readline(int argc, VALUE *argv, VALUE obj)
|
|
4233
4247
|
}
|
4234
4248
|
|
4235
4249
|
/*
|
4236
|
-
* Document-method:
|
4250
|
+
* Document-method: Zstdlib::GzipReader#each
|
4237
4251
|
*
|
4238
|
-
* See
|
4252
|
+
* See Zstdlib::GzipReader documentation for a description.
|
4239
4253
|
*/
|
4240
4254
|
static VALUE
|
4241
4255
|
rb_gzreader_each(int argc, VALUE *argv, VALUE obj)
|
@@ -4251,23 +4265,23 @@ rb_gzreader_each(int argc, VALUE *argv, VALUE obj)
|
|
4251
4265
|
}
|
4252
4266
|
|
4253
4267
|
/*
|
4254
|
-
* Document-method:
|
4268
|
+
* Document-method: Zstdlib::GzipReader#lines
|
4255
4269
|
*
|
4256
4270
|
* This is a deprecated alias for <code>each_line</code>.
|
4257
4271
|
*/
|
4258
4272
|
static VALUE
|
4259
4273
|
rb_gzreader_lines(int argc, VALUE *argv, VALUE obj)
|
4260
4274
|
{
|
4261
|
-
rb_warn("
|
4275
|
+
rb_warn("Zstdlib::GzipReader#lines is deprecated; use #each_line instead");
|
4262
4276
|
if (!rb_block_given_p())
|
4263
4277
|
return rb_enumeratorize(obj, ID2SYM(rb_intern("each_line")), argc, argv);
|
4264
4278
|
return rb_gzreader_each(argc, argv, obj);
|
4265
4279
|
}
|
4266
4280
|
|
4267
4281
|
/*
|
4268
|
-
* Document-method:
|
4282
|
+
* Document-method: Zstdlib::GzipReader#readlines
|
4269
4283
|
*
|
4270
|
-
* See
|
4284
|
+
* See Zstdlib::GzipReader documentation for a description.
|
4271
4285
|
*/
|
4272
4286
|
static VALUE
|
4273
4287
|
rb_gzreader_readlines(int argc, VALUE *argv, VALUE obj)
|
@@ -4281,9 +4295,9 @@ rb_gzreader_readlines(int argc, VALUE *argv, VALUE obj)
|
|
4281
4295
|
}
|
4282
4296
|
|
4283
4297
|
/*
|
4284
|
-
* Document-method:
|
4298
|
+
* Document-method: Zstdlib::GzipReader#external_encoding
|
4285
4299
|
*
|
4286
|
-
* See
|
4300
|
+
* See Zstdlib::GzipReader documentation for a description.
|
4287
4301
|
*/
|
4288
4302
|
static VALUE
|
4289
4303
|
rb_gzreader_external_encoding(VALUE self)
|
@@ -4315,24 +4329,24 @@ static VALUE zlib_gzip_run(VALUE arg);
|
|
4315
4329
|
|
4316
4330
|
/*
|
4317
4331
|
* call-seq:
|
4318
|
-
*
|
4332
|
+
* Zstdlib.gzip(src, level: nil, strategy: nil) -> String
|
4319
4333
|
*
|
4320
4334
|
* Gzip the given +string+. Valid values of level are
|
4321
|
-
*
|
4322
|
-
*
|
4335
|
+
* Zstdlib::NO_COMPRESSION, Zstdlib::BEST_SPEED, Zstdlib::BEST_COMPRESSION,
|
4336
|
+
* Zstdlib::DEFAULT_COMPRESSION (default), or an integer from 0 to 9.
|
4323
4337
|
*
|
4324
4338
|
* This method is almost equivalent to the following code:
|
4325
4339
|
*
|
4326
4340
|
* def gzip(string, level: nil, strategy: nil)
|
4327
4341
|
* sio = StringIO.new
|
4328
4342
|
* sio.binmode
|
4329
|
-
* gz =
|
4343
|
+
* gz = Zstdlib::GzipWriter.new(sio, level, strategy)
|
4330
4344
|
* gz.write(string)
|
4331
4345
|
* gz.close
|
4332
4346
|
* sio.string
|
4333
4347
|
* end
|
4334
4348
|
*
|
4335
|
-
* See also
|
4349
|
+
* See also Zstdlib.gunzip
|
4336
4350
|
*
|
4337
4351
|
*/
|
4338
4352
|
static VALUE
|
@@ -4402,7 +4416,7 @@ static VALUE zlib_gunzip_run(VALUE arg);
|
|
4402
4416
|
|
4403
4417
|
/*
|
4404
4418
|
* call-seq:
|
4405
|
-
*
|
4419
|
+
* Zstdlib.gunzip(src) -> String
|
4406
4420
|
*
|
4407
4421
|
* Decode the given gzipped +string+.
|
4408
4422
|
*
|
@@ -4410,13 +4424,13 @@ static VALUE zlib_gunzip_run(VALUE arg);
|
|
4410
4424
|
*
|
4411
4425
|
* def gunzip(string)
|
4412
4426
|
* sio = StringIO.new(string)
|
4413
|
-
* gz =
|
4427
|
+
* gz = Zstdlib::GzipReader.new(sio, encoding: Encoding::ASCII_8BIT)
|
4414
4428
|
* gz.read
|
4415
4429
|
* ensure
|
4416
4430
|
* gz&.close
|
4417
4431
|
* end
|
4418
4432
|
*
|
4419
|
-
* See also
|
4433
|
+
* See also Zstdlib.gzip
|
4420
4434
|
*/
|
4421
4435
|
static VALUE
|
4422
4436
|
zlib_gunzip(VALUE klass, VALUE src)
|
@@ -4460,7 +4474,7 @@ zlib_gunzip_run(VALUE arg)
|
|
4460
4474
|
#endif /* GZIP_SUPPORT */
|
4461
4475
|
|
4462
4476
|
void
|
4463
|
-
|
4477
|
+
Init_zstdlib(void)
|
4464
4478
|
{
|
4465
4479
|
#undef rb_intern
|
4466
4480
|
VALUE mZlib, cZStream, cDeflate, cInflate;
|
@@ -4468,7 +4482,7 @@ Init_zlib(void)
|
|
4468
4482
|
VALUE cGzipFile, cGzipWriter, cGzipReader;
|
4469
4483
|
#endif
|
4470
4484
|
|
4471
|
-
mZlib = rb_define_module("
|
4485
|
+
mZlib = rb_define_module("Zstdlib");
|
4472
4486
|
|
4473
4487
|
id_dictionaries = rb_intern("@dictionaries");
|
4474
4488
|
|
@@ -4492,6 +4506,8 @@ Init_zlib(void)
|
|
4492
4506
|
rb_define_const(mZlib, "VERSION", rb_str_new2(RUBY_ZLIB_VERSION));
|
4493
4507
|
/* The string which represents the version of zlib.h */
|
4494
4508
|
rb_define_const(mZlib, "ZLIB_VERSION", rb_str_new2(ZLIB_VERSION));
|
4509
|
+
rb_define_const(mZlib, "ZSTD_VERSION", rb_str_new2(ZSTD_versionString()));
|
4510
|
+
rb_define_module_function(mZlib, "zstd_version", rb_zstd_version, 0);
|
4495
4511
|
|
4496
4512
|
cZStream = rb_define_class_under(mZlib, "ZStream", rb_cObject);
|
4497
4513
|
rb_undef_alloc_func(cZStream);
|
@@ -4515,7 +4531,7 @@ Init_zlib(void)
|
|
4515
4531
|
|
4516
4532
|
/* Represents binary data as guessed by deflate.
|
4517
4533
|
*
|
4518
|
-
* See
|
4534
|
+
* See Zstdlib::Deflate#data_type. */
|
4519
4535
|
rb_define_const(mZlib, "BINARY", INT2FIX(Z_BINARY));
|
4520
4536
|
|
4521
4537
|
/* Represents text data as guessed by deflate.
|
@@ -4523,19 +4539,19 @@ Init_zlib(void)
|
|
4523
4539
|
* NOTE: The underlying constant Z_ASCII was deprecated in favor of Z_TEXT
|
4524
4540
|
* in zlib 1.2.2. New applications should not use this constant.
|
4525
4541
|
*
|
4526
|
-
* See
|
4542
|
+
* See Zstdlib::Deflate#data_type. */
|
4527
4543
|
rb_define_const(mZlib, "ASCII", INT2FIX(Z_ASCII));
|
4528
4544
|
|
4529
4545
|
#ifdef Z_TEXT
|
4530
4546
|
/* Represents text data as guessed by deflate.
|
4531
4547
|
*
|
4532
|
-
* See
|
4548
|
+
* See Zstdlib::Deflate#data_type. */
|
4533
4549
|
rb_define_const(mZlib, "TEXT", INT2FIX(Z_TEXT));
|
4534
4550
|
#endif
|
4535
4551
|
|
4536
4552
|
/* Represents an unknown data type as guessed by deflate.
|
4537
4553
|
*
|
4538
|
-
* See
|
4554
|
+
* See Zstdlib::Deflate#data_type. */
|
4539
4555
|
rb_define_const(mZlib, "UNKNOWN", INT2FIX(Z_UNKNOWN));
|
4540
4556
|
|
4541
4557
|
cDeflate = rb_define_class_under(mZlib, "Deflate", cZStream);
|
@@ -4569,12 +4585,12 @@ Init_zlib(void)
|
|
4569
4585
|
/* Fastest compression level, but with the lowest space savings. */
|
4570
4586
|
rb_define_const(mZlib, "BEST_SPEED", INT2FIX(Z_BEST_SPEED));
|
4571
4587
|
/* Slowest compression level, but with the best space savings. */
|
4572
|
-
rb_define_const(mZlib, "BEST_COMPRESSION", INT2FIX(
|
4588
|
+
rb_define_const(mZlib, "BEST_COMPRESSION", INT2FIX(ZSTD_maxCLevel()));
|
4573
4589
|
/* Default compression level which is a good trade-off between space and
|
4574
4590
|
* time
|
4575
4591
|
*/
|
4576
4592
|
rb_define_const(mZlib, "DEFAULT_COMPRESSION",
|
4577
|
-
INT2FIX(
|
4593
|
+
INT2FIX(ZSTD_CLEVEL_DEFAULT));
|
4578
4594
|
|
4579
4595
|
/* Deflate strategy for data produced by a filter (or predictor). The
|
4580
4596
|
* effect of FILTERED is to force more Huffman codes and less string
|
@@ -4605,7 +4621,7 @@ Init_zlib(void)
|
|
4605
4621
|
rb_define_const(mZlib, "DEFAULT_STRATEGY", INT2FIX(Z_DEFAULT_STRATEGY));
|
4606
4622
|
|
4607
4623
|
/* The maximum size of the zlib history buffer. Note that zlib allows
|
4608
|
-
* larger values to enable different inflate modes. See
|
4624
|
+
* larger values to enable different inflate modes. See Zstdlib::Inflate.new
|
4609
4625
|
* for details.
|
4610
4626
|
*/
|
4611
4627
|
rb_define_const(mZlib, "MAX_WBITS", INT2FIX(MAX_WBITS));
|
@@ -4772,28 +4788,28 @@ Init_zlib(void)
|
|
4772
4788
|
/* Document error classes. */
|
4773
4789
|
|
4774
4790
|
/*
|
4775
|
-
* Document-class:
|
4791
|
+
* Document-class: Zstdlib::Error
|
4776
4792
|
*
|
4777
4793
|
* The superclass for all exceptions raised by Ruby/zlib.
|
4778
4794
|
*
|
4779
|
-
* The following exceptions are defined as subclasses of
|
4795
|
+
* The following exceptions are defined as subclasses of Zstdlib::Error. These
|
4780
4796
|
* exceptions are raised when zlib library functions return with an error
|
4781
4797
|
* status.
|
4782
4798
|
*
|
4783
|
-
* -
|
4784
|
-
* -
|
4785
|
-
* -
|
4786
|
-
* -
|
4787
|
-
* -
|
4788
|
-
* -
|
4789
|
-
* -
|
4799
|
+
* - Zstdlib::StreamEnd
|
4800
|
+
* - Zstdlib::NeedDict
|
4801
|
+
* - Zstdlib::DataError
|
4802
|
+
* - Zstdlib::StreamError
|
4803
|
+
* - Zstdlib::MemError
|
4804
|
+
* - Zstdlib::BufError
|
4805
|
+
* - Zstdlib::VersionError
|
4790
4806
|
*
|
4791
4807
|
*/
|
4792
4808
|
|
4793
4809
|
/*
|
4794
|
-
* Document-class:
|
4810
|
+
* Document-class: Zstdlib::StreamEnd
|
4795
4811
|
*
|
4796
|
-
* Subclass of
|
4812
|
+
* Subclass of Zstdlib::Error
|
4797
4813
|
*
|
4798
4814
|
* When zlib returns a Z_STREAM_END
|
4799
4815
|
* is return if the end of the compressed data has been reached
|
@@ -4802,20 +4818,20 @@ Init_zlib(void)
|
|
4802
4818
|
*/
|
4803
4819
|
|
4804
4820
|
/*
|
4805
|
-
* Document-class:
|
4821
|
+
* Document-class: Zstdlib::NeedDict
|
4806
4822
|
*
|
4807
|
-
* Subclass of
|
4823
|
+
* Subclass of Zstdlib::Error
|
4808
4824
|
*
|
4809
4825
|
* When zlib returns a Z_NEED_DICT
|
4810
4826
|
* if a preset dictionary is needed at this point.
|
4811
4827
|
*
|
4812
|
-
* Used by
|
4828
|
+
* Used by Zstdlib::Inflate.inflate and <tt>Zstdlib.inflate</tt>
|
4813
4829
|
*/
|
4814
4830
|
|
4815
4831
|
/*
|
4816
|
-
* Document-class:
|
4832
|
+
* Document-class: Zstdlib::VersionError
|
4817
4833
|
*
|
4818
|
-
* Subclass of
|
4834
|
+
* Subclass of Zstdlib::Error
|
4819
4835
|
*
|
4820
4836
|
* When zlib returns a Z_VERSION_ERROR,
|
4821
4837
|
* usually if the zlib library version is incompatible with the
|
@@ -4824,9 +4840,9 @@ Init_zlib(void)
|
|
4824
4840
|
*/
|
4825
4841
|
|
4826
4842
|
/*
|
4827
|
-
* Document-class:
|
4843
|
+
* Document-class: Zstdlib::MemError
|
4828
4844
|
*
|
4829
|
-
* Subclass of
|
4845
|
+
* Subclass of Zstdlib::Error
|
4830
4846
|
*
|
4831
4847
|
* When zlib returns a Z_MEM_ERROR,
|
4832
4848
|
* usually if there was not enough memory.
|
@@ -4834,9 +4850,9 @@ Init_zlib(void)
|
|
4834
4850
|
*/
|
4835
4851
|
|
4836
4852
|
/*
|
4837
|
-
* Document-class:
|
4853
|
+
* Document-class: Zstdlib::StreamError
|
4838
4854
|
*
|
4839
|
-
* Subclass of
|
4855
|
+
* Subclass of Zstdlib::Error
|
4840
4856
|
*
|
4841
4857
|
* When zlib returns a Z_STREAM_ERROR,
|
4842
4858
|
* usually if the stream state was inconsistent.
|
@@ -4844,44 +4860,44 @@ Init_zlib(void)
|
|
4844
4860
|
*/
|
4845
4861
|
|
4846
4862
|
/*
|
4847
|
-
* Document-class:
|
4863
|
+
* Document-class: Zstdlib::BufError
|
4848
4864
|
*
|
4849
|
-
* Subclass of
|
4865
|
+
* Subclass of Zstdlib::Error when zlib returns a Z_BUF_ERROR.
|
4850
4866
|
*
|
4851
4867
|
* Usually if no progress is possible.
|
4852
4868
|
*
|
4853
4869
|
*/
|
4854
4870
|
|
4855
4871
|
/*
|
4856
|
-
* Document-class:
|
4872
|
+
* Document-class: Zstdlib::DataError
|
4857
4873
|
*
|
4858
|
-
* Subclass of
|
4874
|
+
* Subclass of Zstdlib::Error when zlib returns a Z_DATA_ERROR.
|
4859
4875
|
*
|
4860
4876
|
* Usually if a stream was prematurely freed.
|
4861
4877
|
*
|
4862
4878
|
*/
|
4863
4879
|
|
4864
4880
|
/*
|
4865
|
-
* Document-class:
|
4881
|
+
* Document-class: Zstdlib::GzipFile::Error
|
4866
4882
|
*
|
4867
4883
|
* Base class of errors that occur when processing GZIP files.
|
4868
4884
|
*/
|
4869
4885
|
|
4870
4886
|
/*
|
4871
|
-
* Document-class:
|
4887
|
+
* Document-class: Zstdlib::GzipFile::NoFooter
|
4872
4888
|
*
|
4873
4889
|
* Raised when gzip file footer is not found.
|
4874
4890
|
*/
|
4875
4891
|
|
4876
4892
|
/*
|
4877
|
-
* Document-class:
|
4893
|
+
* Document-class: Zstdlib::GzipFile::CRCError
|
4878
4894
|
*
|
4879
4895
|
* Raised when the CRC checksum recorded in gzip file footer is not equivalent
|
4880
4896
|
* to the CRC checksum of the actual uncompressed data.
|
4881
4897
|
*/
|
4882
4898
|
|
4883
4899
|
/*
|
4884
|
-
* Document-class:
|
4900
|
+
* Document-class: Zstdlib::GzipFile::LengthError
|
4885
4901
|
*
|
4886
4902
|
* Raised when the data length recorded in the gzip file footer is not equivalent
|
4887
4903
|
* to the length of the actual uncompressed data.
|