123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- using System;
- namespace Org.BouncyCastle.Utilities.Zlib {
- public sealed class ZStream{
- private const int MAX_WBITS=15;
- private const int DEF_WBITS=MAX_WBITS;
- private const int Z_NO_FLUSH=0;
- private const int Z_PARTIAL_FLUSH=1;
- private const int Z_SYNC_FLUSH=2;
- private const int Z_FULL_FLUSH=3;
- private const int Z_FINISH=4;
- private const int MAX_MEM_LEVEL=9;
- private const int Z_OK=0;
- private const int Z_STREAM_END=1;
- private const int Z_NEED_DICT=2;
- private const int Z_ERRNO=-1;
- private const int Z_STREAM_ERROR=-2;
- private const int Z_DATA_ERROR=-3;
- private const int Z_MEM_ERROR=-4;
- private const int Z_BUF_ERROR=-5;
- private const int Z_VERSION_ERROR=-6;
- public byte[] next_in;
- public int next_in_index;
- public int avail_in;
- public long total_in;
- public byte[] next_out;
- public int next_out_index;
- public int avail_out;
- public long total_out;
- public String msg;
- internal Deflate dstate;
- internal Inflate istate;
- internal int data_type;
- public long adler;
- internal Adler32 _adler=new Adler32();
- public int inflateInit(){
- return inflateInit(DEF_WBITS);
- }
- public int inflateInit(bool nowrap){
- return inflateInit(DEF_WBITS, nowrap);
- }
- public int inflateInit(int w){
- return inflateInit(w, false);
- }
- public int inflateInit(int w, bool nowrap){
- istate=new Inflate();
- return istate.inflateInit(this, nowrap?-w:w);
- }
- public int inflate(int f){
- if(istate==null) return Z_STREAM_ERROR;
- return istate.inflate(this, f);
- }
- public int inflateEnd(){
- if(istate==null) return Z_STREAM_ERROR;
- int ret=istate.inflateEnd(this);
- istate = null;
- return ret;
- }
- public int inflateSync(){
- if(istate == null)
- return Z_STREAM_ERROR;
- return istate.inflateSync(this);
- }
- public int inflateSetDictionary(byte[] dictionary, int dictLength){
- if(istate == null)
- return Z_STREAM_ERROR;
- return istate.inflateSetDictionary(this, dictionary, dictLength);
- }
- public int deflateInit(int level){
- return deflateInit(level, MAX_WBITS);
- }
- public int deflateInit(int level, bool nowrap){
- return deflateInit(level, MAX_WBITS, nowrap);
- }
- public int deflateInit(int level, int bits){
- return deflateInit(level, bits, false);
- }
- public int deflateInit(int level, int bits, bool nowrap){
- dstate=new Deflate();
- return dstate.deflateInit(this, level, nowrap?-bits:bits);
- }
- public int deflate(int flush){
- if(dstate==null){
- return Z_STREAM_ERROR;
- }
- return dstate.deflate(this, flush);
- }
- public int deflateEnd(){
- if(dstate==null) return Z_STREAM_ERROR;
- int ret=dstate.deflateEnd();
- dstate=null;
- return ret;
- }
- public int deflateParams(int level, int strategy){
- if(dstate==null) return Z_STREAM_ERROR;
- return dstate.deflateParams(this, level, strategy);
- }
- public int deflateSetDictionary (byte[] dictionary, int dictLength){
- if(dstate == null)
- return Z_STREAM_ERROR;
- return dstate.deflateSetDictionary(this, dictionary, dictLength);
- }
-
-
-
-
- internal void flush_pending(){
- int len=dstate.pending;
- if(len>avail_out) len=avail_out;
- if(len==0) return;
- if(dstate.pending_buf.Length<=dstate.pending_out ||
- next_out.Length<=next_out_index ||
- dstate.pending_buf.Length<(dstate.pending_out+len) ||
- next_out.Length<(next_out_index+len)){
-
-
-
- }
- System.Array.Copy(dstate.pending_buf, dstate.pending_out,
- next_out, next_out_index, len);
- next_out_index+=len;
- dstate.pending_out+=len;
- total_out+=len;
- avail_out-=len;
- dstate.pending-=len;
- if(dstate.pending==0){
- dstate.pending_out=0;
- }
- }
-
-
-
-
-
- internal int read_buf(byte[] buf, int start, int size) {
- int len=avail_in;
- if(len>size) len=size;
- if(len==0) return 0;
- avail_in-=len;
- if(dstate.noheader==0) {
- adler=_adler.adler32(adler, next_in, next_in_index, len);
- }
- System.Array.Copy(next_in, next_in_index, buf, start, len);
- next_in_index += len;
- total_in += len;
- return len;
- }
- public void free(){
- next_in=null;
- next_out=null;
- msg=null;
- _adler=null;
- }
- }
- }
- #endif
|