15 #ifdef HAVE_VALGRIND_MEMCHECK_H 16 # include <valgrind/memcheck.h> 17 # ifndef VALGRIND_MAKE_MEM_DEFINED 18 # define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE((p), (n)) 20 # ifndef VALGRIND_MAKE_MEM_UNDEFINED 21 # define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE((p), (n)) 24 # define VALGRIND_MAKE_MEM_DEFINED(p, n) 0 25 # define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0 28 #define RUBY_ZLIB_VERSION "0.6.0" 31 #define GZIP_SUPPORT 1 36 #if MAX_MEM_LEVEL >= 8 37 #define DEF_MEM_LEVEL 8 39 #define DEF_MEM_LEVEL MAX_MEM_LEVEL 43 #if SIZEOF_LONG > SIZEOF_INT 47 if (n > UINT_MAX) n = UINT_MAX;
50 #define MAX_UINT(n) max_uint(n) 52 #define MAX_UINT(n) (uInt)(n) 55 static ID id_dictionaries;
59 static NORETURN(
void raise_zlib_error(
int,
const char*));
61 static VALUE do_checksum(
int,
VALUE*, uLong (*)(uLong,
const Bytef*, uInt));
65 static voidpf zlib_mem_alloc(voidpf, uInt, uInt);
66 static void zlib_mem_free(voidpf, voidpf);
67 static void finalizer_warn(
const char*);
72 static void zstream_init(
struct zstream*,
const struct zstream_funcs*);
73 static void zstream_expand_buffer(
struct zstream*);
74 static void zstream_expand_buffer_into(
struct zstream*,
unsigned long);
75 static int zstream_expand_buffer_non_stream(
struct zstream *
z);
76 static void zstream_append_buffer(
struct zstream*,
const Bytef*,
long);
78 static VALUE zstream_shift_buffer(
struct zstream*,
long);
79 static void zstream_buffer_ungets(
struct zstream*,
const Bytef*,
unsigned long);
80 static void zstream_buffer_ungetbyte(
struct zstream*,
int);
81 static void zstream_append_input(
struct zstream*,
const Bytef*,
long);
82 static void zstream_discard_input(
struct zstream*,
long);
83 static void zstream_reset_input(
struct zstream*);
84 static void zstream_passthrough_input(
struct zstream*);
86 static void zstream_reset(
struct zstream*);
88 static void zstream_run(
struct zstream*, Bytef*,
long,
int);
89 static VALUE zstream_sync(
struct zstream*, Bytef*,
long);
90 static void zstream_mark(
void*);
91 static void zstream_free(
void*);
92 static VALUE zstream_new(
VALUE,
const struct zstream_funcs*);
94 static void zstream_finalize(
struct zstream*);
100 static VALUE rb_zstream_flush_next_out(
VALUE);
136 static void gzfile_mark(
void*);
137 static void gzfile_free(
void*);
138 static VALUE gzfile_new(
VALUE,
const struct zstream_funcs*,
void (*)
_((
struct gzfile*)));
139 static void gzfile_reset(
struct gzfile*);
140 static void gzfile_close(
struct gzfile*,
int);
141 static void gzfile_write_raw(
struct gzfile*);
145 static int gzfile_read_raw_ensure(
struct gzfile*,
long);
146 static char *gzfile_read_raw_until_zero(
struct gzfile*,
long);
147 static unsigned int gzfile_get16(
const unsigned char*);
148 static unsigned long gzfile_get32(
const unsigned char*);
149 static void gzfile_set32(
unsigned long n,
unsigned char*);
150 static void gzfile_make_header(
struct gzfile*);
151 static void gzfile_make_footer(
struct gzfile*);
152 static void gzfile_read_header(
struct gzfile*);
153 static void gzfile_check_footer(
struct gzfile*);
154 static void gzfile_write(
struct gzfile*, Bytef*,
long);
155 static long gzfile_read_more(
struct gzfile*);
156 static void gzfile_calc_crc(
struct gzfile*,
VALUE);
159 static void gzfile_ungets(
struct gzfile*,
const Bytef*,
long);
160 static void gzfile_ungetbyte(
struct gzfile*,
int);
162 static void gzfile_writer_end(
struct gzfile*);
164 static void gzfile_reader_end(
struct gzfile*);
165 static void gzfile_reader_rewind(
struct gzfile*);
166 static VALUE gzfile_reader_get_unused(
struct gzfile*);
214 static void gzreader_skip_linebreaks(
struct gzfile*);
298 static VALUE cZError, cStreamEnd, cNeedDict;
299 static VALUE cStreamError, cDataError, cMemError, cBufError, cVersionError;
302 raise_zlib_error(
int err,
const char *msg)
326 case Z_VERSION_ERROR:
337 rb_sprintf(
"unknown zlib error %d: %s", err, msg));
347 finalizer_warn(
const char *msg)
349 fprintf(stderr,
"zlib(finalizer): %s\n", msg);
361 rb_zlib_version(
VALUE klass)
370 #if SIZEOF_LONG > SIZEOF_INT 372 checksum_long(uLong (*func)(uLong,
const Bytef*, uInt), uLong sum,
const Bytef *ptr,
long len)
374 if (len > UINT_MAX) {
376 sum = func(sum, ptr, UINT_MAX);
379 }
while (len >= UINT_MAX);
381 if (len > 0) sum = func(sum, ptr, (uInt)len);
385 #define checksum_long(func, sum, ptr, len) (func)((sum), (ptr), (len)) 389 do_checksum(
int argc,
VALUE *
argv, uLong (*func)(uLong,
const Bytef*, uInt))
399 else if (
NIL_P(str)) {
403 sum = func(0, Z_NULL, 0);
407 sum = func(sum, Z_NULL, 0);
435 rb_zlib_adler32(
int argc,
VALUE *argv,
VALUE klass)
437 return do_checksum(argc, argv, adler32);
440 #ifdef HAVE_ADLER32_COMBINE 458 #define rb_zlib_adler32_combine rb_f_notimplement 473 rb_zlib_crc32(
int argc,
VALUE *argv,
VALUE klass)
475 return do_checksum(argc, argv, crc32);
478 #ifdef HAVE_CRC32_COMBINE 496 #define rb_zlib_crc32_combine rb_f_notimplement 505 rb_zlib_crc_table(
VALUE obj)
507 #if !defined(HAVE_TYPE_Z_CRC_T) 509 typedef unsigned long z_crc_t;
511 const z_crc_t *crctbl;
515 crctbl = get_crc_table();
518 for (i = 0; i < 256; i++) {
536 int (*
run)(z_streamp, int);
540 #define ZSTREAM_FLAG_READY 0x1 541 #define ZSTREAM_FLAG_IN_STREAM 0x2 542 #define ZSTREAM_FLAG_FINISHED 0x4 543 #define ZSTREAM_FLAG_CLOSING 0x8 544 #define ZSTREAM_FLAG_GZFILE 0x10 546 #define ZSTREAM_FLAG_UNUSED 0x20 548 #define ZSTREAM_READY(z) ((z)->flags |= ZSTREAM_FLAG_READY) 549 #define ZSTREAM_IS_READY(z) ((z)->flags & ZSTREAM_FLAG_READY) 550 #define ZSTREAM_IS_FINISHED(z) ((z)->flags & ZSTREAM_FLAG_FINISHED) 551 #define ZSTREAM_IS_CLOSING(z) ((z)->flags & ZSTREAM_FLAG_CLOSING) 552 #define ZSTREAM_IS_GZFILE(z) ((z)->flags & ZSTREAM_FLAG_GZFILE) 553 #define ZSTREAM_BUF_FILLED(z) (NIL_P((z)->buf) ? 0 : RSTRING_LEN((z)->buf)) 555 #define ZSTREAM_EXPAND_BUFFER_OK 0 559 #define ZSTREAM_INITIAL_BUFSIZE 1024 561 #define ZSTREAM_AVAIL_OUT_STEP_MAX 16384 562 #define ZSTREAM_AVAIL_OUT_STEP_MIN 2048 564 static const struct zstream_funcs deflate_funcs = {
565 deflateReset, deflateEnd, deflate,
568 static const struct zstream_funcs inflate_funcs = {
569 inflateReset, inflateEnd, inflate,
581 zlib_mem_alloc(voidpf opaque, uInt items, uInt
size)
593 zlib_mem_free(voidpf opaque, voidpf address)
599 zstream_init(
struct zstream *z,
const struct zstream_funcs *
func)
604 z->
stream.zalloc = zlib_mem_alloc;
605 z->
stream.zfree = zlib_mem_free;
606 z->
stream.opaque = Z_NULL;
608 z->
stream.next_in = Z_NULL;
610 z->
stream.next_out = Z_NULL;
615 #define zstream_init_deflate(z) zstream_init((z), &deflate_funcs) 616 #define zstream_init_inflate(z) zstream_init((z), &inflate_funcs) 619 zstream_expand_buffer(
struct zstream *z)
646 zstream_expand_buffer_into(z,
651 zstream_expand_buffer_non_stream(z);
656 zstream_expand_buffer_into(
struct zstream *z,
unsigned long size)
666 else if (z->
stream.avail_out != size) {
674 zstream_expand_buffer_protect(
void *ptr)
681 return (
void *)(
VALUE)state;
685 zstream_expand_buffer_non_stream(
struct zstream *z)
708 zstream_append_buffer(
struct zstream *z,
const Bytef *src,
long len)
724 if (z->
stream.avail_out >= (uInt)len) {
725 z->
stream.avail_out -= (uInt)len;
735 #define zstream_append_buffer2(z,v) \ 736 zstream_append_buffer((z),(Bytef*)RSTRING_PTR(v),RSTRING_LEN(v)) 739 zstream_detach_buffer(
struct zstream *z)
773 zstream_shift_buffer(
struct zstream *z,
long len)
780 return zstream_detach_buffer(z);
786 memmove(bufptr, bufptr + len, buflen);
793 z->
stream.avail_out = (uInt)buflen;
799 zstream_buffer_ungets(
struct zstream *z,
const Bytef *b,
unsigned long len)
805 zstream_expand_buffer_into(z, len);
809 memmove(bufptr + len, bufptr, filled);
812 if (z->
stream.avail_out > 0) {
813 if (len > z->
stream.avail_out) len = z->
stream.avail_out;
815 z->
stream.avail_out-=(uInt)len;
820 zstream_buffer_ungetbyte(
struct zstream *z,
int c)
823 zstream_buffer_ungets(z, &cc, 1);
827 zstream_append_input(
struct zstream *z,
const Bytef *src,
long len)
829 if (len <= 0)
return;
841 #define zstream_append_input2(z,v)\ 843 zstream_append_input((z), (Bytef*)RSTRING_PTR(v), RSTRING_LEN(v)) 846 zstream_discard_input(
struct zstream *z,
long len)
858 zstream_reset_input(
struct zstream *z)
864 zstream_passthrough_input(
struct zstream *z)
873 zstream_detach_input(
struct zstream *z)
890 zstream_reset(
struct zstream *z)
896 raise_zlib_error(err, z->
stream.msg);
902 zstream_reset_input(z);
911 rb_warning(
"attempt to close uninitialized zstream; ignored.");
915 rb_warning(
"attempt to close unfinished zstream; reset forced.");
919 zstream_reset_input(z);
922 raise_zlib_error(err, z->
stream.msg);
929 zstream_run_func(
void *ptr)
942 if (err == Z_STREAM_END) {
948 if (err != Z_OK && err != Z_BUF_ERROR)
951 if (z->
stream.avail_out > 0) {
956 if (z->
stream.avail_in == 0 && z->
func == &inflate_funcs) {
969 state = zstream_expand_buffer_non_stream(z);
979 return (
void *)(
VALUE)err;
986 zstream_unblock_func(
void *ptr)
994 zstream_run(
struct zstream *z, Bytef *src,
long len,
int flush)
1007 z->
stream.next_in = (Bytef*)
"";
1011 zstream_append_input(z, src, len);
1020 if (z->
stream.avail_out == 0) {
1021 zstream_expand_buffer(z);
1026 zstream_unblock_func, (
void *)&args);
1028 if (flush != Z_FINISH && err == Z_BUF_ERROR
1029 && z->
stream.avail_out > 0) {
1033 zstream_reset_input(z);
1035 if (err != Z_OK && err != Z_STREAM_END) {
1036 if (z->
stream.avail_in > 0) {
1037 zstream_append_input(z, z->
stream.next_in, z->
stream.avail_in);
1039 if (err == Z_NEED_DICT) {
1045 rb_inflate_set_dictionary(
self, dict);
1050 raise_zlib_error(err, z->
stream.msg);
1053 if (z->
stream.avail_in > 0) {
1054 zstream_append_input(z, z->
stream.next_in, z->
stream.avail_in);
1058 if (args.jump_state)
1063 zstream_sync(
struct zstream *z, Bytef *src,
long len)
1071 err = inflateSync(&z->
stream);
1073 zstream_discard_input(z,
1075 zstream_append_input(z, src, len);
1078 zstream_reset_input(z);
1079 if (err != Z_DATA_ERROR) {
1081 raise_zlib_error(err, z->
stream.msg);
1085 if (len <= 0)
return Qfalse;
1089 err = inflateSync(&z->
stream);
1091 zstream_append_input(z, z->
stream.next_in, z->
stream.avail_in);
1094 if (err != Z_DATA_ERROR) {
1096 raise_zlib_error(err, z->
stream.msg);
1102 zstream_mark(
void *p)
1110 zstream_finalize(
struct zstream *z)
1113 if (err == Z_STREAM_ERROR)
1114 finalizer_warn(
"the stream state was inconsistent.");
1115 if (err == Z_DATA_ERROR)
1116 finalizer_warn(
"the stream was freed prematurely.");
1120 zstream_free(
void *p)
1125 zstream_finalize(z);
1131 zstream_memsize(
const void *p)
1134 return sizeof(
struct zstream);
1139 { zstream_mark, zstream_free, zstream_memsize, },
1144 zstream_new(
VALUE klass,
const struct zstream_funcs *funcs)
1150 zstream_init(z, funcs);
1151 z->
stream.opaque = (voidpf)obj;
1155 #define zstream_deflate_new(klass) zstream_new((klass), &deflate_funcs) 1156 #define zstream_inflate_new(klass) zstream_new((klass), &inflate_funcs) 1159 get_zstream(
VALUE obj)
1165 rb_raise(cZError,
"stream is not ready");
1239 rb_zstream_end(
VALUE obj)
1241 zstream_end(get_zstream(obj));
1250 rb_zstream_reset(
VALUE obj)
1252 zstream_reset(get_zstream(obj));
1266 rb_zstream_finish(
VALUE obj)
1268 struct zstream *z = get_zstream(obj);
1270 zstream_run(z, (Bytef*)
"", 0, Z_FINISH);
1272 return zstream_detach_buffer(z);
1281 rb_zstream_flush_next_in(
VALUE obj)
1287 dst = zstream_detach_input(z);
1302 rb_zstream_flush_next_out(
VALUE obj)
1308 return zstream_detach_buffer(z);
1316 rb_zstream_avail_out(
VALUE obj)
1330 rb_zstream_set_avail_out(
VALUE obj,
VALUE size)
1332 struct zstream *z = get_zstream(obj);
1334 zstream_expand_buffer_into(z,
FIX2INT(size));
1342 rb_zstream_avail_in(
VALUE obj)
1353 rb_zstream_total_in(
VALUE obj)
1362 rb_zstream_total_out(
VALUE obj)
1373 rb_zstream_data_type(
VALUE obj)
1382 rb_zstream_adler(
VALUE obj)
1391 rb_zstream_finished_p(
VALUE obj)
1400 rb_zstream_closed_p(
VALUE obj)
1417 #define FIXNUMARG(val, ifnil) \ 1418 (NIL_P((val)) ? (ifnil) \ 1421 #define ARG_LEVEL(val) FIXNUMARG((val), Z_DEFAULT_COMPRESSION) 1422 #define ARG_WBITS(val) FIXNUMARG((val), MAX_WBITS) 1423 #define ARG_MEMLEVEL(val) FIXNUMARG((val), DEF_MEM_LEVEL) 1424 #define ARG_STRATEGY(val) FIXNUMARG((val), Z_DEFAULT_STRATEGY) 1425 #define ARG_FLUSH(val) FIXNUMARG((val), Z_NO_FLUSH) 1429 rb_deflate_s_allocate(
VALUE klass)
1508 rb_deflate_initialize(
int argc,
VALUE *argv,
VALUE obj)
1514 rb_scan_args(argc, argv,
"04", &level, &wbits, &memlevel, &strategy);
1521 raise_zlib_error(err, z->
stream.msg);
1540 z2 = get_zstream(orig);
1542 if (z1 == z2)
return self;
1545 raise_zlib_error(err, 0);
1555 deflate_run(
VALUE args)
1561 return zstream_detach_buffer(z);
1588 rb_deflate_s_deflate(
int argc,
VALUE *argv,
VALUE klass)
1599 err = deflateInit(&z.
stream, lev);
1601 raise_zlib_error(err, z.
stream.msg);
1605 args[0] = (
VALUE)&z;
1617 zstream_run(z, (Bytef*)
"", 0, Z_FINISH);
1621 if (flush != Z_NO_FLUSH ||
RSTRING_LEN(src) > 0) {
1653 rb_deflate_deflate(
int argc,
VALUE *argv,
VALUE obj)
1655 struct zstream *z = get_zstream(obj);
1662 return zstream_detach_buffer(z);
1678 do_deflate(get_zstream(obj), src, Z_NO_FLUSH);
1698 rb_deflate_flush(
int argc,
VALUE *argv,
VALUE obj)
1700 struct zstream *z = get_zstream(obj);
1705 flush =
FIXNUMARG(v_flush, Z_SYNC_FLUSH);
1706 if (flush != Z_NO_FLUSH) {
1707 zstream_run(z, (Bytef*)
"", 0, flush);
1710 return zstream_detach_buffer(z);
1728 struct zstream *z = get_zstream(obj);
1729 int level, strategy;
1738 err = deflateParams(&z->
stream, level, strategy);
1739 filled = n - z->
stream.avail_out;
1740 while (err == Z_BUF_ERROR) {
1741 rb_warning(
"deflateParams() returned Z_BUF_ERROR");
1742 zstream_expand_buffer(z);
1745 err = deflateParams(&z->
stream, level, strategy);
1746 filled = n - z->
stream.avail_out;
1749 raise_zlib_error(err, z->
stream.msg);
1771 rb_deflate_set_dictionary(
VALUE obj,
VALUE dic)
1773 struct zstream *z = get_zstream(obj);
1779 err = deflateSetDictionary(&z->
stream,
1782 raise_zlib_error(err, z->
stream.msg);
1800 rb_inflate_s_allocate(
VALUE klass)
1853 rb_inflate_initialize(
int argc,
VALUE *argv,
VALUE obj)
1864 raise_zlib_error(err, z->
stream.msg);
1872 inflate_run(
VALUE args)
1878 zstream_run(z, (Bytef*)
"", 0, Z_FINISH);
1879 return zstream_detach_buffer(z);
1914 err = inflateInit(&z.
stream);
1916 raise_zlib_error(err, z.
stream.msg);
1920 args[0] = (
VALUE)&z;
1932 zstream_run(z, (Bytef*)
"", 0, Z_FINISH);
1951 rb_inflate_add_dictionary(
VALUE obj,
VALUE dictionary)
1954 VALUE checksum = do_checksum(1, &dictionary, adler32);
2001 struct zstream *z = get_zstream(obj);
2008 dst = zstream_detach_buffer(z);
2019 dst = zstream_detach_buffer(z);
2021 zstream_passthrough_input(z);
2038 struct zstream *z = get_zstream(obj);
2051 zstream_passthrough_input(z);
2069 struct zstream *z = get_zstream(obj);
2084 rb_inflate_sync_point_p(
VALUE obj)
2086 struct zstream *z = get_zstream(obj);
2089 err = inflateSyncPoint(&z->
stream);
2094 raise_zlib_error(err, z->
stream.msg);
2107 rb_inflate_set_dictionary(
VALUE obj,
VALUE dic)
2109 struct zstream *z = get_zstream(obj);
2115 err = inflateSetDictionary(&z->
stream,
2118 raise_zlib_error(err, z->
stream.msg);
2135 #define GZ_MAGIC1 0x1f 2136 #define GZ_MAGIC2 0x8b 2137 #define GZ_METHOD_DEFLATE 8 2138 #define GZ_FLAG_MULTIPART 0x2 2139 #define GZ_FLAG_EXTRA 0x4 2140 #define GZ_FLAG_ORIG_NAME 0x8 2141 #define GZ_FLAG_COMMENT 0x10 2142 #define GZ_FLAG_ENCRYPT 0x20 2143 #define GZ_FLAG_UNKNOWN_MASK 0xc0 2145 #define GZ_EXTRAFLAG_FAST 0x4 2146 #define GZ_EXTRAFLAG_SLOW 0x2 2149 #define OS_MSDOS 0x00 2150 #define OS_AMIGA 0x01 2152 #define OS_UNIX 0x03 2153 #define OS_ATARI 0x05 2155 #define OS_MACOS 0x07 2156 #define OS_TOPS20 0x0a 2157 #define OS_WIN32 0x0b 2159 #define OS_VMCMS 0x04 2160 #define OS_ZSYSTEM 0x08 2162 #define OS_QDOS 0x0c 2163 #define OS_RISCOS 0x0d 2164 #define OS_UNKNOWN 0xff 2167 #define OS_CODE OS_UNIX 2170 static ID id_write, id_read, id_readpartial, id_flush, id_seek, id_close, id_path, id_input;
2171 static VALUE cGzError, cNoFooter, cCRCError, cLengthError;
2197 #define GZFILE_CBUF_CAPA 10 2199 #define GZFILE_FLAG_SYNC ZSTREAM_FLAG_UNUSED 2200 #define GZFILE_FLAG_HEADER_FINISHED (ZSTREAM_FLAG_UNUSED << 1) 2201 #define GZFILE_FLAG_FOOTER_FINISHED (ZSTREAM_FLAG_UNUSED << 2) 2203 #define GZFILE_IS_FINISHED(gz) \ 2204 (ZSTREAM_IS_FINISHED(&(gz)->z) && ZSTREAM_BUF_FILLED(&(gz)->z) == 0) 2206 #define GZFILE_READ_SIZE 2048 2210 gzfile_mark(
void *p)
2217 zstream_mark(&gz->
z);
2223 gzfile_free(
void *p)
2229 if (z->
func == &deflate_funcs) {
2230 finalizer_warn(
"Zlib::GzipWriter object must be closed explicitly.");
2232 zstream_finalize(z);
2241 gzfile_memsize(
const void *p)
2243 const struct gzfile *gz = p;
2244 size_t size =
sizeof(
struct gzfile);
2254 { gzfile_mark, gzfile_free, gzfile_memsize, },
2255 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
2259 gzfile_init(
struct gzfile *gz,
const struct zstream_funcs *funcs,
void (*endfunc)(
struct gzfile *))
2261 zstream_init(&gz->
z, funcs);
2269 gz->
crc = crc32(0, Z_NULL, 0);
2283 gzfile_new(
VALUE klass,
const struct zstream_funcs *funcs,
void (*endfunc)(
struct gzfile *))
2289 gzfile_init(gz, funcs, endfunc);
2293 #define gzfile_writer_new(gz) gzfile_new((gz),&deflate_funcs,gzfile_writer_end) 2294 #define gzfile_reader_new(gz) gzfile_new((gz),&inflate_funcs,gzfile_reader_end) 2297 gzfile_reset(
struct gzfile *gz)
2299 zstream_reset(&gz->
z);
2301 gz->
crc = crc32(0, Z_NULL, 0);
2312 gzfile_close(
struct gzfile *gz,
int closeflag)
2326 gzfile_write_raw(
struct gzfile *gz)
2331 str = zstream_detach_buffer(&gz->
z);
2341 gzfile_read_raw_partial(
VALUE arg)
2352 gzfile_read_raw_rescue(
VALUE arg)
2366 gzfile_read_raw(
struct gzfile *gz)
2369 gzfile_read_raw_rescue, (
VALUE)gz,
2374 gzfile_read_raw_ensure(
struct gzfile *gz,
long size)
2380 rb_raise(cGzError,
"unexpected end of string");
2383 str = gzfile_read_raw(gz);
2384 if (
NIL_P(str))
return 0;
2391 gzfile_read_raw_until_zero(
struct gzfile *gz,
long offset)
2400 str = gzfile_read_raw(gz);
2402 rb_raise(cGzError,
"unexpected end of file");
2411 gzfile_get16(
const unsigned char *src)
2414 n = *(src++) & 0xff;
2415 n |= (*(src++) & 0xff) << 8;
2419 static unsigned long 2420 gzfile_get32(
const unsigned char *src)
2423 n = *(src++) & 0xff;
2424 n |= (*(src++) & 0xff) << 8;
2425 n |= (*(src++) & 0xff) << 16;
2426 n |= (*(src++) & 0xffU) << 24;
2431 gzfile_set32(
unsigned long n,
unsigned char *dst)
2433 *(dst++) = n & 0xff;
2434 *(dst++) = (n >> 8) & 0xff;
2435 *(dst++) = (n >> 16) & 0xff;
2436 *dst = (n >> 24) & 0xff;
2440 gzfile_raise(
struct gzfile *gz,
VALUE klass,
const char *message)
2455 gzfile_error_inspect(
VALUE error)
2460 if (!
NIL_P(input)) {
2470 gzfile_make_header(
struct gzfile *gz)
2473 unsigned char flags = 0, extraflags = 0;
2481 if (gz->
mtime == 0) {
2482 gz->
mtime = time(0);
2485 if (gz->
level == Z_BEST_SPEED) {
2488 else if (gz->
level == Z_BEST_COMPRESSION) {
2496 gzfile_set32((
unsigned long)gz->
mtime, &buf[4]);
2497 buf[8] = extraflags;
2499 zstream_append_buffer(&gz->
z, buf, (
long)
sizeof(buf));
2503 zstream_append_buffer(&gz->
z, (Bytef*)
"\0", 1);
2507 zstream_append_buffer(&gz->
z, (Bytef*)
"\0", 1);
2514 gzfile_make_footer(
struct gzfile *gz)
2518 gzfile_set32(gz->
crc, buf);
2519 gzfile_set32(gz->
z.
stream.total_in, &buf[4]);
2520 zstream_append_buffer(&gz->
z, buf, (
long)
sizeof(buf));
2525 gzfile_read_header(
struct gzfile *gz)
2527 const unsigned char *head;
2531 if (!gzfile_read_raw_ensure(gz, 10)) {
2532 gzfile_raise(gz, cGzError,
"not in gzip format");
2538 gzfile_raise(gz, cGzError,
"not in gzip format");
2541 rb_raise(cGzError,
"unsupported compression method %d", head[2]);
2546 rb_raise(cGzError,
"multi-part gzip file is not supported");
2549 rb_raise(cGzError,
"encrypted gzip file is not supported");
2552 rb_raise(cGzError,
"unknown flags 0x%02x", flags);
2556 gz->
level = Z_BEST_SPEED;
2559 gz->
level = Z_BEST_COMPRESSION;
2562 gz->
level = Z_DEFAULT_COMPRESSION;
2565 gz->
mtime = gzfile_get32(&head[4]);
2567 zstream_discard_input(&gz->
z, 10);
2570 if (!gzfile_read_raw_ensure(gz, 2)) {
2571 rb_raise(cGzError,
"unexpected end of file");
2574 if (!gzfile_read_raw_ensure(gz, 2 + len)) {
2575 rb_raise(cGzError,
"unexpected end of file");
2577 zstream_discard_input(&gz->
z, 2 + len);
2580 if (!gzfile_read_raw_ensure(gz, 1)) {
2581 rb_raise(cGzError,
"unexpected end of file");
2583 p = gzfile_read_raw_until_zero(gz, 0);
2587 zstream_discard_input(&gz->
z, len + 1);
2590 if (!gzfile_read_raw_ensure(gz, 1)) {
2591 rb_raise(cGzError,
"unexpected end of file");
2593 p = gzfile_read_raw_until_zero(gz, 0);
2597 zstream_discard_input(&gz->
z, len + 1);
2601 zstream_run(&gz->
z, 0, 0, Z_SYNC_FLUSH);
2606 gzfile_check_footer(
struct gzfile *gz)
2608 unsigned long crc, length;
2612 if (!gzfile_read_raw_ensure(gz, 8)) {
2613 gzfile_raise(gz, cNoFooter,
"footer is not found");
2620 zstream_discard_input(&gz->
z, 8);
2622 if (gz->
crc != crc) {
2623 rb_raise(cCRCError,
"invalid compressed data -- crc error");
2626 rb_raise(cLengthError,
"invalid compressed data -- length error");
2631 gzfile_write(
struct gzfile *gz, Bytef *str,
long len)
2634 gzfile_make_header(gz);
2640 ? Z_SYNC_FLUSH : Z_NO_FLUSH);
2642 gzfile_write_raw(gz);
2646 gzfile_read_more(
struct gzfile *gz)
2651 str = gzfile_read_raw(gz);
2654 rb_raise(cGzError,
"unexpected end of file");
2700 gzfile_fill(
struct gzfile *gz,
long len)
2707 gzfile_read_more(gz);
2711 gzfile_check_footer(gz);
2719 gzfile_read(
struct gzfile *gz,
long len)
2723 len = gzfile_fill(gz, len);
2725 if (len < 0)
return Qnil;
2726 dst = zstream_shift_buffer(&gz->
z, len);
2727 if (!
NIL_P(dst)) gzfile_calc_crc(gz, dst);
2732 gzfile_readpartial(
struct gzfile *gz,
long len,
VALUE outbuf)
2751 gzfile_read_more(gz);
2755 gzfile_check_footer(gz);
2762 dst = zstream_shift_buffer(&gz->
z, len);
2763 gzfile_calc_crc(gz, dst);
2765 if (!
NIL_P(outbuf)) {
2776 gzfile_read_all(
struct gzfile *gz)
2781 gzfile_read_more(gz);
2785 gzfile_check_footer(gz);
2790 dst = zstream_detach_buffer(&gz->
z);
2791 if (
NIL_P(dst))
return dst;
2792 gzfile_calc_crc(gz, dst);
2794 return gzfile_newstr(gz, dst);
2798 gzfile_getc(
struct gzfile *gz)
2805 gzfile_read_more(gz);
2809 gzfile_check_footer(gz);
2815 const unsigned char *ss, *sp, *se;
2816 unsigned char *ds, *
dp, *de;
2823 ds = dp = (
unsigned char *)gz->
cbuf;
2827 dst = zstream_shift_buffer(&gz->
z, sp - ss);
2828 gzfile_calc_crc(gz, dst);
2837 dst = gzfile_read(gz, len);
2838 if (
NIL_P(dst))
return dst;
2839 return gzfile_newstr(gz, dst);
2844 gzfile_ungets(
struct gzfile *gz,
const Bytef *b,
long len)
2846 zstream_buffer_ungets(&gz->
z, b, len);
2851 gzfile_ungetbyte(
struct gzfile *gz,
int c)
2853 zstream_buffer_ungetbyte(&gz->
z, c);
2858 gzfile_writer_end_run(
VALUE arg)
2863 gzfile_make_header(gz);
2866 zstream_run(&gz->
z, (Bytef*)
"", 0, Z_FINISH);
2867 gzfile_make_footer(gz);
2868 gzfile_write_raw(gz);
2874 gzfile_writer_end(
struct gzfile *gz)
2883 gzfile_reader_end_run(
VALUE arg)
2889 gzfile_check_footer(gz);
2896 gzfile_reader_end(
struct gzfile *gz)
2905 gzfile_reader_rewind(
struct gzfile *gz)
2919 gzfile_reader_get_unused(
struct gzfile *gz)
2926 gzfile_check_footer(gz);
2936 get_gzfile(
VALUE obj)
2942 rb_raise(cGzError,
"closed gzip stream");
3002 gzfile_ensure_close(
VALUE obj)
3008 gzfile_close(gz, 1);
3014 gzfile_wrap(
int argc,
VALUE *argv,
VALUE klass,
int close_io_on_error)
3018 if (close_io_on_error) {
3058 rb_gzfile_s_wrap(
int argc,
VALUE *argv,
VALUE klass)
3060 return gzfile_wrap(argc, argv, klass, 0);
3069 gzfile_s_open(
int argc,
VALUE *argv,
VALUE klass,
const char *mode)
3077 return gzfile_wrap(argc, argv, klass, 1);
3086 rb_gzfile_to_io(
VALUE obj)
3088 return get_gzfile(obj)->
io;
3097 rb_gzfile_crc(
VALUE obj)
3108 rb_gzfile_mtime(
VALUE obj)
3119 rb_gzfile_level(
VALUE obj)
3130 rb_gzfile_os_code(
VALUE obj)
3142 rb_gzfile_orig_name(
VALUE obj)
3159 rb_gzfile_comment(
VALUE obj)
3175 rb_gzfile_lineno(
VALUE obj)
3188 struct gzfile *gz = get_gzfile(obj);
3215 struct gzfile *gz = get_gzfile(obj);
3219 rb_raise(cGzError,
"header is already written");
3234 rb_gzfile_set_orig_name(
VALUE obj,
VALUE str)
3236 struct gzfile *gz = get_gzfile(obj);
3241 rb_raise(cGzError,
"header is already written");
3260 struct gzfile *gz = get_gzfile(obj);
3265 rb_raise(cGzError,
"header is already written");
3283 rb_gzfile_close(
VALUE obj)
3293 gzfile_close(gz, 1);
3305 rb_gzfile_finish(
VALUE obj)
3307 struct gzfile *gz = get_gzfile(obj);
3311 gzfile_close(gz, 0);
3322 rb_gzfile_closed_p(
VALUE obj)
3335 rb_gzfile_eof_p(
VALUE obj)
3337 struct gzfile *gz = get_gzfile(obj);
3348 rb_gzfile_sync(
VALUE obj)
3365 struct gzfile *gz = get_gzfile(obj);
3382 rb_gzfile_total_in(
VALUE obj)
3393 rb_gzfile_total_out(
VALUE obj)
3395 struct gzfile *gz = get_gzfile(obj);
3396 uLong total_out = gz->
z.
stream.total_out;
3399 if (total_out >= (uLong)buf_filled) {
3402 return LONG2FIX(-(buf_filled - (
long)total_out));
3415 rb_gzfile_path(
VALUE obj)
3472 rb_gzwriter_s_allocate(
VALUE klass)
3485 rb_gzwriter_s_open(
int argc,
VALUE *argv,
VALUE klass)
3487 return gzfile_s_open(argc, argv, klass,
"wb");
3504 rb_gzwriter_initialize(
int argc,
VALUE *argv,
VALUE obj)
3512 if (!
NIL_P(opt)) argc--;
3515 rb_scan_args(argc, argv,
"12", &io, &level, &strategy);
3520 err = deflateInit2(&gz->
z.
stream, gz->
level, Z_DEFLATED,
3523 raise_zlib_error(err, gz->
z.
stream.msg);
3527 rb_gzfile_ecopts(gz, opt);
3545 rb_gzwriter_flush(
int argc,
VALUE *argv,
VALUE obj)
3547 struct gzfile *gz = get_gzfile(obj);
3553 flush =
FIXNUMARG(v_flush, Z_SYNC_FLUSH);
3554 if (flush != Z_NO_FLUSH) {
3555 zstream_run(&gz->
z, (Bytef*)
"", 0, flush);
3558 gzfile_write_raw(gz);
3571 struct gzfile *gz = get_gzfile(obj);
3589 struct gzfile *gz = get_gzfile(obj);
3592 gzfile_write(gz, (Bytef*)&c, 1);
3602 #define rb_gzwriter_addstr rb_io_addstr 3607 #define rb_gzwriter_printf rb_io_printf 3612 #define rb_gzwriter_print rb_io_print 3617 #define rb_gzwriter_puts rb_io_puts 3675 rb_gzreader_s_allocate(
VALUE klass)
3690 rb_gzreader_s_open(
int argc,
VALUE *argv,
VALUE klass)
3692 return gzfile_s_open(argc, argv, klass,
"rb");
3713 rb_gzreader_initialize(
int argc,
VALUE *argv,
VALUE obj)
3723 err = inflateInit2(&gz->
z.
stream, -MAX_WBITS);
3725 raise_zlib_error(err, gz->
z.
stream.msg);
3729 gzfile_read_header(gz);
3730 rb_gzfile_ecopts(gz, opt);
3747 rb_gzreader_rewind(
VALUE obj)
3749 struct gzfile *gz = get_gzfile(obj);
3750 gzfile_reader_rewind(gz);
3761 rb_gzreader_unused(
VALUE obj)
3765 return gzfile_reader_get_unused(gz);
3774 rb_gzreader_read(
int argc,
VALUE *argv,
VALUE obj)
3776 struct gzfile *gz = get_gzfile(obj);
3782 return gzfile_read_all(gz);
3789 return gzfile_read(gz, len);
3805 rb_gzreader_readpartial(
int argc,
VALUE *argv,
VALUE obj)
3807 struct gzfile *gz = get_gzfile(obj);
3819 return gzfile_readpartial(gz, len, outbuf);
3828 rb_gzreader_getc(
VALUE obj)
3830 struct gzfile *gz = get_gzfile(obj);
3832 return gzfile_getc(gz);
3841 rb_gzreader_readchar(
VALUE obj)
3844 dst = rb_gzreader_getc(obj);
3857 rb_gzreader_getbyte(
VALUE obj)
3859 struct gzfile *gz = get_gzfile(obj);
3862 dst = gzfile_read(gz, 1);
3875 rb_gzreader_readbyte(
VALUE obj)
3878 dst = rb_gzreader_getbyte(obj);
3891 rb_gzreader_each_char(
VALUE obj)
3897 while (!
NIL_P(c = rb_gzreader_getc(obj))) {
3909 rb_gzreader_each_byte(
VALUE obj)
3915 while (!
NIL_P(c = rb_gzreader_getbyte(obj))) {
3927 rb_gzreader_bytes(
VALUE obj)
3929 rb_warn(
"Zlib::GzipReader#bytes is deprecated; use #each_byte instead");
3932 return rb_gzreader_each_byte(obj);
3946 return rb_gzreader_ungetbyte(obj, s);
3947 gz = get_gzfile(obj);
3965 struct gzfile *gz = get_gzfile(obj);
3966 gzfile_ungetbyte(gz,
NUM2CHR(ch));
3971 gzreader_skip_linebreaks(
struct gzfile *gz)
3979 gzfile_read_more(gz);
3984 while (n++, *(p++) ==
'\n') {
3986 str = zstream_detach_buffer(&gz->
z);
3987 gzfile_calc_crc(gz, str);
3990 gzfile_read_more(gz);
3997 str = zstream_shift_buffer(&gz->
z, n - 1);
3998 gzfile_calc_crc(gz, str);
4002 rscheck(
const char *rsptr,
long rslen,
VALUE rs)
4009 gzreader_charboundary(
struct gzfile *gz,
long n)
4030 gzreader_gets(
int argc,
VALUE *argv,
VALUE obj)
4032 struct gzfile *gz = get_gzfile(obj);
4037 long rslen, n, limit = -1;
4052 else if (!
NIL_P(rs)) {
4070 dst = gzfile_read_all(gz);
4073 else if ((n = gzfile_fill(gz, limit)) <= 0) {
4078 n = gzreader_charboundary(gz, n);
4083 dst = zstream_shift_buffer(&gz->
z, n);
4084 if (
NIL_P(dst))
return dst;
4085 gzfile_calc_crc(gz, dst);
4086 dst = gzfile_newstr(gz, dst);
4104 gzreader_skip_linebreaks(gz);
4110 return gzfile_read(gz, rslen);
4112 gzfile_read_more(gz);
4121 gzfile_read_more(gz);
4124 if (!rspara) rscheck(rsptr, rslen, rs);
4126 if (limit > 0 && filled >= limit) {
4129 res = memchr(p, rsptr[0], (filled - n + 1));
4132 if (limit > 0 && filled >= limit)
break;
4136 n += (long)(res - p);
4138 if (rslen == 1 ||
memcmp(p, rsptr, rslen) == 0)
break;
4143 n = gzreader_charboundary(gz, n);
4147 dst = gzfile_read(gz, n);
4148 if (
NIL_P(dst))
return dst;
4150 gzreader_skip_linebreaks(gz);
4154 return gzfile_newstr(gz, dst);
4163 rb_gzreader_gets(
int argc,
VALUE *argv,
VALUE obj)
4166 dst = gzreader_gets(argc, argv, obj);
4179 rb_gzreader_readline(
int argc,
VALUE *argv,
VALUE obj)
4182 dst = rb_gzreader_gets(argc, argv, obj);
4195 rb_gzreader_each(
int argc,
VALUE *argv,
VALUE obj)
4201 while (!
NIL_P(str = gzreader_gets(argc, argv, obj))) {
4213 rb_gzreader_lines(
int argc,
VALUE *argv,
VALUE obj)
4215 rb_warn(
"Zlib::GzipReader#lines is deprecated; use #each_line instead");
4218 return rb_gzreader_each(argc, argv, obj);
4227 rb_gzreader_readlines(
int argc,
VALUE *argv,
VALUE obj)
4231 while (!
NIL_P(str = gzreader_gets(argc, argv, obj))) {
4243 rb_gzreader_external_encoding(
VALUE self)
4249 zlib_gzip_ensure(
VALUE arg)
4257 zlib_gzip_end(
struct gzfile *gz)
4260 zstream_run(&gz->
z, (Bytef*)
"", 0, Z_FINISH);
4261 gzfile_make_footer(gz);
4262 zstream_end(&gz->
z);
4265 #define OPTHASH_GIVEN_P(opts) \ 4266 (argc > 0 && !NIL_P((opts) = rb_check_hash_type(argv[argc-1])) && (--argc, 1)) 4267 static ID id_level, id_strategy;
4293 zlib_s_gzip(
int argc,
VALUE *argv,
VALUE klass)
4296 struct gzfile *gz = &gz0;
4303 keyword_ids[0] = id_level;
4304 keyword_ids[1] = id_strategy;
4306 if (kwargs[0] !=
Qundef) {
4309 if (kwargs[1] !=
Qundef) {
4310 strategy = kwargs[1];
4315 gzfile_init(gz, &deflate_funcs, zlib_gzip_end);
4317 err = deflateInit2(&gz->
z.
stream, gz->
level, Z_DEFLATED,
4321 raise_zlib_error(err, gz->
z.
stream.msg);
4324 args[0] = (
VALUE)gz;
4330 zlib_gzip_run(
VALUE arg)
4334 VALUE src = args[1];
4337 gzfile_make_header(gz);
4342 zstream_run(&gz->
z, ptr, len, Z_NO_FLUSH);
4344 gzfile_close(gz, 0);
4345 return zstream_detach_buffer(&gz->
z);
4349 zlib_gunzip_end(
struct gzfile *gz)
4352 zstream_end(&gz->
z);
4379 struct gzfile *gz = &gz0;
4384 gzfile_init(gz, &inflate_funcs, zlib_gunzip_end);
4385 err = inflateInit2(&gz->
z.
stream, -MAX_WBITS);
4387 raise_zlib_error(err, gz->
z.
stream.msg);
4396 zlib_gunzip_run(
VALUE arg)
4401 gzfile_read_header(gz);
4402 dst = zstream_detach_buffer(&gz->
z);
4403 gzfile_calc_crc(gz, dst);
4405 rb_raise(cGzError,
"unexpected end of file");
4408 rb_raise(cNoFooter,
"footer is not found");
4410 gzfile_check_footer(gz);
4419 VALUE mZlib, cZStream, cDeflate, cInflate;
4421 VALUE cGzipFile, cGzipWriter, cGzipReader;
4426 id_dictionaries =
rb_intern(
"@dictionaries");
4467 rb_define_method(cZStream,
"flush_next_out", rb_zstream_flush_next_out, 0);
4504 rb_define_method(cDeflate,
"set_dictionary", rb_deflate_set_dictionary, 1);
4511 rb_define_method(cInflate,
"add_dictionary", rb_inflate_add_dictionary, 1);
4516 rb_define_method(cInflate,
"set_dictionary", rb_inflate_set_dictionary, 1);
4530 INT2FIX(Z_DEFAULT_COMPRESSION));
4601 id_readpartial =
rb_intern(
"readpartial");
4682 rb_define_method(cGzipReader,
"external_encoding", rb_gzreader_external_encoding, 0);
RUBY_EXTERN VALUE rb_cString
#define ZSTREAM_IS_CLOSING(z)
#define MBCLEN_CHARFOUND_P(ret)
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *pstate)
Protects a function call from potential global escapes from the function.
void rb_warn(const char *fmt,...)
#define MBCLEN_CHARFOUND_LEN(ret)
#define RUBY_TYPED_FREE_IMMEDIATELY
void rb_undef_alloc_func(VALUE)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
int rb_block_given_p(void)
Determines if the current method is given a block.
#define zstream_init_inflate(z)
#define ZSTREAM_AVAIL_OUT_STEP_MAX
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_str_cat(VALUE, const char *, long)
void rb_jump_tag(int tag)
Continues the exception caught by rb_protect() and rb_eval_string_protect().
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
#define rb_zlib_adler32_combine
#define TypedData_Get_Struct(obj, type, data_type, sval)
#define GZ_FLAG_ORIG_NAME
int rb_enc_dummy_p(rb_encoding *enc)
void(* end)(struct gzfile *)
int rb_econv_prepare_opts(VALUE opthash, VALUE *ecopts)
void rb_econv_close(rb_econv_t *ec)
VALUE rb_enc_from_encoding(rb_encoding *encoding)
VALUE rb_ary_push(VALUE ary, VALUE item)
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
void rb_str_set_len(VALUE, long)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_ivar_get(VALUE, ID)
#define RSTRING_GETMEM(str, ptrvar, lenvar)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
VALUE rb_exc_new_str(VALUE etype, VALUE str)
VALUE rb_rescue(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2)
An equivalent of rescue clause.
#define GZFILE_FLAG_FOOTER_FINISHED
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE rb_Integer(VALUE)
Equivalent to Kernel#Integer in Ruby.
VALUE rb_check_convert_type(VALUE, int, const char *, const char *)
Tries to convert an object into another type.
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
void rb_include_module(VALUE klass, VALUE module)
void rb_gc_mark(VALUE ptr)
#define GZFILE_IS_FINISHED(gz)
#define GZFILE_FLAG_HEADER_FINISHED
#define ZSTREAM_IS_READY(z)
VALUE rb_file_open_str(VALUE, const char *)
#define ZSTREAM_FLAG_FINISHED
#define rb_enc_mbmaxlen(enc)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
An equivalent to ensure clause.
#define ZSTREAM_FLAG_IN_STREAM
#define ZSTREAM_IS_GZFILE(z)
#define ZSTREAM_FLAG_CLOSING
#define OPTHASH_GIVEN_P(opts)
VALUE rb_rescue2(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2,...)
An equivalent of rescue clause.
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts)
RUBY_EXTERN void * memmove(void *, const void *, size_t)
#define rb_gzwriter_printf
VALUE rb_str_buf_cat(VALUE, const char *, long)
#define ZSTREAM_FLAG_GZFILE
void * xmalloc2(size_t, size_t) RUBY_ATTR_ALLOC_SIZE((1
#define RB_TYPE_P(obj, type)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
call-seq: obj.is_a?(class) -> true or false obj.kind_of?(class) -> true or false
#define gzfile_writer_new(gz)
void rb_econv_check_error(rb_econv_t *ec)
rb_encoding * rb_default_external_encoding(void)
#define ZSTREAM_FLAG_READY
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
VALUE rb_str_substr(VALUE, long, long)
RUBY_EXTERN VALUE rb_cObject
#define checksum_long(func, sum, ptr, len)
#define VALGRIND_MAKE_MEM_DEFINED(p, n)
const struct zstream::zstream_funcs * func
#define MBCLEN_NEEDMORE_P(ret)
VALUE rb_str_cat2(VALUE, const char *)
VALUE rb_obj_as_string(VALUE)
rb_econv_t * rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE ecopts)
#define ECONV_PARTIAL_INPUT
#define ECONV_AFTER_OUTPUT
void rb_define_const(VALUE, const char *, VALUE)
#define GZ_EXTRAFLAG_FAST
#define zstream_deflate_new(klass)
void rb_lastline_set(VALUE)
#define MBCLEN_NEEDMORE_LEN(ret)
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
int(* run)(z_streamp, int)
void * rb_thread_call_without_gvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
VALUE rb_time_new(time_t, long)
#define ZSTREAM_IS_FINISHED(z)
#define ARG_STRATEGY(val)
VALUE rb_str_resurrect(VALUE str)
VALUE rb_str_resize(VALUE, long)
void rb_sys_fail(const char *mesg)
#define rb_zlib_crc32_combine
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p)
VALUE rb_obj_reveal(VALUE obj, VALUE klass)
Make a hidden object visible again.
VALUE rb_sprintf(const char *format,...)
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
#define ZSTREAM_INITIAL_BUFSIZE
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
void rb_str_modify_expand(VALUE, long)
VALUE rb_ivar_set(VALUE, ID, VALUE)
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
#define zstream_append_input2(z, v)
#define GZ_FLAG_MULTIPART
#define rb_gzwriter_print
VALUE rb_call_super(int, const VALUE *)
#define RUBY_ZLIB_VERSION
int memcmp(const void *s1, const void *s2, size_t len)
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
NORETURN(static void gzfile_raise(struct gzfile *, VALUE, const char *))
#define FIXNUMARG(val, ifnil)
int rb_respond_to(VALUE, ID)
register unsigned int len
rb_encoding * rb_enc_get(VALUE obj)
#define UNLIMITED_ARGUMENTS
#define ZSTREAM_AVAIL_OUT_STEP_MIN
rb_econv_result_t rb_econv_convert(rb_econv_t *ec, const unsigned char **source_buffer_ptr, const unsigned char *source_buffer_end, unsigned char **destination_buffer_ptr, unsigned char *destination_buffer_end, int flags)
void rb_define_attr(VALUE klass, const char *name, int read, int write)
Defines (a) public accessor method(s) for an attribute.
RUBY_SYMBOL_EXPORT_BEGIN void * rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
VALUE rb_hash_aref(VALUE hash, VALUE key)
VALUE rb_enumeratorize(VALUE obj, VALUE meth, int argc, const VALUE *argv)
#define ARG_MEMLEVEL(val)
VALUE rb_check_string_type(VALUE)
void rb_warning(const char *fmt,...)
#define gzfile_reader_new(gz)
#define ZSTREAM_BUF_FILLED(z)
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Allocates and initializes an instance of klass.
VALUE rb_uint2inum(VALUE n)
size_t rb_str_capacity(VALUE str)
VALUE rb_errinfo(void)
The current exception in the current thread.
#define TypedData_Make_Struct(klass, type, data_type, sval)
#define rb_enc_left_char_head(s, p, e, enc)
VALUE rb_str_inspect(VALUE)
#define RETURN_ENUMERATOR(obj, argc, argv)
#define rb_gzwriter_addstr
#define GZ_EXTRAFLAG_SLOW
VALUE rb_int2inum(SIGNED_VALUE n)
#define ZSTREAM_EXPAND_BUFFER_OK
rb_encoding * rb_ascii8bit_encoding(void)
#define GZ_METHOD_DEFLATE
#define RSTRING_LENINT(str)
RUBY_EXTERN VALUE rb_eEOFError
#define zstream_init_deflate(z)
VALUE rb_define_module(const char *name)
#define GZ_FLAG_UNKNOWN_MASK
VALUE rb_str_buf_new(long)
#define zstream_append_buffer2(z, v)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_append(VALUE, VALUE)
VALUE rb_str_to_str(VALUE)
#define zstream_inflate_new(klass)
VALUE rb_attr_get(VALUE, ID)
VALUE rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags)
VALUE rb_str_new(const char *, long)