1% -*- mode: slang; mode: fold -*- 2% Copyright (C) 2012-2017,2018 John E. Davis 3% 4% This file is part of the S-Lang Library and may be distributed under the 5% terms of the GNU General Public License. See the file COPYING for 6% more information. 7%--------------------------------------------------------------------------- 8import ("zlib"); 9 10%{{{ Deflate Object and methods 11private define deflate_method () 12{ 13 if (_NARGS != 2) 14 { 15 _pop_n (_NARGS); 16 usage (".deflate(str [;flush=val])"); 17 } 18 variable z, b; 19 (z, b) = (); 20 return _zlib_deflate (z.zobj, b, qualifier("flush", ZLIB_NO_FLUSH)); 21} 22 23private define def_reset_method (z) 24{ 25 _zlib_deflate_reset (z.zobj); 26} 27 28private define def_flush_method () 29{ 30 variable z, flush = ZLIB_FINISH; 31 switch (_NARGS) 32 { 33 case 2: 34 (z, flush) = (); 35 } 36 { 37 case 1: 38 z = (); 39 } 40 { 41 _pop_n (_NARGS); 42 usage (".flush ([val]); Default is ZLIB_FINISH"); 43 } 44 45 return _zlib_deflate_flush (z.zobj, flush); 46} 47 48private variable Deflate_Object = struct 49{ 50 zobj, 51 deflate = &deflate_method, 52 reset = &def_reset_method, 53 flush = &def_flush_method, 54}; 55 56define zlib_deflate_new () 57{ 58 variable z = @Deflate_Object; 59 z.zobj = _zlib_deflate_new (qualifier ("level", ZLIB_DEFAULT_COMPRESSION), 60 qualifier ("method", ZLIB_DEFLATED), 61 qualifier ("wbits", 15), 62 qualifier ("memlevel", 8), 63 qualifier ("strategy", ZLIB_DEFAULT_STRATEGY)); 64 return z; 65} 66 67%}}} 68 69%{{{ Inflate Object and methods 70 71private define inflate_method () 72{ 73 if (_NARGS != 2) 74 { 75 _pop_n (_NARGS); 76 usage (".inflate(str [;flush=val])"); 77 } 78 variable z, b; 79 (z, b) = (); 80 return _zlib_inflate (z.zobj, b, qualifier("flush", ZLIB_NO_FLUSH)); 81} 82 83private define inf_reset_method (z) 84{ 85 _zlib_inflate_reset (z.zobj); 86} 87 88private define inf_flush_method () 89{ 90 variable z, flush = ZLIB_FINISH; 91 switch (_NARGS) 92 { 93 case 2: 94 (z, flush) = (); 95 } 96 { 97 case 1: 98 z = (); 99 } 100 { 101 _pop_n (_NARGS); 102 usage (".flush ([val]); Default is ZLIB_FINISH"); 103 } 104 105 return _zlib_inflate_flush (z.zobj, flush); 106} 107 108private variable Inflate_Object = struct 109{ 110 zobj, 111 inflate = &inflate_method, 112 reset = &inf_reset_method, 113 flush = &inf_flush_method, 114}; 115 116define zlib_inflate_new () 117{ 118 variable z = @Inflate_Object; 119 z.zobj = _zlib_inflate_new (qualifier ("wbits", 15)); 120 return z; 121} 122 123%}}} 124 125define zlib_deflate () 126{ 127 if (_NARGS != 1) 128 { 129 usage ("zstr = zlib_deflate (str [;qualifiers])\n" 130 + " qualifiers:\n" 131 + " level=val, method=val, wbits=val, memlevel=val, strategy=val"); 132 } 133 variable bstr = (); 134 variable z = zlib_deflate_new (;; __qualifiers); 135 136 return _zlib_deflate (z.zobj, bstr, ZLIB_FINISH); 137} 138 139define zlib_inflate () 140{ 141 if (_NARGS != 1) 142 { 143 usage ("str = zlib_inflate (zstr [;wbits=val])"); 144 } 145 146 variable zstr = (); 147 variable z = zlib_inflate_new (;; __qualifiers); 148 return _zlib_inflate (z.zobj, zstr, ZLIB_FINISH); 149} 150