2 * Author : Paul Marquess, <pmqs@cpan.org>
3 * Created : 22nd January 1996
6 * Copyright (c) 1995-2013 Paul Marquess. All rights reserved.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the same terms as Perl itself.
12 /* Parts of this code are based on the files gzio.c and gzappend.c from
13 * the standard zlib source distribution. Below are the copyright statements
17 /* gzio.c -- IO on .gz files
18 * Copyright (C) 1995 Jean-loup Gailly.
19 * For conditions of distribution and use, see copyright notice in zlib.h
22 /* gzappend -- command to append to a gzip file
24 Copyright (C) 2003 Mark Adler, all rights reserved
25 version 1.1, 4 Nov 2003
29 #define PERL_NO_GET_CONTEXT
36 /* zlib prior to 1.06 doesn't know about z_off_t */
41 #if ! defined(ZLIB_VERNUM) || ZLIB_VERNUM < 0x1200
42 # define NEED_DUMMY_BYTE_AT_END
45 #if defined(ZLIB_VERNUM) && ZLIB_VERNUM >= 0x1210
47 # define AT_LEAST_ZLIB_1_2_1
50 #if defined(ZLIB_VERNUM) && ZLIB_VERNUM >= 0x1221
51 # define AT_LEAST_ZLIB_1_2_2_1
54 #if defined(ZLIB_VERNUM) && ZLIB_VERNUM >= 0x1222
55 # define AT_LEAST_ZLIB_1_2_2_2
58 #if defined(ZLIB_VERNUM) && ZLIB_VERNUM >= 0x1223
59 # define AT_LEAST_ZLIB_1_2_2_3
62 #if defined(ZLIB_VERNUM) && ZLIB_VERNUM >= 0x1230
63 # define AT_LEAST_ZLIB_1_2_3
66 #if defined(ZLIB_VERNUM) && ZLIB_VERNUM >= 0x1252
68 Use Z_SOLO to build source means need own malloc/free
70 # define AT_LEAST_ZLIB_1_2_5_2
73 #if defined(ZLIB_VERNUM) && ZLIB_VERNUM >= 0x1280
74 # define AT_LEAST_ZLIB_1_2_8
77 #if defined(ZLIB_VERNUM) && ZLIB_VERNUM >= 0x1290
78 # define AT_LEAST_ZLIB_1_2_9
82 # define NEED_sv_2pvbyte
83 # define NEED_sv_2pv_nolen
84 # define NEED_sv_pvn_force_flags
88 #if PERL_REVISION == 5 && PERL_VERSION == 9
90 # define sv_pvbyte_force(sv,lp) sv_pvbyten_force(sv,lp)
93 #if PERL_REVISION == 5 && (PERL_VERSION < 8 || (PERL_VERSION == 8 && PERL_SUBVERSION < 4 ))
95 # ifdef SvPVbyte_force
96 # undef SvPVbyte_force
99 # define SvPVbyte_force(sv,lp) SvPV_force(sv,lp)
103 #ifndef SvPVbyte_nolen
104 # define SvPVbyte_nolen SvPV_nolen
110 # ifndef SvPVbyte_nolen
111 # define SvPVbyte_nolen SvPV_nolen
114 # ifndef SvPVbyte_force
115 # define SvPVbyte_force(sv,lp) SvPV_force(sv,lp)
119 #if PERL_REVISION == 5 && (PERL_VERSION >= 8 || (PERL_VERSION == 8 && PERL_SUBVERSION < 4 ))
120 # define UTF8_AVAILABLE
123 typedef int DualType ;
124 typedef int int_undef ;
126 typedef struct di_stream {
128 #define FLAG_APPEND 1
130 #define FLAG_ADLER32 4
131 #define FLAG_CONSUME_INPUT 8
132 #define FLAG_LIMIT_OUTPUT 16
141 /* #define SETP_BYTE */
143 /* SETP_BYTE only works with zlib up to 1.2.8 */
144 bool deflateParams_out_valid ;
145 Bytef deflateParams_out_byte;
147 #define deflateParams_BUFFER_SIZE 0x40000
148 uLong deflateParams_out_length;
149 Bytef* deflateParams_out_buffer;
156 uLong bytesInflated ;
157 uLong compressedBytes ;
158 uLong uncompressedBytes ;
161 #define WINDOW_SIZE 32768U
163 bool matchedEndBlock;
165 int window_lastbit, window_left, window_full;
166 unsigned window_have;
167 off_t window_lastoff, window_end;
168 off_t window_endOffset;
170 uLong lastBlockOffset ;
171 unsigned char window_lastByte ;
177 typedef di_stream * deflateStream ;
178 typedef di_stream * Compress__Raw__Zlib__deflateStream ;
179 typedef di_stream * inflateStream ;
180 typedef di_stream * Compress__Raw__Zlib__inflateStream ;
181 typedef di_stream * Compress__Raw__Zlib__inflateScanStream ;
183 #define ZMALLOC(to, typ) ((to = (typ *)safemalloc(sizeof(typ))), \
186 /* Figure out the Operating System */
188 # define OS_CODE 0x00
191 #if defined(AMIGA) || defined(AMIGAOS) || defined(__amigaos4__)
192 # define OS_CODE 0x01
195 #if defined(VAXC) || defined(VMS)
196 # define OS_CODE 0x02
200 # define OS_CODE 0x04
203 #if defined(ATARI) || defined(atarist)
204 # define OS_CODE 0x05
208 # define OS_CODE 0x06
211 #if defined(MACOS) || defined(TARGET_OS_MAC)
212 # define OS_CODE 0x07
216 # define OS_CODE 0x08
220 # define OS_CODE 0x09
224 # define OS_CODE 0x0a
227 #ifdef WIN32 /* Window 95 & Windows NT */
228 # define OS_CODE 0x0b
232 # define OS_CODE 0x0c
235 #if 0 /* Acorn RISCOS */
236 # define OS_CODE 0x0d
240 # define OS_CODE 0x0e
243 #ifdef __50SERIES /* Prime/PRIMOS */
244 # define OS_CODE 0x0F
247 /* Default to UNIX */
249 # define OS_CODE 0x03 /* assume Unix */
253 # define GZIP_OS_CODE OS_CODE
256 #define adlerInitial adler32(0L, Z_NULL, 0)
257 #define crcInitial crc32(0L, Z_NULL, 0)
259 /* static const char * const my_z_errmsg[] = { */
260 static const char my_z_errmsg[][32] = {
261 "need dictionary", /* Z_NEED_DICT 2 */
262 "stream end", /* Z_STREAM_END 1 */
264 "file error", /* Z_ERRNO (-1) */
265 "stream error", /* Z_STREAM_ERROR (-2) */
266 "data error", /* Z_DATA_ERROR (-3) */
267 "insufficient memory", /* Z_MEM_ERROR (-4) */
268 "buffer error", /* Z_BUF_ERROR (-5) */
269 "incompatible version",/* Z_VERSION_ERROR(-6) */
272 #define setDUALstatus(var, err) \
273 sv_setnv(var, (double)err) ; \
274 sv_setpv(var, ((err) ? GetErrorString(err) : "")) ; \
278 #if defined(__SYMBIAN32__)
279 # define NO_WRITEABLE_DATA
282 /* Set TRACE_DEFAULT to a non-zero value to enable tracing */
283 #define TRACE_DEFAULT 0
285 #if defined(NO_WRITEABLE_DATA) || TRACE_DEFAULT == 0
286 # define trace TRACE_DEFAULT
288 static int trace = TRACE_DEFAULT ;
291 /* Dodge PerlIO hiding of these functions. */
296 GetErrorString(int error_no)
298 GetErrorString(error_no)
305 if (error_no == Z_ERRNO) {
306 errstr = Strerror(errno) ;
309 /* errstr = gzerror(fil, &error_no) ; */
310 errstr = (char*) my_z_errmsg[2 - error_no];
319 The following two functions are taken almost directly from
320 examples/gzappend.c. Only cosmetic changes have been made to conform to
321 the coding style of the rest of the code in this file.
325 /* return the greatest common divisor of a and b using Euclid's algorithm,
326 modified to be fast when one argument much greater than the other, and
327 coded to avoid unnecessary swapping */
330 gcd(unsigned a, unsigned b)
355 /* rotate list[0..len-1] left by rot positions, in place */
358 rotate(unsigned char *list, unsigned len, unsigned rot)
360 rotate(list, len, rot)
368 unsigned char *start, *last, *to, *from;
370 /* normalize rot and handle degenerate cases */
372 if (rot >= len) rot %= len;
373 if (rot == 0) return;
375 /* pointer to last entry in list */
376 last = list + (len - 1);
378 /* do simple left shift by one */
381 memmove(list, list + 1, len - 1);
386 /* do simple right shift by one */
387 if (rot == len - 1) {
389 memmove(list + 1, list, len - 1);
394 /* otherwise do rotate as a set of cycles in place */
395 cycles = gcd(len, rot); /* number of cycles */
397 start = from = list + cycles; /* start index is arbitrary */
398 tmp = *from; /* save entry to be overwritten */
400 to = from; /* next step in cycle */
401 from += rot; /* go right rot positions */
402 if (from > last) from -= len; /* (pointer better not wrap) */
403 if (from == start) break; /* all but one shifted */
404 *to = *from; /* shift left */
406 *to = tmp; /* complete the circle */
410 #endif /* MAGIC_APPEND */
414 DispHex(void * ptr, int length)
421 char * p = (char*)ptr;
423 for (i = 0; i < length; ++i) {
424 printf(" %02x", 0xFF & *(p+i));
431 DispStream(di_stream * s, const char * message)
433 DispStream(s, message)
435 const char * message;
444 #define EnDis(f) (s->flags & f ? "Enabled" : "Disabled")
446 printf("DispStream %p", s) ;
448 printf("- %s \n", message) ;
452 printf(" stream pointer is NULL\n");
455 printf(" stream %p\n", &(s->stream));
456 printf(" zalloc %p\n", s->stream.zalloc);
457 printf(" zfree %p\n", s->stream.zfree);
458 printf(" opaque %p\n", s->stream.opaque);
459 printf(" state %p\n", s->stream.state);
461 printf(" msg %s\n", s->stream.msg);
464 printf(" next_in %p", s->stream.next_in);
465 if (s->stream.next_in){
467 DispHex(s->stream.next_in, 4);
471 printf(" next_out %p", s->stream.next_out);
472 if (s->stream.next_out){
474 DispHex(s->stream.next_out, 4);
478 printf(" avail_in %lu\n", (unsigned long)s->stream.avail_in);
479 printf(" avail_out %lu\n", (unsigned long)s->stream.avail_out);
480 printf(" total_in %ld\n", s->stream.total_in);
481 printf(" total_out %ld\n", s->stream.total_out);
482 printf(" adler %ld\n", s->stream.adler );
483 printf(" bufsize %ld\n", s->bufsize);
484 printf(" dictionary %p\n", s->dictionary);
485 printf(" dict_adler 0x%ld\n",s->dict_adler);
486 printf(" zip_mode %d\n", s->zip_mode);
487 printf(" crc32 0x%x\n", (unsigned)s->crc32);
488 printf(" adler32 0x%x\n", (unsigned)s->adler32);
489 printf(" flags 0x%x\n", s->flags);
490 printf(" APPEND %s\n", EnDis(FLAG_APPEND));
491 printf(" CRC32 %s\n", EnDis(FLAG_CRC32));
492 printf(" ADLER32 %s\n", EnDis(FLAG_ADLER32));
493 printf(" CONSUME %s\n", EnDis(FLAG_CONSUME_INPUT));
494 printf(" LIMIT %s\n", EnDis(FLAG_LIMIT_OUTPUT));
498 printf(" window %p\n", s->window);
505 #ifdef AT_LEAST_ZLIB_1_2_5_2
506 voidpf my_zcalloc (voidpf opaque, unsigned items, unsigned size)
508 PERL_UNUSED_VAR(opaque);
509 return safemalloc(items * size);
513 void my_zcfree (voidpf opaque, voidpf ptr)
515 PERL_UNUSED_VAR(opaque);
531 ZMALLOC(s, di_stream) ;
533 #ifdef AT_LEAST_ZLIB_1_2_5_2
534 s->stream.zalloc = my_zcalloc;
535 s->stream.zfree = my_zcfree;
543 PostInitStream(di_stream * s, int flags, int bufsize, int windowBits)
545 PostInitStream(s, flags, bufsize, windowBits)
552 s->bufsize = bufsize ;
554 s->uncompressedBytes =
557 s->zip_mode = (windowBits < 0) ;
558 if (flags & FLAG_CRC32)
559 s->crc32 = crcInitial ;
560 if (flags & FLAG_ADLER32)
561 s->adler32 = adlerInitial ;
567 deRef(SV * sv, const char * string)
584 croak("%s: buffer parameter is not a SCALAR reference", string);
589 croak("%s: buffer parameter is a reference to a reference", string) ;
593 sv = sv_2mortal(newSVpv("", 0));
600 deRef_l(SV * sv, const char * string)
623 croak("%s: buffer parameter is not a SCALAR reference", string);
628 croak("%s: buffer parameter is a reference to a reference", string) ;
631 if (SvREADONLY(sv) && PL_curcop != &PL_compiling)
632 croak("%s: buffer parameter is read-only", string);
634 SvUPGRADE(sv, SVt_PV);
639 (void)SvPVbyte_force(sv, na) ;
646 flushToBuffer(di_stream* s, int flush)
650 z_stream * strm = &s->stream;
652 Bytef* output = s->deflateParams_out_buffer ;
654 strm->next_in = NULL;
657 uLong total_output = 0;
663 output = (unsigned char *)saferealloc(output, total_output + s->bufsize);
665 output = (unsigned char *)safemalloc(s->bufsize);
667 strm->next_out = output + total_output;
668 strm->avail_out = s->bufsize;
670 ret = deflate(strm, flush); /* no bad return value */
671 //assert(ret != Z_STREAM_ERROR); /* state not clobbered */
672 if(ret == Z_STREAM_ERROR)
677 have = s->bufsize - strm->avail_out;
678 total_output += have;
680 //fprintf(stderr, "FLUSH %s %d, return %d\n", flush_flags[flush], have, ret);
682 } while (strm->avail_out == 0);
684 s->deflateParams_out_buffer = output;
685 s->deflateParams_out_length = total_output;
693 flushParams(di_stream* s)
697 z_stream * strm = &s->stream;
699 Bytef* output = s->deflateParams_out_buffer ;
700 uLong total_output = s->deflateParams_out_length;
703 strm->next_in = NULL;
710 output = (unsigned char *)saferealloc(output, total_output + s->bufsize);
712 output = (unsigned char *)safemalloc(s->bufsize);
714 strm->next_out = output + total_output;
715 strm->avail_out = s->bufsize;
717 ret = deflateParams(&(s->stream), s->Level, s->Strategy);
718 /* fprintf(stderr, "deflateParams %d %s %lu\n", ret,
719 GetErrorString(ret), s->bufsize - strm->avail_out); */
721 if (ret == Z_STREAM_ERROR)
724 have = s->bufsize - strm->avail_out;
725 total_output += have;
728 } while (ret == Z_BUF_ERROR) ;
730 if(ret == Z_STREAM_ERROR)
734 s->deflateParams_out_buffer = output;
735 s->deflateParams_out_length = total_output;
740 #endif /* ! SETP_BYTE */
742 #include "constants.h"
744 MODULE = Compress::Raw::Zlib PACKAGE = Compress::Raw::Zlib PREFIX = Zip_
749 INCLUDE: constants.xs
752 /* Check this version of zlib is == 1 */
753 if (zlibVersion()[0] != '1')
754 croak("Compress::Raw::Zlib needs zlib version 1.x\n") ;
757 /* Create the $os_code scalar */
758 SV * os_code_sv = perl_get_sv("Compress::Raw::Zlib::gzip_os_code", GV_ADDMULTI) ;
759 sv_setiv(os_code_sv, GZIP_OS_CODE) ;
763 #define Zip_zlib_version() (const char*)zlib_version
771 RETVAL = ZLIB_VERNUM ;
773 /* 1.1.4 => 0x1140 */
774 RETVAL = (ZLIB_VERSION[0] - '0') << 12 ;
775 RETVAL += (ZLIB_VERSION[2] - '0') << 8 ;
776 RETVAL += (ZLIB_VERSION[4] - '0') << 4 ;
777 if (strlen(ZLIB_VERSION) > 5)
778 RETVAL += (ZLIB_VERSION[6] - '0') ;
784 #ifndef AT_LEAST_ZLIB_1_2_1
785 #define zlibCompileFlags() 0
790 MODULE = Compress::Raw::Zlib PACKAGE = Compress::Raw::Zlib PREFIX = Zip_
792 #define Zip_adler32(buf, adler) adler32(adler, buf, (uInt)len)
795 Zip_adler32(buf, adler=adlerInitial)
796 uLong adler = NO_INIT
798 Bytef * buf = NO_INIT
801 /* If the buffer is a reference, dereference it */
802 sv = deRef(sv, "adler32") ;
803 #ifdef UTF8_AVAILABLE
804 if (DO_UTF8(sv) && !sv_utf8_downgrade(sv, 1))
805 croak("Wide character in Compress::Raw::Zlib::adler32");
807 buf = (Byte*)SvPVbyte(sv, len) ;
810 adler = adlerInitial;
811 else if (SvOK(ST(1)))
812 adler = SvUV(ST(1)) ;
814 adler = adlerInitial;
818 #define Zip_crc32(buf, crc, offset) crc32(crc, buf+offset, (uInt)len-offset)
821 Zip_crc32(buf, crc=crcInitial, offset=0)
824 Bytef * buf = NO_INIT
828 /* If the buffer is a reference, dereference it */
829 sv = deRef(sv, "crc32") ;
830 #ifdef UTF8_AVAILABLE
831 if (DO_UTF8(sv) && !sv_utf8_downgrade(sv, 1))
832 croak("Wide character in Compress::Raw::Zlib::crc32");
834 buf = (Byte*)SvPVbyte(sv, len) ;
838 else if (SvOK(ST(1)))
844 crc32_combine(crc1, crc2, len2)
849 #ifndef AT_LEAST_ZLIB_1_2_2_1
850 crc1 = crc1; crc2 = crc2 ; len2 = len2; /* Silence -Wall */
851 croak("crc32_combine needs zlib 1.2.3 or better");
853 RETVAL = crc32_combine(crc1, crc2, len2);
860 adler32_combine(adler1, adler2, len2)
865 #ifndef AT_LEAST_ZLIB_1_2_2_1
866 adler1 = adler1; adler2 = adler2 ; len2 = len2; /* Silence -Wall */
867 croak("adler32_combine needs zlib 1.2.3 or better");
869 RETVAL = adler32_combine(adler1, adler2, len2);
875 MODULE = Compress::Raw::Zlib PACKAGE = Compress::Raw::Zlib
878 _deflateInit(flags,level, method, windowBits, memLevel, strategy, bufsize, dictionary)
892 warn("in _deflateInit(level=%d, method=%d, windowBits=%d, memLevel=%d, strategy=%d, bufsize=%ld dictionary=%p)\n",
893 level, method, windowBits, memLevel, strategy, bufsize, dictionary) ;
894 if ((s = InitStream() )) {
898 s->WindowBits = windowBits;
899 s->MemLevel = memLevel;
900 s->Strategy = strategy;
902 err = deflateInit2(&(s->stream), level,
903 method, windowBits, memLevel, strategy);
906 warn(" _deflateInit2 returned %d (state %p)\n", err, s);
907 DispStream(s, "INIT");
910 /* Check if a dictionary has been specified */
911 SvGETMAGIC(dictionary);
912 if (err == Z_OK && SvPOK(dictionary) && SvCUR(dictionary)) {
913 #ifdef UTF8_AVAILABLE
914 if (DO_UTF8(dictionary) && !sv_utf8_downgrade(dictionary, 1))
915 croak("Wide character in Compress::Raw::Zlib::Deflate::new dicrionary parameter");
917 err = deflateSetDictionary(&(s->stream), (const Bytef*) SvPVX(dictionary), SvCUR(dictionary)) ;
919 warn("deflateSetDictionary returned %d\n", err);
920 s->dict_adler = s->stream.adler ;
928 PostInitStream(s, flags, bufsize, windowBits) ;
935 SV* obj = sv_setref_pv(sv_newmortal(),
936 "Compress::Raw::Zlib::deflateStream", (void*)s);
939 if (GIMME == G_ARRAY) {
940 SV * sv = sv_2mortal(newSViv(err)) ;
941 setDUALstatus(sv, err);
946 _inflateInit(flags, windowBits, bufsize, dictionary)
959 croak("inflateScanInit needs zlib 1.2.1 or better");
962 warn("in _inflateInit(windowBits=%d, bufsize=%lu, dictionary=%lu\n",
963 windowBits, bufsize, (unsigned long)SvCUR(dictionary)) ;
964 if ((s = InitStream() )) {
966 s->WindowBits = windowBits;
968 err = inflateInit2(&(s->stream), windowBits);
973 else if (sv_len(dictionary)) {
974 #ifdef AT_LEAST_ZLIB_1_2_2_1
975 /* Zlib 1.2.2.1 or better allows a dictionary with raw inflate */
976 if (s->WindowBits < 0) {
978 const Bytef* b = (const Bytef*)SvPVbyte(dictionary, dlen);
979 err = inflateSetDictionary(&(s->stream),
988 /* Dictionary specified - take a copy for use in inflate */
989 s->dictionary = newSVsv(dictionary) ;
992 PostInitStream(s, flags, bufsize, windowBits) ;
996 s->window = (unsigned char *)safemalloc(WINDOW_SIZE);
1005 SV* obj = sv_setref_pv(sv_newmortal(),
1007 ? "Compress::Raw::Zlib::inflateScanStream"
1008 : "Compress::Raw::Zlib::inflateStream",
1012 if (GIMME == G_ARRAY) {
1013 SV * sv = sv_2mortal(newSViv(err)) ;
1014 setDUALstatus(sv, err);
1020 MODULE = Compress::Raw::Zlib PACKAGE = Compress::Raw::Zlib::deflateStream
1023 DispStream(s, message=NULL)
1024 Compress::Raw::Zlib::deflateStream s
1025 const char * message
1029 Compress::Raw::Zlib::deflateStream s
1031 RETVAL = deflateReset(&(s->stream)) ;
1032 if (RETVAL == Z_OK) {
1033 PostInitStream(s, s->flags, s->bufsize, s->WindowBits) ;
1039 deflate (s, buf, output)
1040 Compress::Raw::Zlib::deflateStream s
1043 uInt cur_length = NO_INIT
1044 uInt increment = NO_INIT
1045 uInt prefix = NO_INIT
1047 uLong bufinc = NO_INIT
1048 STRLEN origlen = NO_INIT
1050 bufinc = s->bufsize;
1052 /* If the input buffer is a reference, dereference it */
1053 buf = deRef(buf, "deflate") ;
1055 /* initialise the input buffer */
1056 #ifdef UTF8_AVAILABLE
1057 if (DO_UTF8(buf) && !sv_utf8_downgrade(buf, 1))
1058 croak("Wide character in Compress::Raw::Zlib::Deflate::deflate input parameter");
1060 s->stream.next_in = (Bytef*)SvPV_nomg(buf, origlen) ;
1061 s->stream.avail_in = origlen;
1063 if (s->flags & FLAG_CRC32)
1064 s->crc32 = crc32(s->crc32, s->stream.next_in, s->stream.avail_in) ;
1066 if (s->flags & FLAG_ADLER32)
1067 s->adler32 = adler32(s->adler32, s->stream.next_in, s->stream.avail_in) ;
1069 /* and retrieve the output buffer */
1070 output = deRef_l(output, "deflate") ;
1071 #ifdef UTF8_AVAILABLE
1072 if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1))
1073 croak("Wide character in Compress::Raw::Zlib::Deflate::deflate output parameter");
1076 if((s->flags & FLAG_APPEND) != FLAG_APPEND) {
1077 SvCUR_set(output, 0);
1078 /* sv_setpvn(output, "", 0); */
1080 prefix = cur_length = SvCUR(output) ;
1081 s->stream.next_out = (Bytef*) SvPVX(output) + cur_length;
1082 increment = SvLEN(output) - cur_length;
1083 s->stream.avail_out = increment;
1085 /* Check for saved output from deflateParams */
1086 if (s->deflateParams_out_valid) {
1087 *(s->stream.next_out) = s->deflateParams_out_byte;
1088 ++ s->stream.next_out;
1089 -- s->stream.avail_out ;
1090 s->deflateParams_out_valid = FALSE;
1093 /* Check for saved output from deflateParams */
1094 if (s->deflateParams_out_length) {
1095 uLong plen = s->deflateParams_out_length ;
1096 /* printf("Copy %lu bytes saved data\n", plen); */
1097 if (s->stream.avail_out < plen) {
1098 /* printf("GROW from %d to %lu\n", s->stream.avail_out,
1099 SvLEN(output) + plen - s->stream.avail_out); */
1100 s->stream.next_out = (Bytef*) Sv_Grow(output, SvLEN(output) + plen - s->stream.avail_out) ;
1101 s->stream.next_out += cur_length;
1104 Copy(s->deflateParams_out_buffer, s->stream.next_out, plen, Bytef) ;
1106 SvCUR_set(output, cur_length);
1107 s->stream.next_out += plen ;
1108 s->stream.avail_out = SvLEN(output) - cur_length ;
1109 increment = s->stream.avail_out;
1111 s->deflateParams_out_length = 0;
1112 Safefree(s->deflateParams_out_buffer);
1113 s->deflateParams_out_buffer = NULL;
1117 while (s->stream.avail_in != 0) {
1119 if (s->stream.avail_out == 0) {
1120 /* out of space in the output buffer so make it bigger */
1121 s->stream.next_out = (Bytef*) Sv_Grow(output, SvLEN(output) + bufinc) ;
1122 cur_length += increment ;
1123 s->stream.next_out += cur_length ;
1124 increment = bufinc ;
1125 s->stream.avail_out = increment;
1130 printf("DEFLATE Avail In %d, Out %d\n", s->stream.avail_in, s->stream.avail_out);
1131 DispStream(s, "BEFORE");
1132 /* Perl_sv_dump(output); */
1135 RETVAL = deflate(&(s->stream), Z_NO_FLUSH);
1137 if (RETVAL != Z_STREAM_ERROR) {
1138 int done = increment - s->stream.avail_out ;
1139 printf("std DEFLATEr returned %d '%s' avail in %d, out %d wrote %d\n", RETVAL,
1140 GetErrorString(RETVAL), s->stream.avail_in,
1141 s->stream.avail_out, done);
1146 printf("DEFLATE returned %d %s, avail in %d, out %d\n", RETVAL,
1147 GetErrorString(RETVAL), s->stream.avail_in, s->stream.avail_out);
1148 DispStream(s, "AFTER");
1155 s->compressedBytes += cur_length + increment - prefix - s->stream.avail_out ;
1156 s->uncompressedBytes += origlen - s->stream.avail_in ;
1158 s->last_error = RETVAL ;
1159 if (RETVAL == Z_OK) {
1161 SvCUR_set(output, cur_length + increment - s->stream.avail_out) ;
1170 Compress::Raw::Zlib::deflateStream s
1173 printf("Compress::Raw::Zlib::deflateStream::DESTROY %p\n", s);
1174 deflateEnd(&s->stream) ;
1176 SvREFCNT_dec(s->dictionary) ;
1178 if (s->deflateParams_out_buffer)
1179 Safefree(s->deflateParams_out_buffer);
1185 flush(s, output, f=Z_FINISH)
1186 Compress::Raw::Zlib::deflateStream s
1189 uInt cur_length = NO_INIT
1190 uInt increment = NO_INIT
1191 uInt prefix = NO_INIT
1192 uLong bufinc = NO_INIT
1193 uLong availableout = NO_INIT
1195 bufinc = s->bufsize;
1198 /* retrieve the output buffer */
1199 output = deRef_l(output, "flush") ;
1200 #ifdef UTF8_AVAILABLE
1201 if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1))
1202 croak("Wide character in Compress::Raw::Zlib::Deflate::flush input parameter");
1204 if((s->flags & FLAG_APPEND) != FLAG_APPEND) {
1205 SvCUR_set(output, 0);
1206 /* sv_setpvn(output, "", 0); */
1208 prefix = cur_length = SvCUR(output) ;
1209 s->stream.next_out = (Bytef*) SvPVX(output) + cur_length;
1210 increment = SvLEN(output) - cur_length;
1211 s->stream.avail_out = increment;
1213 /* Check for saved output from deflateParams */
1214 if (s->deflateParams_out_valid) {
1215 *(s->stream.next_out) = s->deflateParams_out_byte;
1216 ++ s->stream.next_out;
1217 -- s->stream.avail_out ;
1218 s->deflateParams_out_valid = FALSE;
1221 /* Check for saved output from deflateParams */
1222 if (s->deflateParams_out_length) {
1223 uLong plen = s->deflateParams_out_length ;
1224 /* printf("Copy %lu bytes saved data\n", plen); */
1225 if (s->stream.avail_out < plen) {
1226 /* printf("GROW from %d to %lu\n", s->stream.avail_out,
1227 SvLEN(output) + plen - s->stream.avail_out); */
1228 s->stream.next_out = (Bytef*) Sv_Grow(output, SvLEN(output) + plen - s->stream.avail_out) ;
1229 s->stream.next_out += cur_length;
1232 Copy(s->deflateParams_out_buffer, s->stream.next_out, plen, Bytef) ;
1234 SvCUR_set(output, cur_length);
1235 s->stream.next_out += plen ;
1236 s->stream.avail_out = SvLEN(output) - cur_length ;
1237 increment = s->stream.avail_out;
1239 s->deflateParams_out_length = 0;
1240 Safefree(s->deflateParams_out_buffer);
1241 s->deflateParams_out_buffer = NULL;
1246 if (s->stream.avail_out == 0) {
1247 /* consumed all the available output, so extend it */
1248 s->stream.next_out = (Bytef*) Sv_Grow(output, SvLEN(output) + bufinc) ;
1249 cur_length += increment ;
1250 s->stream.next_out += cur_length ;
1251 increment = bufinc ;
1252 s->stream.avail_out = increment;
1256 availableout = s->stream.avail_out ;
1259 printf("flush (%d) DEFLATE Avail In %d, Out %d\n", f, s->stream.avail_in, s->stream.avail_out);
1260 DispStream(s, "BEFORE");
1261 /* Perl_sv_dump(output); */
1264 RETVAL = deflate(&(s->stream), f);
1266 if (RETVAL != Z_STREAM_ERROR) {
1267 int done = availableout - s->stream.avail_out ;
1268 printf("flush DEFLATEr returned %d '%s' avail in %d, out %d wrote %d\n", RETVAL,
1269 GetErrorString(RETVAL), s->stream.avail_in,
1270 s->stream.avail_out, done);
1275 printf("flush DEFLATE returned %d '%s', avail in %d, out %d\n", RETVAL,
1276 GetErrorString(RETVAL), s->stream.avail_in, s->stream.avail_out);
1277 DispStream(s, "AFTER");
1280 /* Ignore the second of two consecutive flushes: */
1281 if (availableout == s->stream.avail_out && RETVAL == Z_BUF_ERROR)
1284 /* deflate has finished flushing only when it hasn't used up
1285 * all the available space in the output buffer:
1287 if (s->stream.avail_out != 0 || RETVAL != Z_OK )
1291 RETVAL = (RETVAL == Z_STREAM_END ? Z_OK : RETVAL) ;
1292 s->last_error = RETVAL ;
1294 s->compressedBytes += cur_length + increment - prefix - s->stream.avail_out ;
1296 if (RETVAL == Z_OK) {
1298 SvCUR_set(output, cur_length + increment - s->stream.avail_out) ;
1306 _deflateParams(s, flags, level, strategy, bufsize)
1307 Compress::Raw::Zlib::deflateStream s
1312 bool changed = FALSE;
1314 /* printf("_deflateParams(Flags %d Level %d Strategy %d Bufsize %d)\n", flags, level, strategy, bufsize);
1315 printf("Before -- Level %d, Strategy %d, Bufsize %d\n", s->Level, s->Strategy, s->bufsize); */
1316 if (flags & 1 && level != s->Level) {
1320 if (flags & 2 && strategy != s->Strategy) {
1321 s->Strategy = strategy ;
1325 s->bufsize = bufsize;
1328 s->stream.avail_in = 0;
1329 s->stream.next_out = &(s->deflateParams_out_byte) ;
1330 s->stream.avail_out = 1;
1331 RETVAL = deflateParams(&(s->stream), s->Level, s->Strategy);
1332 s->deflateParams_out_valid =
1333 (RETVAL == Z_OK && s->stream.avail_out == 0) ;
1335 /* printf("Level %d Strategy %d, Prev Len %d\n",
1336 s->Level, s->Strategy, s->deflateParams_out_length); */
1337 RETVAL = flushParams(s);
1348 Compress::Raw::Zlib::deflateStream s
1356 Compress::Raw::Zlib::deflateStream s
1358 RETVAL = s->Strategy ;
1365 Compress::Raw::Zlib::deflateStream s
1367 RETVAL = s->bufsize ;
1374 Compress::Raw::Zlib::deflateStream s
1376 RETVAL = s->last_error ;
1382 Compress::Raw::Zlib::deflateStream s
1390 Compress::Raw::Zlib::deflateStream s
1392 RETVAL = s->dict_adler ;
1398 Compress::Raw::Zlib::deflateStream s
1400 RETVAL = s->adler32 ;
1406 Compress::Raw::Zlib::deflateStream s
1408 RETVAL = s->compressedBytes;
1413 uncompressedBytes(s)
1414 Compress::Raw::Zlib::deflateStream s
1416 RETVAL = s->uncompressedBytes;
1422 Compress::Raw::Zlib::deflateStream s
1424 RETVAL = s->stream.total_in ;
1430 Compress::Raw::Zlib::deflateStream s
1432 RETVAL = s->stream.total_out ;
1438 Compress::Raw::Zlib::deflateStream s
1440 RETVAL = s->stream.msg;
1445 deflateTune(s, good_length, max_lazy, nice_length, max_chain)
1446 Compress::Raw::Zlib::deflateStream s
1452 #ifndef AT_LEAST_ZLIB_1_2_2_3
1453 good_length = good_length; max_lazy = max_lazy ; /* Silence -Wall */
1454 nice_length = nice_length; max_chain = max_chain; /* Silence -Wall */
1455 croak("deflateTune needs zlib 1.2.2.3 or better");
1457 RETVAL = deflateTune(&(s->stream), good_length, max_lazy, nice_length, max_chain);
1463 MODULE = Compress::Raw::Zlib PACKAGE = Compress::Raw::Zlib::inflateStream
1466 DispStream(s, message=NULL)
1467 Compress::Raw::Zlib::inflateStream s
1468 const char * message
1472 Compress::Raw::Zlib::inflateStream s
1474 RETVAL = inflateReset(&(s->stream)) ;
1475 if (RETVAL == Z_OK) {
1476 PostInitStream(s, s->flags, s->bufsize, s->WindowBits) ;
1482 inflate (s, buf, output, eof=FALSE)
1483 Compress::Raw::Zlib::inflateStream s
1487 uInt cur_length = 0;
1488 uInt prefix_length = 0;
1490 uLong bufinc = NO_INIT
1491 STRLEN na = NO_INIT ;
1493 #ifdef UTF8_AVAILABLE
1494 bool out_utf8 = FALSE;
1498 bufinc = s->bufsize;
1499 /* If the buffer is a reference, dereference it */
1500 buf = deRef(buf, "inflate") ;
1502 if (s->flags & FLAG_CONSUME_INPUT) {
1503 if (SvREADONLY(buf))
1504 croak("Compress::Raw::Zlib::Inflate::inflate input parameter cannot be read-only when ConsumeInput is specified");
1505 SvPV_force(buf, na);
1507 #ifdef UTF8_AVAILABLE
1508 if (DO_UTF8(buf) && !sv_utf8_downgrade(buf, 1))
1509 croak("Wide character in Compress::Raw::Zlib::Inflate::inflate input parameter");
1512 /* initialise the input buffer */
1513 s->stream.next_in = (Bytef*)SvPV_nomg(buf, origlen) ;
1514 s->stream.avail_in = origlen ;
1516 /* and retrieve the output buffer */
1517 output = deRef_l(output, "inflate") ;
1518 #ifdef UTF8_AVAILABLE
1519 if (DO_UTF8(output))
1521 if (DO_UTF8(output) && !sv_utf8_downgrade(output, 1))
1522 croak("Wide character in Compress::Raw::Zlib::Inflate::inflate output parameter");
1524 if((s->flags & FLAG_APPEND) != FLAG_APPEND) {
1525 SvCUR_set(output, 0);
1528 /* Assume no output buffer - the code below will update if there is any available */
1529 s->stream.avail_out = 0;
1532 if (SvLEN(output)) {
1533 prefix_length = cur_length = SvCUR(output) ;
1535 if (s->flags & FLAG_LIMIT_OUTPUT && SvLEN(output) - cur_length - 1 < bufinc)
1537 Sv_Grow(output, bufinc + cur_length + 1) ;
1540 /* Only setup the stream output pointers if there is spare
1541 capacity in the outout SV
1543 if (SvLEN(output) > cur_length + 1)
1545 s->stream.next_out = (Bytef*) SvPV_nomg_nolen(output) + cur_length;
1546 increment = SvLEN(output) - cur_length - 1;
1547 s->stream.avail_out = increment;
1552 s->bytesInflated = 0;
1556 while (RETVAL == Z_OK) {
1557 if (s->stream.avail_out == 0) {
1558 /* out of space in the output buffer so make it bigger */
1559 s->stream.next_out = (Bytef*) Sv_Grow(output, SvLEN(output) + bufinc +1) ;
1560 cur_length += increment ;
1561 s->stream.next_out += cur_length ;
1562 increment = bufinc ;
1563 s->stream.avail_out = increment;
1567 /* printf("INFLATE Availl In %d, Out %d\n", s->stream.avail_in,
1568 s->stream.avail_out);
1569 DispStream(s, "BEFORE");
1570 Perl_sv_dump(output); */
1571 RETVAL = inflate(&(s->stream), Z_SYNC_FLUSH);
1572 /* printf("INFLATE returned %d %s, avail in %d, out %d\n", RETVAL,
1573 GetErrorString(RETVAL), s->stream.avail_in, s->stream.avail_out); */
1576 if (RETVAL == Z_NEED_DICT && s->dictionary) {
1578 const Bytef* b = (const Bytef*)SvPV(s->dictionary, dlen) ;
1579 s->dict_adler = s->stream.adler ;
1580 RETVAL = inflateSetDictionary(&(s->stream),
1586 if (s->flags & FLAG_LIMIT_OUTPUT &&
1587 (RETVAL == Z_OK || RETVAL == Z_BUF_ERROR )) {
1588 if (s->stream.avail_out == 0)
1589 RETVAL = Z_BUF_ERROR;
1592 if (s->flags & FLAG_LIMIT_OUTPUT &&
1593 (RETVAL == Z_OK || RETVAL == Z_BUF_ERROR ))
1596 if (RETVAL == Z_STREAM_ERROR || RETVAL == Z_MEM_ERROR ||
1597 RETVAL == Z_DATA_ERROR || RETVAL == Z_STREAM_END )
1600 if (RETVAL == Z_BUF_ERROR) {
1601 if (s->stream.avail_out == 0)
1603 if (s->stream.avail_in == 0) {
1609 #ifdef NEED_DUMMY_BYTE_AT_END
1610 if (eof && RETVAL == Z_OK && s->flags & FLAG_LIMIT_OUTPUT == 0) {
1611 Bytef* nextIn = s->stream.next_in;
1612 uInt availIn = s->stream.avail_in;
1613 s->stream.next_in = (Bytef*) " ";
1614 s->stream.avail_in = 1;
1615 if (s->stream.avail_out == 0) {
1616 /* out of space in the output buffer so make it bigger */
1617 s->stream.next_out = Sv_Grow(output, SvLEN(output) + bufinc) ;
1618 cur_length += increment ;
1619 s->stream.next_out += cur_length ;
1620 increment = bufinc ;
1621 s->stream.avail_out = increment;
1624 RETVAL = inflate(&(s->stream), Z_SYNC_FLUSH);
1625 s->stream.next_in = nextIn ;
1626 s->stream.avail_in = availIn ;
1629 PERL_UNUSED_VAR(eof);
1632 s->last_error = RETVAL ;
1633 if (RETVAL == Z_OK || RETVAL == Z_STREAM_END || RETVAL == Z_BUF_ERROR || RETVAL == Z_DATA_ERROR) {
1636 s->bytesInflated = cur_length + increment - s->stream.avail_out - prefix_length;
1637 s->uncompressedBytes += s->bytesInflated ;
1638 s->compressedBytes += origlen - s->stream.avail_in ;
1641 SvCUR_set(output, prefix_length + s->bytesInflated) ;
1642 *SvEND(output) = '\0';
1643 #ifdef UTF8_AVAILABLE
1645 sv_utf8_upgrade(output);
1649 if (s->flags & FLAG_CRC32 )
1650 s->crc32 = crc32(s->crc32,
1651 (const Bytef*)SvPVX(output)+prefix_length,
1652 SvCUR(output)-prefix_length) ;
1654 if (s->flags & FLAG_ADLER32)
1655 s->adler32 = adler32(s->adler32,
1656 (const Bytef*)SvPVX(output)+prefix_length,
1657 SvCUR(output)-prefix_length) ;
1659 /* fix the input buffer */
1660 if (s->flags & FLAG_CONSUME_INPUT || s->flags & FLAG_LIMIT_OUTPUT) {
1661 in = s->stream.avail_in ;
1662 SvCUR_set(buf, in) ;
1664 Move(s->stream.next_in, SvPVX(buf), in, char) ;
1675 Compress::Raw::Zlib::inflateStream s
1677 RETVAL = s->bytesInflated;
1683 Compress::Raw::Zlib::inflateStream s
1685 RETVAL = s->compressedBytes;
1690 uncompressedBytes(s)
1691 Compress::Raw::Zlib::inflateStream s
1693 RETVAL = s->uncompressedBytes;
1699 inflateSync (s, buf)
1700 Compress::Raw::Zlib::inflateStream s
1704 /* If the buffer is a reference, dereference it */
1705 buf = deRef(buf, "inflateSync") ;
1706 #ifdef UTF8_AVAILABLE
1707 if (DO_UTF8(buf) && !sv_utf8_downgrade(buf, 1))
1708 croak("Wide character in Compress::Raw::Zlib::Inflate::inflateSync");
1711 /* initialise the input buffer */
1712 s->stream.next_in = (Bytef*)SvPV_force_nomg_nolen(buf) ;
1713 s->stream.avail_in = SvCUR(buf) ;
1715 /* inflateSync doesn't create any output */
1716 s->stream.next_out = (Bytef*) NULL;
1717 s->stream.avail_out = 0;
1719 RETVAL = inflateSync(&(s->stream));
1720 s->last_error = RETVAL ;
1722 /* fix the input buffer */
1724 unsigned in = s->stream.avail_in ;
1725 SvCUR_set(buf, in) ;
1727 Move(s->stream.next_in, SvPVX(buf), in, char) ;
1736 Compress::Raw::Zlib::inflateStream s
1738 inflateEnd(&s->stream) ;
1740 SvREFCNT_dec(s->dictionary) ;
1742 if (s->deflateParams_out_buffer)
1743 Safefree(s->deflateParams_out_buffer);
1747 Safefree(s->window);
1754 Compress::Raw::Zlib::inflateStream s
1756 RETVAL = s->last_error ;
1762 Compress::Raw::Zlib::inflateStream s
1770 Compress::Raw::Zlib::inflateStream s
1772 RETVAL = s->dict_adler ;
1778 Compress::Raw::Zlib::inflateStream s
1780 RETVAL = s->stream.total_in ;
1786 Compress::Raw::Zlib::inflateStream s
1788 RETVAL = s->adler32 ;
1794 Compress::Raw::Zlib::inflateStream s
1796 RETVAL = s->stream.total_out ;
1802 Compress::Raw::Zlib::inflateStream s
1804 RETVAL = s->stream.msg;
1811 Compress::Raw::Zlib::inflateStream s
1813 RETVAL = s->bufsize ;
1819 Compress::Raw::Zlib::inflateStream s
1822 RETVAL = ((s->flags & FLAG_APPEND) == FLAG_APPEND);
1824 s->flags |= FLAG_APPEND ;
1826 s->flags &= ~FLAG_APPEND ;
1830 MODULE = Compress::Raw::Zlib PACKAGE = Compress::Raw::Zlib::inflateScanStream
1834 Compress::Raw::Zlib::inflateScanStream s
1836 inflateEnd(&s->stream) ;
1838 SvREFCNT_dec(s->dictionary) ;
1840 if (s->deflateParams_out_buffer)
1841 Safefree(s->deflateParams_out_buffer);
1845 Safefree(s->window);
1850 DispStream(s, message=NULL)
1851 Compress::Raw::Zlib::inflateScanStream s
1852 const char * message
1856 Compress::Raw::Zlib::inflateScanStream s
1858 RETVAL = inflateReset(&(s->stream)) ;
1859 if (RETVAL == Z_OK) {
1860 PostInitStream(s, s->flags, s->bufsize, s->WindowBits) ;
1866 scan(s, buf, out=NULL, eof=FALSE)
1867 Compress::Raw::Zlib::inflateScanStream s
1871 bool eof_mode = FALSE;
1872 int start_len = NO_INIT
1874 PERL_UNUSED_VAR(out);
1875 PERL_UNUSED_VAR(eof);
1876 /* If the input buffer is a reference, dereference it */
1877 #ifndef MAGIC_APPEND
1879 croak("scan needs zlib 1.2.1 or better");
1881 buf = deRef(buf, "inflateScan") ;
1882 #ifdef UTF8_AVAILABLE
1883 if (DO_UTF8(buf) && !sv_utf8_downgrade(buf, 1))
1884 croak("Wide character in Compress::Raw::Zlib::InflateScan::scan input parameter");
1886 /* initialise the input buffer */
1887 s->stream.next_in = (Bytef*)SvPV_force_nomg_nolen(buf) ;
1888 s->stream.avail_in = SvCUR(buf) ;
1889 start_len = s->stream.avail_in ;
1890 s->bytesInflated = 0 ;
1893 if (s->stream.avail_in == 0) {
1898 /* set up output to next available section of sliding window */
1899 s->stream.avail_out = WINDOW_SIZE - s->window_have;
1900 s->stream.next_out = s->window + s->window_have;
1902 /* DispStream(s, "before inflate\n"); */
1904 /* inflate and check for errors */
1905 RETVAL = inflate(&(s->stream), Z_BLOCK);
1907 if (start_len > 1 && ! eof_mode)
1908 s->window_lastByte = *(s->stream.next_in - 1 ) ;
1910 if (RETVAL == Z_STREAM_ERROR || RETVAL == Z_MEM_ERROR ||
1911 RETVAL == Z_DATA_ERROR )
1914 if (s->flags & FLAG_CRC32 )
1915 s->crc32 = crc32(s->crc32, s->window + s->window_have,
1916 WINDOW_SIZE - s->window_have - s->stream.avail_out);
1918 if (s->flags & FLAG_ADLER32)
1919 s->adler32 = adler32(s->adler32, s->window + s->window_have,
1920 WINDOW_SIZE - s->window_have - s->stream.avail_out);
1922 s->uncompressedBytes =
1923 s->bytesInflated += WINDOW_SIZE - s->window_have - s->stream.avail_out;
1925 if (s->stream.avail_out)
1926 s->window_have = WINDOW_SIZE - s->stream.avail_out;
1932 /* process end of block */
1933 if (s->stream.data_type & 128) {
1934 if (s->stream.data_type & 64) {
1935 s->window_left = s->stream.data_type & 0x1f;
1938 s->window_lastbit = s->stream.data_type & 0x1f;
1939 s->lastBlockOffset = s->stream.total_in;
1943 } while (RETVAL != Z_STREAM_END);
1945 s->last_error = RETVAL ;
1946 s->window_lastoff = s->stream.total_in ;
1947 s->compressedBytes += SvCUR(buf) - s->stream.avail_in ;
1949 if (RETVAL == Z_STREAM_END)
1951 s->matchedEndBlock = 1 ;
1953 /* save the location of the end of the compressed data */
1954 s->window_end = SvCUR(buf) - s->stream.avail_in - 1 ;
1955 s->window_endOffset = s->stream.total_in ;
1958 -- s->window_endOffset ;
1961 /* if window wrapped, build dictionary from window by rotating */
1962 if (s->window_full) {
1963 rotate(s->window, WINDOW_SIZE, s->window_have);
1964 s->window_have = WINDOW_SIZE;
1967 /* if (s->flags & FLAG_CONSUME_INPUT) { */
1969 unsigned in = s->stream.avail_in ;
1970 SvCUR_set(buf, in) ;
1972 Move(s->stream.next_in, SvPVX(buf), in, char) ;
1984 Compress::Raw::Zlib::inflateScanStream s
1986 #ifndef MAGIC_APPEND
1987 croak("getEndOffset needs zlib 1.2.1 or better");
1989 RETVAL = s->window_endOffset;
1996 Compress::Raw::Zlib::inflateScanStream s
1998 #ifndef MAGIC_APPEND
1999 croak("inflateCount needs zlib 1.2.1 or better");
2001 RETVAL = s->bytesInflated;
2008 Compress::Raw::Zlib::inflateScanStream s
2010 RETVAL = s->compressedBytes;
2015 uncompressedBytes(s)
2016 Compress::Raw::Zlib::inflateScanStream s
2018 RETVAL = s->uncompressedBytes;
2024 getLastBlockOffset(s)
2025 Compress::Raw::Zlib::inflateScanStream s
2027 #ifndef MAGIC_APPEND
2028 croak("getLastBlockOffset needs zlib 1.2.1 or better");
2030 RETVAL = s->lastBlockOffset - (s->window_lastbit != 0);
2036 getLastBufferOffset(s)
2037 Compress::Raw::Zlib::inflateScanStream s
2039 #ifndef MAGIC_APPEND
2040 croak("getLastBufferOffset needs zlib 1.2.1 or better");
2042 RETVAL = s->window_lastoff;
2048 resetLastBlockByte(s, byte)
2049 Compress::Raw::Zlib::inflateScanStream s
2052 #ifndef MAGIC_APPEND
2053 croak("resetLastBlockByte needs zlib 1.2.1 or better");
2056 *byte = *byte ^ (1 << ((8 - s->window_lastbit) & 7));
2061 _createDeflateStream(inf_s, flags,level, method, windowBits, memLevel, strategy, bufsize)
2062 Compress::Raw::Zlib::inflateScanStream inf_s
2072 #ifndef MAGIC_APPEND
2076 windowBits = windowBits;
2077 memLevel = memLevel;
2078 strategy = strategy;
2080 croak("_createDeflateStream needs zlib 1.2.1 or better");
2086 warn("in _createDeflateStream(level=%d, method=%d, windowBits=%d, memLevel=%d, strategy=%d, bufsize=%lu\n",
2087 level, method, windowBits, memLevel, strategy, bufsize) ;
2088 if ((s = InitStream() )) {
2092 s->WindowBits = windowBits;
2093 s->MemLevel = memLevel;
2094 s->Strategy = strategy;
2096 err = deflateInit2(&(s->stream), level,
2097 method, windowBits, memLevel, strategy);
2100 err = deflateSetDictionary(&(s->stream), inf_s->window, inf_s->window_have);
2101 s->dict_adler = s->stream.adler ;
2109 PostInitStream(s, flags, bufsize, windowBits) ;
2110 s->crc32 = inf_s->crc32;
2111 s->adler32 = inf_s->adler32;
2112 s->stream.adler = inf_s->stream.adler ;
2113 /* s->stream.total_out = inf_s->bytesInflated ; */
2114 s->stream.total_in = inf_s->stream.total_out ;
2115 if (inf_s->window_left) {
2116 /* printf("** window_left %d, window_lastByte %d\n", inf_s->window_left, inf_s->window_lastByte); */
2117 deflatePrime(&(s->stream), 8 - inf_s->window_left, inf_s->window_lastByte);
2124 XPUSHs(sv_setref_pv(sv_newmortal(),
2125 "Compress::Raw::Zlib::deflateStream", (void*)s));
2126 if (GIMME == G_ARRAY) {
2127 SV * sv = sv_2mortal(newSViv(err)) ;
2128 setDUALstatus(sv, err);
2136 Compress::Raw::Zlib::inflateScanStream s
2138 RETVAL = s->last_error ;
2144 Compress::Raw::Zlib::inflateScanStream s
2153 Compress::Raw::Zlib::inflateScanStream s
2155 RETVAL = s->adler32 ;