zlib 2.1.1 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/{LICENSE.txt → BSDL} +3 -3
- data/COPYING +56 -0
- data/README.md +1 -1
- data/ext/zlib/extconf.rb +11 -4
- data/ext/zlib/zlib.c +340 -211
- data/zlib.gemspec +2 -2
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92e21e7d156e0a92bfb671d2c63ce8773f14faa73376b134d2b50619ee0d5cf1
|
4
|
+
data.tar.gz: 4dbf1207f8e6bfde47c7c7ad3e6e4fb34ac925ab6aa46c801b5f6260c1a81031
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d651705b95865f99bc0b47efb06a2b8bbd0154c63dc905c7e21733ce1ce244489eb67925bd83dd48eb9b7f8a8fd1cd3622b2a73159e33d8d51c9f78ae5f723e
|
7
|
+
data.tar.gz: 22166bec315ebd5c069c6c32bd451bc8af24d90904d9051b78c867a839617b5a49133e9dd25afa6e357bb321a3ac46e4b2dec307f7835ec7b094a7d0d6782dfe
|
data/{LICENSE.txt → BSDL}
RENAMED
@@ -4,10 +4,10 @@ Redistribution and use in source and binary forms, with or without
|
|
4
4
|
modification, are permitted provided that the following conditions
|
5
5
|
are met:
|
6
6
|
1. Redistributions of source code must retain the above copyright
|
7
|
-
notice, this list of conditions and the following disclaimer.
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
8
|
2. Redistributions in binary form must reproduce the above copyright
|
9
|
-
notice, this list of conditions and the following disclaimer in the
|
10
|
-
documentation and/or other materials provided with the distribution.
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
11
|
|
12
12
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
13
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
data/COPYING
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
|
2
|
+
You can redistribute it and/or modify it under either the terms of the
|
3
|
+
2-clause BSDL (see the file BSDL), or the conditions below:
|
4
|
+
|
5
|
+
1. You may make and give away verbatim copies of the source form of the
|
6
|
+
software without restriction, provided that you duplicate all of the
|
7
|
+
original copyright notices and associated disclaimers.
|
8
|
+
|
9
|
+
2. You may modify your copy of the software in any way, provided that
|
10
|
+
you do at least ONE of the following:
|
11
|
+
|
12
|
+
a. place your modifications in the Public Domain or otherwise
|
13
|
+
make them Freely Available, such as by posting said
|
14
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
15
|
+
the author to include your modifications in the software.
|
16
|
+
|
17
|
+
b. use the modified software only within your corporation or
|
18
|
+
organization.
|
19
|
+
|
20
|
+
c. give non-standard binaries non-standard names, with
|
21
|
+
instructions on where to get the original software distribution.
|
22
|
+
|
23
|
+
d. make other distribution arrangements with the author.
|
24
|
+
|
25
|
+
3. You may distribute the software in object code or binary form,
|
26
|
+
provided that you do at least ONE of the following:
|
27
|
+
|
28
|
+
a. distribute the binaries and library files of the software,
|
29
|
+
together with instructions (in the manual page or equivalent)
|
30
|
+
on where to get the original distribution.
|
31
|
+
|
32
|
+
b. accompany the distribution with the machine-readable source of
|
33
|
+
the software.
|
34
|
+
|
35
|
+
c. give non-standard binaries non-standard names, with
|
36
|
+
instructions on where to get the original software distribution.
|
37
|
+
|
38
|
+
d. make other distribution arrangements with the author.
|
39
|
+
|
40
|
+
4. You may modify and include the part of the software into any other
|
41
|
+
software (possibly commercial). But some files in the distribution
|
42
|
+
are not written by the author, so that they are not under these terms.
|
43
|
+
|
44
|
+
For the list of those files and their copying conditions, see the
|
45
|
+
file LEGAL.
|
46
|
+
|
47
|
+
5. The scripts and library files supplied as input to or produced as
|
48
|
+
output from the software do not automatically fall under the
|
49
|
+
copyright of the software, but belong to whomever generated them,
|
50
|
+
and may be sold commercially, and may be aggregated with this
|
51
|
+
software.
|
52
|
+
|
53
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
54
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
55
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
56
|
+
PURPOSE.
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ puts "Uncompressed data is: #{uncompressed_data}"
|
|
53
53
|
|
54
54
|
## Development
|
55
55
|
|
56
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake compile test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
57
57
|
|
58
58
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
59
59
|
|
data/ext/zlib/extconf.rb
CHANGED
@@ -11,10 +11,9 @@ require 'rbconfig'
|
|
11
11
|
dir_config 'zlib'
|
12
12
|
|
13
13
|
libs = $libs
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
else
|
14
|
+
have_zlib = %w'z libz zlib1 zlib zdll zlibwapi'.any? {|z| have_library(z, 'deflateReset(NULL)', 'zlib.h')}
|
15
|
+
|
16
|
+
unless have_zlib
|
18
17
|
$libs = libs
|
19
18
|
unless File.directory?(zsrc = "#{$srcdir}/zlib")
|
20
19
|
dirs = Dir.open($srcdir) {|z| z.grep(/\Azlib-\d+[.\d]*\z/) {|x|"#{$srcdir}/#{x}"}}
|
@@ -121,10 +120,18 @@ if have_zlib
|
|
121
120
|
$defs << "-DHAVE_CRC32_COMBINE"
|
122
121
|
$defs << "-DHAVE_ADLER32_COMBINE"
|
123
122
|
$defs << "-DHAVE_TYPE_Z_CRC_T"
|
123
|
+
$defs << "-DHAVE_CRC32_Z"
|
124
|
+
$defs << "-DHAVE_ADLER32_Z"
|
125
|
+
$defs << "-DHAVE_ZLIB_SIZE_T_FUNCS"
|
124
126
|
else
|
125
127
|
have_func('crc32_combine', 'zlib.h')
|
126
128
|
have_func('adler32_combine', 'zlib.h')
|
127
129
|
have_type('z_crc_t', 'zlib.h')
|
130
|
+
if (have_type('z_size_t', 'zlib.h') &&
|
131
|
+
have_func('crc32_z', 'zlib.h') &&
|
132
|
+
have_func('adler32_z', 'zlib.h'))
|
133
|
+
$defs << "-DHAVE_ZLIB_SIZE_T_FUNCS"
|
134
|
+
end
|
128
135
|
end
|
129
136
|
|
130
137
|
create_makefile('zlib') {|conf|
|
data/ext/zlib/zlib.c
CHANGED
@@ -25,7 +25,7 @@
|
|
25
25
|
# define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0
|
26
26
|
#endif
|
27
27
|
|
28
|
-
#define RUBY_ZLIB_VERSION "2.1
|
28
|
+
#define RUBY_ZLIB_VERSION "3.2.1"
|
29
29
|
|
30
30
|
#ifndef RB_PASS_CALLED_KEYWORDS
|
31
31
|
# define rb_class_new_instance_kw(argc, argv, klass, kw_splat) rb_class_new_instance(argc, argv, klass)
|
@@ -44,6 +44,14 @@
|
|
44
44
|
#endif
|
45
45
|
#endif
|
46
46
|
|
47
|
+
#if defined(HAVE_ZLIB_SIZE_T_FUNCS)
|
48
|
+
typedef uLong (*checksum_func)(uLong, const Bytef*, z_size_t);
|
49
|
+
# define crc32 crc32_z
|
50
|
+
# define adler32 adler32_z
|
51
|
+
#else
|
52
|
+
typedef uLong (*checksum_func)(uLong, const Bytef*, uInt);
|
53
|
+
#endif
|
54
|
+
|
47
55
|
#if SIZEOF_LONG > SIZEOF_INT
|
48
56
|
static inline uInt
|
49
57
|
max_uint(long n)
|
@@ -65,7 +73,7 @@ static ID id_dictionaries, id_read, id_buffer;
|
|
65
73
|
|
66
74
|
static NORETURN(void raise_zlib_error(int, const char*));
|
67
75
|
static VALUE rb_zlib_version(VALUE);
|
68
|
-
static VALUE do_checksum(int, VALUE*,
|
76
|
+
static VALUE do_checksum(int, VALUE*, checksum_func);
|
69
77
|
static VALUE rb_zlib_adler32(int, VALUE*, VALUE);
|
70
78
|
static VALUE rb_zlib_crc32(int, VALUE*, VALUE);
|
71
79
|
static VALUE rb_zlib_crc_table(VALUE);
|
@@ -82,7 +90,7 @@ static void zstream_expand_buffer_into(struct zstream*, unsigned long);
|
|
82
90
|
static int zstream_expand_buffer_non_stream(struct zstream *z);
|
83
91
|
static void zstream_append_buffer(struct zstream*, const Bytef*, long);
|
84
92
|
static VALUE zstream_detach_buffer(struct zstream*);
|
85
|
-
static VALUE zstream_shift_buffer(struct zstream*, long);
|
93
|
+
static VALUE zstream_shift_buffer(struct zstream*, long, VALUE);
|
86
94
|
static void zstream_buffer_ungets(struct zstream*, const Bytef*, unsigned long);
|
87
95
|
static void zstream_buffer_ungetbyte(struct zstream*, int);
|
88
96
|
static void zstream_append_input(struct zstream*, const Bytef*, long);
|
@@ -162,8 +170,8 @@ static void gzfile_check_footer(struct gzfile*, VALUE outbuf);
|
|
162
170
|
static void gzfile_write(struct gzfile*, Bytef*, long);
|
163
171
|
static long gzfile_read_more(struct gzfile*, VALUE outbuf);
|
164
172
|
static void gzfile_calc_crc(struct gzfile*, VALUE);
|
165
|
-
static VALUE gzfile_read(struct gzfile*, long);
|
166
|
-
static VALUE gzfile_read_all(struct gzfile
|
173
|
+
static VALUE gzfile_read(struct gzfile*, long, VALUE);
|
174
|
+
static VALUE gzfile_read_all(struct gzfile*, VALUE);
|
167
175
|
static void gzfile_ungets(struct gzfile*, const Bytef*, long);
|
168
176
|
static void gzfile_ungetbyte(struct gzfile*, int);
|
169
177
|
static VALUE gzfile_writer_end_run(VALUE);
|
@@ -288,6 +296,7 @@ static VALUE rb_gzreader_readlines(int, VALUE*, VALUE);
|
|
288
296
|
* - Zlib::MemError
|
289
297
|
* - Zlib::BufError
|
290
298
|
* - Zlib::VersionError
|
299
|
+
* - Zlib::InProgressError
|
291
300
|
*
|
292
301
|
* (if you have GZIP_SUPPORT)
|
293
302
|
* - Zlib::GzipReader
|
@@ -304,7 +313,7 @@ void Init_zlib(void);
|
|
304
313
|
/*--------- Exceptions --------*/
|
305
314
|
|
306
315
|
static VALUE cZError, cStreamEnd, cNeedDict;
|
307
|
-
static VALUE cStreamError, cDataError, cMemError, cBufError, cVersionError;
|
316
|
+
static VALUE cStreamError, cDataError, cMemError, cBufError, cVersionError, cInProgressError;
|
308
317
|
|
309
318
|
static void
|
310
319
|
raise_zlib_error(int err, const char *msg)
|
@@ -373,26 +382,32 @@ rb_zlib_version(VALUE klass)
|
|
373
382
|
return rb_str_new2(zlibVersion());
|
374
383
|
}
|
375
384
|
|
376
|
-
#if SIZEOF_LONG >
|
385
|
+
#if SIZEOF_LONG * CHAR_BIT > 32
|
386
|
+
# define mask32(x) ((x) & 0xffffffff)
|
387
|
+
#else
|
388
|
+
# define mask32(x) (x)
|
389
|
+
#endif
|
390
|
+
|
391
|
+
#if SIZEOF_LONG > SIZEOF_INT && !defined(HAVE_ZLIB_SIZE_T_FUNCS)
|
377
392
|
static uLong
|
378
393
|
checksum_long(uLong (*func)(uLong, const Bytef*, uInt), uLong sum, const Bytef *ptr, long len)
|
379
394
|
{
|
380
395
|
if (len > UINT_MAX) {
|
381
396
|
do {
|
382
|
-
sum = func(sum, ptr, UINT_MAX);
|
397
|
+
sum = func(mask32(sum), ptr, UINT_MAX);
|
383
398
|
ptr += UINT_MAX;
|
384
399
|
len -= UINT_MAX;
|
385
400
|
} while (len >= UINT_MAX);
|
386
401
|
}
|
387
|
-
if (len > 0) sum = func(sum, ptr, (uInt)len);
|
402
|
+
if (len > 0) sum = func(mask32(sum), ptr, (uInt)len);
|
388
403
|
return sum;
|
389
404
|
}
|
390
405
|
#else
|
391
|
-
#define checksum_long(func, sum, ptr, len) (func)((sum), (ptr), (len))
|
406
|
+
#define checksum_long(func, sum, ptr, len) (func)(mask32(sum), (ptr), (len))
|
392
407
|
#endif
|
393
408
|
|
394
409
|
static VALUE
|
395
|
-
do_checksum(int argc, VALUE *argv,
|
410
|
+
do_checksum(int argc, VALUE *argv, checksum_func func)
|
396
411
|
{
|
397
412
|
VALUE str, vsum;
|
398
413
|
unsigned long sum;
|
@@ -410,7 +425,7 @@ do_checksum(int argc, VALUE *argv, uLong (*func)(uLong, const Bytef*, uInt))
|
|
410
425
|
}
|
411
426
|
|
412
427
|
if (NIL_P(str)) {
|
413
|
-
sum = func(sum, Z_NULL, 0);
|
428
|
+
sum = func(mask32(sum), Z_NULL, 0);
|
414
429
|
}
|
415
430
|
else if (rb_obj_is_kind_of(str, rb_cIO)) {
|
416
431
|
VALUE buf;
|
@@ -460,7 +475,7 @@ rb_zlib_adler32(int argc, VALUE *argv, VALUE klass)
|
|
460
475
|
*
|
461
476
|
* call-seq: Zlib.adler32_combine(adler1, adler2, len2)
|
462
477
|
*
|
463
|
-
* Combine two Adler-32 check values in to one. +
|
478
|
+
* Combine two Adler-32 check values in to one. +adler1+ is the first Adler-32
|
464
479
|
* value, +adler2+ is the second Adler-32 value. +len2+ is the length of the
|
465
480
|
* string used to generate +adler2+.
|
466
481
|
*
|
@@ -557,14 +572,15 @@ struct zstream {
|
|
557
572
|
} *func;
|
558
573
|
};
|
559
574
|
|
560
|
-
#define ZSTREAM_FLAG_READY
|
561
|
-
#define ZSTREAM_FLAG_IN_STREAM
|
562
|
-
#define ZSTREAM_FLAG_FINISHED
|
563
|
-
#define ZSTREAM_FLAG_CLOSING
|
564
|
-
#define ZSTREAM_FLAG_GZFILE
|
575
|
+
#define ZSTREAM_FLAG_READY (1 << 0)
|
576
|
+
#define ZSTREAM_FLAG_IN_STREAM (1 << 1)
|
577
|
+
#define ZSTREAM_FLAG_FINISHED (1 << 2)
|
578
|
+
#define ZSTREAM_FLAG_CLOSING (1 << 3)
|
579
|
+
#define ZSTREAM_FLAG_GZFILE (1 << 4) /* disallows yield from expand_buffer for
|
565
580
|
gzip*/
|
566
|
-
#define ZSTREAM_REUSE_BUFFER
|
567
|
-
#define
|
581
|
+
#define ZSTREAM_REUSE_BUFFER (1 << 5)
|
582
|
+
#define ZSTREAM_IN_PROGRESS (1 << 6)
|
583
|
+
#define ZSTREAM_FLAG_UNUSED (1 << 7)
|
568
584
|
|
569
585
|
#define ZSTREAM_READY(z) ((z)->flags |= ZSTREAM_FLAG_READY)
|
570
586
|
#define ZSTREAM_IS_READY(z) ((z)->flags & ZSTREAM_FLAG_READY)
|
@@ -593,7 +609,9 @@ static const struct zstream_funcs inflate_funcs = {
|
|
593
609
|
};
|
594
610
|
|
595
611
|
struct zstream_run_args {
|
596
|
-
struct zstream * z;
|
612
|
+
struct zstream *const z;
|
613
|
+
Bytef *src;
|
614
|
+
long len;
|
597
615
|
int flush; /* stream flush value for inflate() or deflate() */
|
598
616
|
int interrupt; /* stop processing the stream and return to ruby */
|
599
617
|
int jump_state; /* for buffer expansion block break or exception */
|
@@ -656,9 +674,7 @@ zstream_expand_buffer(struct zstream *z)
|
|
656
674
|
rb_obj_reveal(z->buf, rb_cString);
|
657
675
|
}
|
658
676
|
|
659
|
-
|
660
|
-
rb_protect(rb_yield, z->buf, &state);
|
661
|
-
rb_mutex_lock(z->mutex);
|
677
|
+
rb_protect(rb_yield, z->buf, &state);
|
662
678
|
|
663
679
|
if (ZSTREAM_REUSE_BUFFER_P(z)) {
|
664
680
|
rb_str_modify(z->buf);
|
@@ -702,15 +718,14 @@ zstream_expand_buffer_into(struct zstream *z, unsigned long size)
|
|
702
718
|
}
|
703
719
|
}
|
704
720
|
|
705
|
-
static
|
706
|
-
zstream_expand_buffer_protect(
|
721
|
+
static int
|
722
|
+
zstream_expand_buffer_protect(struct zstream *z)
|
707
723
|
{
|
708
|
-
struct zstream *z = (struct zstream *)ptr;
|
709
724
|
int state = 0;
|
710
725
|
|
711
726
|
rb_protect((VALUE (*)(VALUE))zstream_expand_buffer, (VALUE)z, &state);
|
712
727
|
|
713
|
-
return
|
728
|
+
return state;
|
714
729
|
}
|
715
730
|
|
716
731
|
static int
|
@@ -802,19 +817,31 @@ zstream_detach_buffer(struct zstream *z)
|
|
802
817
|
}
|
803
818
|
|
804
819
|
static VALUE
|
805
|
-
zstream_shift_buffer(struct zstream *z, long len)
|
820
|
+
zstream_shift_buffer(struct zstream *z, long len, VALUE dst)
|
806
821
|
{
|
807
|
-
VALUE dst;
|
808
822
|
char *bufptr;
|
809
823
|
long buflen = ZSTREAM_BUF_FILLED(z);
|
810
824
|
|
811
825
|
if (buflen <= len) {
|
812
|
-
|
826
|
+
if (NIL_P(dst) || (!ZSTREAM_IS_FINISHED(z) && !ZSTREAM_IS_GZFILE(z) &&
|
827
|
+
rb_block_given_p())) {
|
828
|
+
return zstream_detach_buffer(z);
|
829
|
+
} else {
|
830
|
+
bufptr = RSTRING_PTR(z->buf);
|
831
|
+
rb_str_resize(dst, buflen);
|
832
|
+
memcpy(RSTRING_PTR(dst), bufptr, buflen);
|
833
|
+
}
|
834
|
+
buflen = 0;
|
835
|
+
} else {
|
836
|
+
bufptr = RSTRING_PTR(z->buf);
|
837
|
+
if (NIL_P(dst)) {
|
838
|
+
dst = rb_str_new(bufptr, len);
|
839
|
+
} else {
|
840
|
+
rb_str_resize(dst, len);
|
841
|
+
memcpy(RSTRING_PTR(dst), bufptr, len);
|
842
|
+
}
|
843
|
+
buflen -= len;
|
813
844
|
}
|
814
|
-
|
815
|
-
bufptr = RSTRING_PTR(z->buf);
|
816
|
-
dst = rb_str_new(bufptr, len);
|
817
|
-
buflen -= len;
|
818
845
|
memmove(bufptr, bufptr + len, buflen);
|
819
846
|
rb_str_set_len(z->buf, buflen);
|
820
847
|
z->stream.next_out = (Bytef*)RSTRING_END(z->buf);
|
@@ -894,7 +921,6 @@ zstream_discard_input(struct zstream *z, long len)
|
|
894
921
|
}
|
895
922
|
rb_str_resize(z->input, newlen);
|
896
923
|
if (newlen == 0) {
|
897
|
-
rb_gc_force_recycle(z->input);
|
898
924
|
z->input = Qnil;
|
899
925
|
}
|
900
926
|
else {
|
@@ -906,7 +932,7 @@ zstream_discard_input(struct zstream *z, long len)
|
|
906
932
|
z->input = Qnil;
|
907
933
|
}
|
908
934
|
else {
|
909
|
-
z->input =
|
935
|
+
z->input = rb_str_subseq(z->input, len,
|
910
936
|
RSTRING_LEN(z->input) - len);
|
911
937
|
}
|
912
938
|
}
|
@@ -994,57 +1020,14 @@ zstream_ensure_end(VALUE v)
|
|
994
1020
|
}
|
995
1021
|
|
996
1022
|
static void *
|
997
|
-
|
1023
|
+
zstream_run_once(void *_arguments)
|
998
1024
|
{
|
999
|
-
struct zstream_run_args *
|
1000
|
-
|
1001
|
-
struct zstream *z = args->z;
|
1002
|
-
uInt n;
|
1003
|
-
|
1004
|
-
err = Z_OK;
|
1005
|
-
while (!args->interrupt) {
|
1006
|
-
n = z->stream.avail_out;
|
1007
|
-
err = z->func->run(&z->stream, flush);
|
1008
|
-
rb_str_set_len(z->buf, ZSTREAM_BUF_FILLED(z) + (n - z->stream.avail_out));
|
1009
|
-
|
1010
|
-
if (err == Z_STREAM_END) {
|
1011
|
-
z->flags &= ~ZSTREAM_FLAG_IN_STREAM;
|
1012
|
-
z->flags |= ZSTREAM_FLAG_FINISHED;
|
1013
|
-
break;
|
1014
|
-
}
|
1025
|
+
struct zstream_run_args *arguments = (struct zstream_run_args *)_arguments;
|
1026
|
+
struct zstream *z = arguments->z;
|
1015
1027
|
|
1016
|
-
|
1017
|
-
break;
|
1018
|
-
|
1019
|
-
if (z->stream.avail_out > 0) {
|
1020
|
-
z->flags |= ZSTREAM_FLAG_IN_STREAM;
|
1021
|
-
break;
|
1022
|
-
}
|
1028
|
+
uintptr_t error = z->func->run(&z->stream, arguments->flush);
|
1023
1029
|
|
1024
|
-
|
1025
|
-
/* break here because inflate() return Z_BUF_ERROR when avail_in == 0. */
|
1026
|
-
/* but deflate() could be called with avail_in == 0 (there's hidden buffer
|
1027
|
-
in zstream->state) */
|
1028
|
-
z->flags |= ZSTREAM_FLAG_IN_STREAM;
|
1029
|
-
break;
|
1030
|
-
}
|
1031
|
-
|
1032
|
-
if (args->stream_output) {
|
1033
|
-
state = (int)(VALUE)rb_thread_call_with_gvl(zstream_expand_buffer_protect,
|
1034
|
-
(void *)z);
|
1035
|
-
}
|
1036
|
-
else {
|
1037
|
-
state = zstream_expand_buffer_non_stream(z);
|
1038
|
-
}
|
1039
|
-
|
1040
|
-
if (state) {
|
1041
|
-
err = Z_OK; /* buffer expanded but stream processing was stopped */
|
1042
|
-
args->jump_state = state;
|
1043
|
-
break;
|
1044
|
-
}
|
1045
|
-
}
|
1046
|
-
|
1047
|
-
return (void *)(VALUE)err;
|
1030
|
+
return (void*)error;
|
1048
1031
|
}
|
1049
1032
|
|
1050
1033
|
/*
|
@@ -1059,18 +1042,108 @@ zstream_unblock_func(void *ptr)
|
|
1059
1042
|
args->interrupt = 1;
|
1060
1043
|
}
|
1061
1044
|
|
1062
|
-
|
1063
|
-
|
1045
|
+
#ifndef RB_NOGVL_OFFLOAD_SAFE
|
1046
|
+
// Default to no-op if it's not defined:
|
1047
|
+
#define RB_NOGVL_OFFLOAD_SAFE 0
|
1048
|
+
#endif
|
1049
|
+
|
1050
|
+
static VALUE
|
1051
|
+
zstream_run_once_begin(VALUE _arguments)
|
1052
|
+
{
|
1053
|
+
struct zstream_run_args *arguments = (struct zstream_run_args *)_arguments;
|
1054
|
+
struct zstream *z = arguments->z;
|
1055
|
+
|
1056
|
+
rb_str_locktmp(z->buf);
|
1057
|
+
|
1058
|
+
#ifndef RB_NOGVL_UBF_ASYNC_SAFE
|
1059
|
+
return (VALUE)rb_thread_call_without_gvl(zstream_run_once, (void *)arguments, zstream_unblock_func, (void *)arguments);
|
1060
|
+
#else
|
1061
|
+
return (VALUE)rb_nogvl(zstream_run_once, (void *)arguments, zstream_unblock_func, (void *)arguments, RB_NOGVL_UBF_ASYNC_SAFE | RB_NOGVL_OFFLOAD_SAFE);
|
1062
|
+
#endif
|
1063
|
+
}
|
1064
|
+
|
1065
|
+
static VALUE
|
1066
|
+
zstream_run_once_ensure(VALUE _arguments)
|
1067
|
+
{
|
1068
|
+
struct zstream_run_args *arguments = (struct zstream_run_args *)_arguments;
|
1069
|
+
struct zstream *z = arguments->z;
|
1070
|
+
|
1071
|
+
rb_str_unlocktmp(z->buf);
|
1072
|
+
|
1073
|
+
return Qnil;
|
1074
|
+
}
|
1075
|
+
|
1076
|
+
static int
|
1077
|
+
zstream_run_func(struct zstream_run_args *args)
|
1078
|
+
{
|
1079
|
+
struct zstream *z = args->z;
|
1080
|
+
int state;
|
1081
|
+
uInt n;
|
1082
|
+
|
1083
|
+
int err = Z_OK;
|
1084
|
+
while (!args->interrupt) {
|
1085
|
+
n = z->stream.avail_out;
|
1086
|
+
|
1087
|
+
err = (int)(VALUE)rb_ensure(zstream_run_once_begin, (VALUE)args, zstream_run_once_ensure, (VALUE)args);
|
1088
|
+
|
1089
|
+
rb_str_set_len(z->buf, ZSTREAM_BUF_FILLED(z) + (n - z->stream.avail_out));
|
1090
|
+
|
1091
|
+
if (err == Z_STREAM_END) {
|
1092
|
+
z->flags &= ~ZSTREAM_FLAG_IN_STREAM;
|
1093
|
+
z->flags |= ZSTREAM_FLAG_FINISHED;
|
1094
|
+
break;
|
1095
|
+
}
|
1096
|
+
|
1097
|
+
if (err != Z_OK && err != Z_BUF_ERROR)
|
1098
|
+
break;
|
1099
|
+
|
1100
|
+
if (z->stream.avail_out > 0) {
|
1101
|
+
z->flags |= ZSTREAM_FLAG_IN_STREAM;
|
1102
|
+
break;
|
1103
|
+
}
|
1104
|
+
|
1105
|
+
if (z->stream.avail_in == 0 && z->func == &inflate_funcs) {
|
1106
|
+
/* break here because inflate() return Z_BUF_ERROR when avail_in == 0. */
|
1107
|
+
/* but deflate() could be called with avail_in == 0 (there's hidden buffer
|
1108
|
+
in zstream->state) */
|
1109
|
+
z->flags |= ZSTREAM_FLAG_IN_STREAM;
|
1110
|
+
break;
|
1111
|
+
}
|
1112
|
+
|
1113
|
+
if (args->stream_output) {
|
1114
|
+
state = zstream_expand_buffer_protect(z);
|
1115
|
+
}
|
1116
|
+
else {
|
1117
|
+
state = zstream_expand_buffer_non_stream(z);
|
1118
|
+
}
|
1119
|
+
|
1120
|
+
if (state) {
|
1121
|
+
err = Z_OK; /* buffer expanded but stream processing was stopped */
|
1122
|
+
args->jump_state = state;
|
1123
|
+
break;
|
1124
|
+
}
|
1125
|
+
}
|
1126
|
+
|
1127
|
+
return err;
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
static VALUE
|
1131
|
+
zstream_run_try(VALUE value_arg)
|
1064
1132
|
{
|
1065
|
-
struct zstream_run_args args;
|
1133
|
+
struct zstream_run_args *args = (struct zstream_run_args *)value_arg;
|
1134
|
+
struct zstream *z = args->z;
|
1135
|
+
Bytef *src = args->src;
|
1136
|
+
long len = args->len;
|
1137
|
+
int flush = args->flush;
|
1138
|
+
|
1066
1139
|
int err;
|
1067
1140
|
VALUE old_input = Qnil;
|
1068
1141
|
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1142
|
+
/* Cannot start zstream while it is in progress. */
|
1143
|
+
if (z->flags & ZSTREAM_IN_PROGRESS) {
|
1144
|
+
rb_raise(cInProgressError, "zlib stream is in progress");
|
1145
|
+
}
|
1146
|
+
z->flags |= ZSTREAM_IN_PROGRESS;
|
1074
1147
|
|
1075
1148
|
if (NIL_P(z->input) && len == 0) {
|
1076
1149
|
z->stream.next_in = (Bytef*)"";
|
@@ -1092,18 +1165,11 @@ zstream_run0(struct zstream *z, Bytef *src, long len, int flush)
|
|
1092
1165
|
}
|
1093
1166
|
|
1094
1167
|
loop:
|
1095
|
-
|
1096
|
-
err = (int)(VALUE)rb_thread_call_without_gvl(zstream_run_func, (void *)&args,
|
1097
|
-
zstream_unblock_func, (void *)&args);
|
1098
|
-
#else
|
1099
|
-
err = (int)(VALUE)rb_nogvl(zstream_run_func, (void *)&args,
|
1100
|
-
zstream_unblock_func, (void *)&args,
|
1101
|
-
RB_NOGVL_UBF_ASYNC_SAFE);
|
1102
|
-
#endif
|
1168
|
+
err = zstream_run_func(args);
|
1103
1169
|
|
1104
1170
|
/* retry if no exception is thrown */
|
1105
|
-
if (err == Z_OK && args
|
1106
|
-
args
|
1171
|
+
if (err == Z_OK && args->interrupt) {
|
1172
|
+
args->interrupt = 0;
|
1107
1173
|
goto loop;
|
1108
1174
|
}
|
1109
1175
|
|
@@ -1137,37 +1203,39 @@ loop:
|
|
1137
1203
|
}
|
1138
1204
|
if (!NIL_P(old_input)) {
|
1139
1205
|
rb_str_resize(old_input, 0);
|
1140
|
-
rb_gc_force_recycle(old_input);
|
1141
1206
|
}
|
1142
1207
|
|
1143
|
-
|
1144
|
-
rb_jump_tag(args.jump_state);
|
1208
|
+
return Qnil;
|
1145
1209
|
}
|
1146
1210
|
|
1147
|
-
struct zstream_run_synchronized_args {
|
1148
|
-
struct zstream *z;
|
1149
|
-
Bytef *src;
|
1150
|
-
long len;
|
1151
|
-
int flush;
|
1152
|
-
};
|
1153
|
-
|
1154
1211
|
static VALUE
|
1155
|
-
|
1212
|
+
zstream_run_ensure(VALUE value_arg)
|
1156
1213
|
{
|
1157
|
-
struct
|
1158
|
-
|
1214
|
+
struct zstream_run_args *args = (struct zstream_run_args *)value_arg;
|
1215
|
+
struct zstream *z = args->z;
|
1216
|
+
|
1217
|
+
/* Remove ZSTREAM_IN_PROGRESS flag to signal that this zstream is not in use. */
|
1218
|
+
z->flags &= ~ZSTREAM_IN_PROGRESS;
|
1219
|
+
|
1159
1220
|
return Qnil;
|
1160
1221
|
}
|
1161
1222
|
|
1162
1223
|
static void
|
1163
1224
|
zstream_run(struct zstream *z, Bytef *src, long len, int flush)
|
1164
1225
|
{
|
1165
|
-
struct
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1226
|
+
struct zstream_run_args args = {
|
1227
|
+
.z = z,
|
1228
|
+
.src = src,
|
1229
|
+
.len = len,
|
1230
|
+
.flush = flush,
|
1231
|
+
.interrupt = 0,
|
1232
|
+
.jump_state = 0,
|
1233
|
+
.stream_output = !ZSTREAM_IS_GZFILE(z) && rb_block_given_p(),
|
1234
|
+
};
|
1235
|
+
|
1236
|
+
rb_ensure(zstream_run_try, (VALUE)&args, zstream_run_ensure, (VALUE)&args);
|
1237
|
+
if (args.jump_state)
|
1238
|
+
rb_jump_tag(args.jump_state);
|
1171
1239
|
}
|
1172
1240
|
|
1173
1241
|
static VALUE
|
@@ -1476,7 +1544,7 @@ rb_zstream_total_out(VALUE obj)
|
|
1476
1544
|
}
|
1477
1545
|
|
1478
1546
|
/*
|
1479
|
-
* Guesses the type of the data which have been
|
1547
|
+
* Guesses the type of the data which have been inputted into the stream. The
|
1480
1548
|
* returned value is either <tt>BINARY</tt>, <tt>ASCII</tt>, or
|
1481
1549
|
* <tt>UNKNOWN</tt>.
|
1482
1550
|
*/
|
@@ -1733,6 +1801,22 @@ do_deflate(struct zstream *z, VALUE src, int flush)
|
|
1733
1801
|
}
|
1734
1802
|
}
|
1735
1803
|
|
1804
|
+
struct rb_zlib_deflate_arguments {
|
1805
|
+
struct zstream *z;
|
1806
|
+
VALUE src;
|
1807
|
+
int flush;
|
1808
|
+
};
|
1809
|
+
|
1810
|
+
static VALUE
|
1811
|
+
rb_deflate_deflate_body(VALUE args)
|
1812
|
+
{
|
1813
|
+
struct rb_zlib_deflate_arguments *arguments = (struct rb_zlib_deflate_arguments *)args;
|
1814
|
+
|
1815
|
+
do_deflate(arguments->z, arguments->src, arguments->flush);
|
1816
|
+
|
1817
|
+
return zstream_detach_buffer(arguments->z);
|
1818
|
+
}
|
1819
|
+
|
1736
1820
|
/*
|
1737
1821
|
* Document-method: Zlib::Deflate#deflate
|
1738
1822
|
*
|
@@ -1764,11 +1848,10 @@ rb_deflate_deflate(int argc, VALUE *argv, VALUE obj)
|
|
1764
1848
|
{
|
1765
1849
|
struct zstream *z = get_zstream(obj);
|
1766
1850
|
VALUE src, flush;
|
1767
|
-
|
1768
1851
|
rb_scan_args(argc, argv, "11", &src, &flush);
|
1769
|
-
|
1852
|
+
struct rb_zlib_deflate_arguments arguments = {z, src, ARG_FLUSH(flush)};
|
1770
1853
|
|
1771
|
-
return
|
1854
|
+
return rb_mutex_synchronize(z->mutex, rb_deflate_deflate_body, (VALUE)&arguments);
|
1772
1855
|
}
|
1773
1856
|
|
1774
1857
|
/*
|
@@ -2064,56 +2147,19 @@ rb_inflate_add_dictionary(VALUE obj, VALUE dictionary)
|
|
2064
2147
|
return obj;
|
2065
2148
|
}
|
2066
2149
|
|
2067
|
-
|
2068
|
-
*
|
2069
|
-
|
2070
|
-
*
|
2071
|
-
|
2072
|
-
|
2073
|
-
*
|
2074
|
-
* Inputs +deflate_string+ into the inflate stream and returns the output from
|
2075
|
-
* the stream. Calling this method, both the input and the output buffer of
|
2076
|
-
* the stream are flushed. If string is +nil+, this method finishes the
|
2077
|
-
* stream, just like Zlib::ZStream#finish.
|
2078
|
-
*
|
2079
|
-
* If a block is given consecutive inflated chunks from the +deflate_string+
|
2080
|
-
* are yielded to the block and +nil+ is returned.
|
2081
|
-
*
|
2082
|
-
* If a :buffer keyword argument is given and not nil:
|
2083
|
-
*
|
2084
|
-
* * The :buffer keyword should be a String, and will used as the output buffer.
|
2085
|
-
* Using this option can reuse the memory required during inflation.
|
2086
|
-
* * When not passing a block, the return value will be the same object as the
|
2087
|
-
* :buffer keyword argument.
|
2088
|
-
* * When passing a block, the yielded chunks will be the same value as the
|
2089
|
-
* :buffer keyword argument.
|
2090
|
-
*
|
2091
|
-
* Raises a Zlib::NeedDict exception if a preset dictionary is needed to
|
2092
|
-
* decompress. Set the dictionary by Zlib::Inflate#set_dictionary and then
|
2093
|
-
* call this method again with an empty string to flush the stream:
|
2094
|
-
*
|
2095
|
-
* inflater = Zlib::Inflate.new
|
2096
|
-
*
|
2097
|
-
* begin
|
2098
|
-
* out = inflater.inflate compressed
|
2099
|
-
* rescue Zlib::NeedDict
|
2100
|
-
* # ensure the dictionary matches the stream's required dictionary
|
2101
|
-
* raise unless inflater.adler == Zlib.adler32(dictionary)
|
2102
|
-
*
|
2103
|
-
* inflater.set_dictionary dictionary
|
2104
|
-
* inflater.inflate ''
|
2105
|
-
* end
|
2106
|
-
*
|
2107
|
-
* # ...
|
2108
|
-
*
|
2109
|
-
* inflater.close
|
2110
|
-
*
|
2111
|
-
* See also Zlib::Inflate.new
|
2112
|
-
*/
|
2150
|
+
struct rb_zlib_inflate_arguments {
|
2151
|
+
struct zstream *z;
|
2152
|
+
int argc;
|
2153
|
+
VALUE *argv;
|
2154
|
+
};
|
2155
|
+
|
2113
2156
|
static VALUE
|
2114
|
-
|
2157
|
+
rb_inflate_inflate_body(VALUE _arguments)
|
2115
2158
|
{
|
2116
|
-
struct
|
2159
|
+
struct rb_zlib_inflate_arguments *arguments = (struct rb_zlib_inflate_arguments*)_arguments;
|
2160
|
+
struct zstream *z = arguments->z;
|
2161
|
+
int argc = arguments->argc;
|
2162
|
+
VALUE *argv = arguments->argv;
|
2117
2163
|
VALUE dst, src, opts, buffer = Qnil;
|
2118
2164
|
|
2119
2165
|
if (OPTHASH_GIVEN_P(opts)) {
|
@@ -2168,6 +2214,60 @@ rb_inflate_inflate(int argc, VALUE* argv, VALUE obj)
|
|
2168
2214
|
return dst;
|
2169
2215
|
}
|
2170
2216
|
|
2217
|
+
/*
|
2218
|
+
* Document-method: Zlib::Inflate#inflate
|
2219
|
+
*
|
2220
|
+
* call-seq:
|
2221
|
+
* inflate(deflate_string, buffer: nil) -> String
|
2222
|
+
* inflate(deflate_string, buffer: nil) { |chunk| ... } -> nil
|
2223
|
+
*
|
2224
|
+
* Inputs +deflate_string+ into the inflate stream and returns the output from
|
2225
|
+
* the stream. Calling this method, both the input and the output buffer of
|
2226
|
+
* the stream are flushed. If string is +nil+, this method finishes the
|
2227
|
+
* stream, just like Zlib::ZStream#finish.
|
2228
|
+
*
|
2229
|
+
* If a block is given consecutive inflated chunks from the +deflate_string+
|
2230
|
+
* are yielded to the block and +nil+ is returned.
|
2231
|
+
*
|
2232
|
+
* If a :buffer keyword argument is given and not nil:
|
2233
|
+
*
|
2234
|
+
* * The :buffer keyword should be a String, and will used as the output buffer.
|
2235
|
+
* Using this option can reuse the memory required during inflation.
|
2236
|
+
* * When not passing a block, the return value will be the same object as the
|
2237
|
+
* :buffer keyword argument.
|
2238
|
+
* * When passing a block, the yielded chunks will be the same value as the
|
2239
|
+
* :buffer keyword argument.
|
2240
|
+
*
|
2241
|
+
* Raises a Zlib::NeedDict exception if a preset dictionary is needed to
|
2242
|
+
* decompress. Set the dictionary by Zlib::Inflate#set_dictionary and then
|
2243
|
+
* call this method again with an empty string to flush the stream:
|
2244
|
+
*
|
2245
|
+
* inflater = Zlib::Inflate.new
|
2246
|
+
*
|
2247
|
+
* begin
|
2248
|
+
* out = inflater.inflate compressed
|
2249
|
+
* rescue Zlib::NeedDict
|
2250
|
+
* # ensure the dictionary matches the stream's required dictionary
|
2251
|
+
* raise unless inflater.adler == Zlib.adler32(dictionary)
|
2252
|
+
*
|
2253
|
+
* inflater.set_dictionary dictionary
|
2254
|
+
* inflater.inflate ''
|
2255
|
+
* end
|
2256
|
+
*
|
2257
|
+
* # ...
|
2258
|
+
*
|
2259
|
+
* inflater.close
|
2260
|
+
*
|
2261
|
+
* See also Zlib::Inflate.new
|
2262
|
+
*/
|
2263
|
+
static VALUE
|
2264
|
+
rb_inflate_inflate(int argc, VALUE* argv, VALUE obj)
|
2265
|
+
{
|
2266
|
+
struct zstream *z = get_zstream(obj);
|
2267
|
+
struct rb_zlib_inflate_arguments arguments = {z, argc, argv};
|
2268
|
+
return rb_mutex_synchronize(z->mutex, rb_inflate_inflate_body, (VALUE)&arguments);
|
2269
|
+
}
|
2270
|
+
|
2171
2271
|
/*
|
2172
2272
|
* call-seq: << string
|
2173
2273
|
*
|
@@ -2841,18 +2941,18 @@ gzfile_newstr(struct gzfile *gz, VALUE str)
|
|
2841
2941
|
}
|
2842
2942
|
|
2843
2943
|
static long
|
2844
|
-
gzfile_fill(struct gzfile *gz, long len)
|
2944
|
+
gzfile_fill(struct gzfile *gz, long len, VALUE outbuf)
|
2845
2945
|
{
|
2846
2946
|
if (len < 0)
|
2847
2947
|
rb_raise(rb_eArgError, "negative length %ld given", len);
|
2848
2948
|
if (len == 0)
|
2849
2949
|
return 0;
|
2850
2950
|
while (!ZSTREAM_IS_FINISHED(&gz->z) && ZSTREAM_BUF_FILLED(&gz->z) < len) {
|
2851
|
-
gzfile_read_more(gz,
|
2951
|
+
gzfile_read_more(gz, outbuf);
|
2852
2952
|
}
|
2853
2953
|
if (GZFILE_IS_FINISHED(gz)) {
|
2854
2954
|
if (!(gz->z.flags & GZFILE_FLAG_FOOTER_FINISHED)) {
|
2855
|
-
gzfile_check_footer(gz,
|
2955
|
+
gzfile_check_footer(gz, outbuf);
|
2856
2956
|
}
|
2857
2957
|
return -1;
|
2858
2958
|
}
|
@@ -2860,14 +2960,27 @@ gzfile_fill(struct gzfile *gz, long len)
|
|
2860
2960
|
}
|
2861
2961
|
|
2862
2962
|
static VALUE
|
2863
|
-
gzfile_read(struct gzfile *gz, long len)
|
2963
|
+
gzfile_read(struct gzfile *gz, long len, VALUE outbuf)
|
2864
2964
|
{
|
2865
2965
|
VALUE dst;
|
2866
2966
|
|
2867
|
-
len = gzfile_fill(gz, len);
|
2868
|
-
|
2869
|
-
if (len < 0)
|
2870
|
-
|
2967
|
+
len = gzfile_fill(gz, len, outbuf);
|
2968
|
+
|
2969
|
+
if (len < 0) {
|
2970
|
+
if (!NIL_P(outbuf))
|
2971
|
+
rb_str_resize(outbuf, 0);
|
2972
|
+
return Qnil;
|
2973
|
+
}
|
2974
|
+
if (len == 0) {
|
2975
|
+
if (NIL_P(outbuf))
|
2976
|
+
return rb_str_new(0, 0);
|
2977
|
+
else {
|
2978
|
+
rb_str_resize(outbuf, 0);
|
2979
|
+
return outbuf;
|
2980
|
+
}
|
2981
|
+
}
|
2982
|
+
|
2983
|
+
dst = zstream_shift_buffer(&gz->z, len, outbuf);
|
2871
2984
|
if (!NIL_P(dst)) gzfile_calc_crc(gz, dst);
|
2872
2985
|
return dst;
|
2873
2986
|
}
|
@@ -2900,31 +3013,26 @@ gzfile_readpartial(struct gzfile *gz, long len, VALUE outbuf)
|
|
2900
3013
|
rb_raise(rb_eEOFError, "end of file reached");
|
2901
3014
|
}
|
2902
3015
|
|
2903
|
-
dst = zstream_shift_buffer(&gz->z, len);
|
3016
|
+
dst = zstream_shift_buffer(&gz->z, len, outbuf);
|
2904
3017
|
gzfile_calc_crc(gz, dst);
|
2905
3018
|
|
2906
|
-
if (!NIL_P(outbuf)) {
|
2907
|
-
rb_str_resize(outbuf, RSTRING_LEN(dst));
|
2908
|
-
memcpy(RSTRING_PTR(outbuf), RSTRING_PTR(dst), RSTRING_LEN(dst));
|
2909
|
-
rb_str_resize(dst, 0);
|
2910
|
-
rb_gc_force_recycle(dst);
|
2911
|
-
dst = outbuf;
|
2912
|
-
}
|
2913
3019
|
return dst;
|
2914
3020
|
}
|
2915
3021
|
|
2916
3022
|
static VALUE
|
2917
|
-
gzfile_read_all(struct gzfile *gz)
|
3023
|
+
gzfile_read_all(struct gzfile *gz, VALUE dst)
|
2918
3024
|
{
|
2919
|
-
VALUE dst;
|
2920
|
-
|
2921
3025
|
while (!ZSTREAM_IS_FINISHED(&gz->z)) {
|
2922
|
-
gzfile_read_more(gz,
|
3026
|
+
gzfile_read_more(gz, dst);
|
2923
3027
|
}
|
2924
3028
|
if (GZFILE_IS_FINISHED(gz)) {
|
2925
3029
|
if (!(gz->z.flags & GZFILE_FLAG_FOOTER_FINISHED)) {
|
2926
|
-
gzfile_check_footer(gz,
|
3030
|
+
gzfile_check_footer(gz, dst);
|
2927
3031
|
}
|
3032
|
+
if (!NIL_P(dst)) {
|
3033
|
+
rb_str_resize(dst, 0);
|
3034
|
+
return dst;
|
3035
|
+
}
|
2928
3036
|
return rb_str_new(0, 0);
|
2929
3037
|
}
|
2930
3038
|
|
@@ -2962,7 +3070,7 @@ gzfile_getc(struct gzfile *gz)
|
|
2962
3070
|
de = (unsigned char *)ds + GZFILE_CBUF_CAPA;
|
2963
3071
|
(void)rb_econv_convert(gz->ec, &sp, se, &dp, de, ECONV_PARTIAL_INPUT|ECONV_AFTER_OUTPUT);
|
2964
3072
|
rb_econv_check_error(gz->ec);
|
2965
|
-
dst = zstream_shift_buffer(&gz->z, sp - ss);
|
3073
|
+
dst = zstream_shift_buffer(&gz->z, sp - ss, Qnil);
|
2966
3074
|
gzfile_calc_crc(gz, dst);
|
2967
3075
|
rb_str_resize(cbuf, dp - ds);
|
2968
3076
|
return cbuf;
|
@@ -2970,7 +3078,7 @@ gzfile_getc(struct gzfile *gz)
|
|
2970
3078
|
else {
|
2971
3079
|
buf = gz->z.buf;
|
2972
3080
|
len = rb_enc_mbclen(RSTRING_PTR(buf), RSTRING_END(buf), gz->enc);
|
2973
|
-
dst = gzfile_read(gz, len);
|
3081
|
+
dst = gzfile_read(gz, len, Qnil);
|
2974
3082
|
if (NIL_P(dst)) return dst;
|
2975
3083
|
return gzfile_newstr(gz, dst);
|
2976
3084
|
}
|
@@ -3469,6 +3577,9 @@ static VALUE
|
|
3469
3577
|
rb_gzfile_eof_p(VALUE obj)
|
3470
3578
|
{
|
3471
3579
|
struct gzfile *gz = get_gzfile(obj);
|
3580
|
+
while (!ZSTREAM_IS_FINISHED(&gz->z) && ZSTREAM_BUF_FILLED(&gz->z) == 0) {
|
3581
|
+
gzfile_read_more(gz, Qnil);
|
3582
|
+
}
|
3472
3583
|
return GZFILE_IS_FINISHED(gz) ? Qtrue : Qfalse;
|
3473
3584
|
}
|
3474
3585
|
|
@@ -3875,7 +3986,7 @@ rb_gzreader_s_zcat(int argc, VALUE *argv, VALUE klass)
|
|
3875
3986
|
if (!buf) {
|
3876
3987
|
buf = rb_str_new(0, 0);
|
3877
3988
|
}
|
3878
|
-
tmpbuf = gzfile_read_all(get_gzfile(obj));
|
3989
|
+
tmpbuf = gzfile_read_all(get_gzfile(obj), Qnil);
|
3879
3990
|
rb_str_cat(buf, RSTRING_PTR(tmpbuf), RSTRING_LEN(tmpbuf));
|
3880
3991
|
}
|
3881
3992
|
|
@@ -3977,19 +4088,19 @@ static VALUE
|
|
3977
4088
|
rb_gzreader_read(int argc, VALUE *argv, VALUE obj)
|
3978
4089
|
{
|
3979
4090
|
struct gzfile *gz = get_gzfile(obj);
|
3980
|
-
VALUE vlen;
|
4091
|
+
VALUE vlen, outbuf;
|
3981
4092
|
long len;
|
3982
4093
|
|
3983
|
-
rb_scan_args(argc, argv, "
|
4094
|
+
rb_scan_args(argc, argv, "02", &vlen, &outbuf);
|
3984
4095
|
if (NIL_P(vlen)) {
|
3985
|
-
return gzfile_read_all(gz);
|
4096
|
+
return gzfile_read_all(gz, outbuf);
|
3986
4097
|
}
|
3987
4098
|
|
3988
4099
|
len = NUM2INT(vlen);
|
3989
4100
|
if (len < 0) {
|
3990
4101
|
rb_raise(rb_eArgError, "negative length %ld given", len);
|
3991
4102
|
}
|
3992
|
-
return gzfile_read(gz, len);
|
4103
|
+
return gzfile_read(gz, len, outbuf);
|
3993
4104
|
}
|
3994
4105
|
|
3995
4106
|
/*
|
@@ -3998,7 +4109,7 @@ rb_gzreader_read(int argc, VALUE *argv, VALUE obj)
|
|
3998
4109
|
* call-seq:
|
3999
4110
|
* gzipreader.readpartial(maxlen [, outbuf]) => string, outbuf
|
4000
4111
|
*
|
4001
|
-
* Reads at most <i>maxlen</i> bytes from the
|
4112
|
+
* Reads at most <i>maxlen</i> bytes from the gzipped stream but
|
4002
4113
|
* it blocks only if <em>gzipreader</em> has no data immediately available.
|
4003
4114
|
* If the optional <i>outbuf</i> argument is present,
|
4004
4115
|
* it must reference a String, which will receive the data.
|
@@ -4062,7 +4173,7 @@ rb_gzreader_getbyte(VALUE obj)
|
|
4062
4173
|
struct gzfile *gz = get_gzfile(obj);
|
4063
4174
|
VALUE dst;
|
4064
4175
|
|
4065
|
-
dst = gzfile_read(gz, 1);
|
4176
|
+
dst = gzfile_read(gz, 1, Qnil);
|
4066
4177
|
if (!NIL_P(dst)) {
|
4067
4178
|
dst = INT2FIX((unsigned int)(RSTRING_PTR(dst)[0]) & 0xff);
|
4068
4179
|
}
|
@@ -4173,6 +4284,7 @@ gzreader_skip_linebreaks(struct gzfile *gz)
|
|
4173
4284
|
while (n++, *(p++) == '\n') {
|
4174
4285
|
if (n >= ZSTREAM_BUF_FILLED(&gz->z)) {
|
4175
4286
|
str = zstream_detach_buffer(&gz->z);
|
4287
|
+
ASSUME(!NIL_P(str));
|
4176
4288
|
gzfile_calc_crc(gz, str);
|
4177
4289
|
while (ZSTREAM_BUF_FILLED(&gz->z) == 0) {
|
4178
4290
|
if (GZFILE_IS_FINISHED(gz)) return;
|
@@ -4183,7 +4295,7 @@ gzreader_skip_linebreaks(struct gzfile *gz)
|
|
4183
4295
|
}
|
4184
4296
|
}
|
4185
4297
|
|
4186
|
-
str = zstream_shift_buffer(&gz->z, n - 1);
|
4298
|
+
str = zstream_shift_buffer(&gz->z, n - 1, Qnil);
|
4187
4299
|
gzfile_calc_crc(gz, str);
|
4188
4300
|
}
|
4189
4301
|
|
@@ -4204,7 +4316,7 @@ gzreader_charboundary(struct gzfile *gz, long n)
|
|
4204
4316
|
if (l < n) {
|
4205
4317
|
int n_bytes = rb_enc_precise_mbclen(p, e, gz->enc);
|
4206
4318
|
if (MBCLEN_NEEDMORE_P(n_bytes)) {
|
4207
|
-
if ((l = gzfile_fill(gz, n + MBCLEN_NEEDMORE_LEN(n_bytes))) > 0) {
|
4319
|
+
if ((l = gzfile_fill(gz, n + MBCLEN_NEEDMORE_LEN(n_bytes), Qnil)) > 0) {
|
4208
4320
|
return l;
|
4209
4321
|
}
|
4210
4322
|
}
|
@@ -4256,10 +4368,10 @@ gzreader_gets(int argc, VALUE *argv, VALUE obj)
|
|
4256
4368
|
|
4257
4369
|
if (NIL_P(rs)) {
|
4258
4370
|
if (limit < 0) {
|
4259
|
-
dst = gzfile_read_all(gz);
|
4371
|
+
dst = gzfile_read_all(gz, Qnil);
|
4260
4372
|
if (RSTRING_LEN(dst) == 0) return Qnil;
|
4261
4373
|
}
|
4262
|
-
else if ((n = gzfile_fill(gz, limit)) <= 0) {
|
4374
|
+
else if ((n = gzfile_fill(gz, limit, Qnil)) <= 0) {
|
4263
4375
|
return Qnil;
|
4264
4376
|
}
|
4265
4377
|
else {
|
@@ -4269,7 +4381,7 @@ gzreader_gets(int argc, VALUE *argv, VALUE obj)
|
|
4269
4381
|
else {
|
4270
4382
|
n = limit;
|
4271
4383
|
}
|
4272
|
-
dst = zstream_shift_buffer(&gz->z, n);
|
4384
|
+
dst = zstream_shift_buffer(&gz->z, n, Qnil);
|
4273
4385
|
if (NIL_P(dst)) return dst;
|
4274
4386
|
gzfile_calc_crc(gz, dst);
|
4275
4387
|
dst = gzfile_newstr(gz, dst);
|
@@ -4296,7 +4408,7 @@ gzreader_gets(int argc, VALUE *argv, VALUE obj)
|
|
4296
4408
|
while (ZSTREAM_BUF_FILLED(&gz->z) < rslen) {
|
4297
4409
|
if (ZSTREAM_IS_FINISHED(&gz->z)) {
|
4298
4410
|
if (ZSTREAM_BUF_FILLED(&gz->z) > 0) gz->lineno++;
|
4299
|
-
return gzfile_read(gz, rslen);
|
4411
|
+
return gzfile_read(gz, rslen, Qnil);
|
4300
4412
|
}
|
4301
4413
|
gzfile_read_more(gz, Qnil);
|
4302
4414
|
}
|
@@ -4333,7 +4445,7 @@ gzreader_gets(int argc, VALUE *argv, VALUE obj)
|
|
4333
4445
|
}
|
4334
4446
|
|
4335
4447
|
gz->lineno++;
|
4336
|
-
dst = gzfile_read(gz, n);
|
4448
|
+
dst = gzfile_read(gz, n, Qnil);
|
4337
4449
|
if (NIL_P(dst)) return dst;
|
4338
4450
|
if (rspara) {
|
4339
4451
|
gzreader_skip_linebreaks(gz);
|
@@ -4581,6 +4693,7 @@ zlib_gunzip_run(VALUE arg)
|
|
4581
4693
|
|
4582
4694
|
gzfile_read_header(gz, Qnil);
|
4583
4695
|
dst = zstream_detach_buffer(&gz->z);
|
4696
|
+
ASSUME(!NIL_P(dst));
|
4584
4697
|
gzfile_calc_crc(gz, dst);
|
4585
4698
|
if (!ZSTREAM_IS_FINISHED(&gz->z)) {
|
4586
4699
|
rb_raise(cGzError, "unexpected end of file");
|
@@ -4619,6 +4732,7 @@ Init_zlib(void)
|
|
4619
4732
|
cMemError = rb_define_class_under(mZlib, "MemError", cZError);
|
4620
4733
|
cBufError = rb_define_class_under(mZlib, "BufError", cZError);
|
4621
4734
|
cVersionError = rb_define_class_under(mZlib, "VersionError", cZError);
|
4735
|
+
cInProgressError = rb_define_class_under(mZlib, "InProgressError", cZError);
|
4622
4736
|
|
4623
4737
|
rb_define_module_function(mZlib, "zlib_version", rb_zlib_version, 0);
|
4624
4738
|
rb_define_module_function(mZlib, "adler32", rb_zlib_adler32, -1);
|
@@ -4926,6 +5040,7 @@ Init_zlib(void)
|
|
4926
5040
|
* - Zlib::MemError
|
4927
5041
|
* - Zlib::BufError
|
4928
5042
|
* - Zlib::VersionError
|
5043
|
+
* - Zlib::InProgressError
|
4929
5044
|
*
|
4930
5045
|
*/
|
4931
5046
|
|
@@ -5000,6 +5115,20 @@ Init_zlib(void)
|
|
5000
5115
|
*
|
5001
5116
|
*/
|
5002
5117
|
|
5118
|
+
/*
|
5119
|
+
* Document-class: Zlib::InProgressError
|
5120
|
+
*
|
5121
|
+
* Subclass of Zlib::Error. This error is raised when the zlib
|
5122
|
+
* stream is currently in progress.
|
5123
|
+
*
|
5124
|
+
* For example:
|
5125
|
+
*
|
5126
|
+
* inflater = Zlib::Inflate.new
|
5127
|
+
* inflater.inflate(compressed) do
|
5128
|
+
* inflater.inflate(compressed) # Raises Zlib::InProgressError
|
5129
|
+
* end
|
5130
|
+
*/
|
5131
|
+
|
5003
5132
|
/*
|
5004
5133
|
* Document-class: Zlib::GzipFile::Error
|
5005
5134
|
*
|
data/zlib.gemspec
CHANGED
@@ -22,10 +22,10 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.homepage = "https://github.com/ruby/zlib"
|
23
23
|
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
24
24
|
|
25
|
-
spec.files = ["
|
25
|
+
spec.files = ["COPYING", "BSDL", "README.md", "ext/zlib/extconf.rb", "ext/zlib/zlib.c", "zlib.gemspec"]
|
26
26
|
spec.bindir = "exe"
|
27
27
|
spec.executables = []
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
spec.extensions = "ext/zlib/extconf.rb"
|
30
|
-
spec.required_ruby_version = ">= 2.
|
30
|
+
spec.required_ruby_version = ">= 2.5.0"
|
31
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1
|
4
|
+
version: 3.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yukihiro Matsumoto
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby interface for the zlib compression/decompression library
|
15
15
|
email:
|
@@ -20,7 +20,8 @@ extensions:
|
|
20
20
|
- ext/zlib/extconf.rb
|
21
21
|
extra_rdoc_files: []
|
22
22
|
files:
|
23
|
-
-
|
23
|
+
- BSDL
|
24
|
+
- COPYING
|
24
25
|
- README.md
|
25
26
|
- ext/zlib/extconf.rb
|
26
27
|
- ext/zlib/zlib.c
|
@@ -38,14 +39,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
39
|
requirements:
|
39
40
|
- - ">="
|
40
41
|
- !ruby/object:Gem::Version
|
41
|
-
version: 2.
|
42
|
+
version: 2.5.0
|
42
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
44
|
requirements:
|
44
45
|
- - ">="
|
45
46
|
- !ruby/object:Gem::Version
|
46
47
|
version: '0'
|
47
48
|
requirements: []
|
48
|
-
rubygems_version: 3.
|
49
|
+
rubygems_version: 3.5.11
|
49
50
|
signing_key:
|
50
51
|
specification_version: 4
|
51
52
|
summary: Ruby interface for the zlib compression/decompression library
|