本文整理匯總了C#中System.util.zlib.ZStream類的典型用法代碼示例。如果您正苦於以下問題:C# ZStream類的具體用法?C# ZStream怎麽用?C# ZStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ZStream類屬於System.util.zlib命名空間,在下文中一共展示了ZStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: deflate
internal int deflate(ZStream strm, int flush){
int old_flush;
if(flush>Z_FINISH || flush<0){
return Z_STREAM_ERROR;
}
if(strm.next_out == null ||
(strm.next_in == null && strm.avail_in != 0) ||
(status == FINISH_STATE && flush != Z_FINISH)) {
strm.msg=z_errmsg[Z_NEED_DICT-(Z_STREAM_ERROR)];
return Z_STREAM_ERROR;
}
if(strm.avail_out == 0){
strm.msg=z_errmsg[Z_NEED_DICT-(Z_BUF_ERROR)];
return Z_BUF_ERROR;
}
this.strm = strm; // just in case
old_flush = last_flush;
last_flush = flush;
// Write the zlib header
if(status == INIT_STATE) {
int header = (Z_DEFLATED+((w_bits-8)<<4))<<8;
int level_flags=((level-1)&0xff)>>1;
if(level_flags>3) level_flags=3;
header |= (level_flags<<6);
if(strstart!=0) header |= PRESET_DICT;
header+=31-(header % 31);
status=BUSY_STATE;
putShortMSB(header);
// Save the adler32 of the preset dictionary:
if(strstart!=0){
putShortMSB((int)(strm.adler>>16));
putShortMSB((int)(strm.adler&0xffff));
}
strm.adler=strm._adler.adler32(0, null, 0, 0);
}
// Flush as much pending output as possible
if(pending != 0) {
strm.flush_pending();
if(strm.avail_out == 0) {
//System.out.println(" avail_out==0");
// Since avail_out is 0, deflate will be called again with
// more output space, but possibly with both pending and
// avail_in equal to zero. There won't be anything to do,
// but this is not an error situation so make sure we
// return OK instead of BUF_ERROR at next call of deflate:
last_flush = -1;
return Z_OK;
}
// Make sure there is something to do and avoid duplicate consecutive
// flushes. For repeated and useless calls with Z_FINISH, we keep
// returning Z_STREAM_END instead of Z_BUFF_ERROR.
}
else if(strm.avail_in==0 && flush <= old_flush &&
flush != Z_FINISH) {
strm.msg=z_errmsg[Z_NEED_DICT-(Z_BUF_ERROR)];
return Z_BUF_ERROR;
}
// User must not provide more input after the first FINISH:
if(status == FINISH_STATE && strm.avail_in != 0) {
strm.msg=z_errmsg[Z_NEED_DICT-(Z_BUF_ERROR)];
return Z_BUF_ERROR;
}
// Start a new block or continue the current one.
if(strm.avail_in!=0 || lookahead!=0 ||
(flush != Z_NO_FLUSH && status != FINISH_STATE)) {
int bstate=-1;
switch(config_table[level].func){
case STORED:
bstate = deflate_stored(flush);
break;
case FAST:
bstate = deflate_fast(flush);
break;
case SLOW:
bstate = deflate_slow(flush);
break;
default:
break;
}
if (bstate==FinishStarted || bstate==FinishDone) {
status = FINISH_STATE;
}
if (bstate==NeedMore || bstate==FinishStarted) {
if(strm.avail_out == 0) {
last_flush = -1; // avoid BUF_ERROR next call, see above
}
return Z_OK;
//.........這裏部分代碼省略.........
示例2: init
internal void init(int bl, int bd,
int[] tl, int tl_index,
int[] td, int td_index, ZStream z)
{
mode=START;
lbits=(byte)bl;
dbits=(byte)bd;
ltree=tl;
ltree_index=tl_index;
dtree = td;
dtree_index=td_index;
tree=null;
}
示例3: inflateSyncPoint
// Returns true if inflate is currently at the end of a block generated
// by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
// implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
// but removes the length bytes of the resulting empty stored block. When
// decompressing, PPP checks that at the end of input packet, inflate is
// waiting for these length bytes.
internal int inflateSyncPoint(ZStream z){
if(z == null || z.istate == null || z.istate.blocks == null)
return Z_STREAM_ERROR;
return z.istate.blocks.sync_point();
}
示例4: free
internal void free(ZStream z)
{
// ZFREE(z, c);
}
示例5: inflateInit
internal int inflateInit(ZStream z, int w){
z.msg = null;
blocks = null;
// handle undocumented nowrap option (no zlib header or check)
nowrap = 0;
if(w < 0){
w = - w;
nowrap = 1;
}
// set window size
if(w<8 ||w>15){
inflateEnd(z);
return Z_STREAM_ERROR;
}
wbits=w;
z.istate.blocks=new InfBlocks(z,
z.istate.nowrap!=0 ? null : this,
1<<w);
// reset state
inflateReset(z);
return Z_OK;
}
示例6: inflateSetDictionary
internal int inflateSetDictionary(ZStream z, byte[] dictionary, int dictLength){
int index=0;
int length = dictLength;
if(z==null || z.istate == null|| z.istate.mode != DICT0)
return Z_STREAM_ERROR;
if(z._adler.adler32(1L, dictionary, 0, dictLength)!=z.adler){
return Z_DATA_ERROR;
}
z.adler = z._adler.adler32(0, null, 0, 0);
if(length >= (1<<z.istate.wbits)){
length = (1<<z.istate.wbits)-1;
index=dictLength - length;
}
z.istate.blocks.set_dictionary(dictionary, index, length);
z.istate.mode = BLOCKS;
return Z_OK;
}
示例7: inflate_trees_dynamic
internal int inflate_trees_dynamic(int nl, // number of literal/length codes
int nd, // number of distance codes
int[] c, // that many (total) code lengths
int[] bl, // literal desired/actual bit depth
int[] bd, // distance desired/actual bit depth
int[] tl, // literal/length tree result
int[] td, // distance tree result
int[] hp, // space for trees
ZStream z // for messages
){
int result;
// build literal/length tree
initWorkArea(288);
hn[0]=0;
result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
if (result != Z_OK || bl[0] == 0){
if(result == Z_DATA_ERROR){
z.msg = "oversubscribed literal/length tree";
}
else if (result != Z_MEM_ERROR){
z.msg = "incomplete literal/length tree";
result = Z_DATA_ERROR;
}
return result;
}
// build distance tree
initWorkArea(288);
result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
if (result != Z_OK || (bd[0] == 0 && nl > 257)){
if (result == Z_DATA_ERROR){
z.msg = "oversubscribed distance tree";
}
else if (result == Z_BUF_ERROR) {
z.msg = "incomplete distance tree";
result = Z_DATA_ERROR;
}
else if (result != Z_MEM_ERROR){
z.msg = "empty distance tree with lengths";
result = Z_DATA_ERROR;
}
return result;
}
return Z_OK;
}
示例8: inflate_trees_fixed
internal static int inflate_trees_fixed(int[] bl, //literal desired/actual bit depth
int[] bd, //distance desired/actual bit depth
int[][] tl,//literal/length tree result
int[][] td,//distance tree result
ZStream z //for memory allocation
){
bl[0]=fixed_bl;
bd[0]=fixed_bd;
tl[0]=fixed_tl;
td[0]=fixed_td;
return Z_OK;
}
示例9: inflate_trees_bits
internal int inflate_trees_bits(int[] c, // 19 code lengths
int[] bb, // bits tree desired/actual depth
int[] tb, // bits tree result
int[] hp, // space for trees
ZStream z // for messages
){
int result;
initWorkArea(19);
hn[0]=0;
result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
if(result == Z_DATA_ERROR){
z.msg = "oversubscribed dynamic bit lengths tree";
}
else if(result == Z_BUF_ERROR || bb[0] == 0){
z.msg = "incomplete dynamic bit lengths tree";
result = Z_DATA_ERROR;
}
return result;
}
示例10: deflateInit
internal int deflateInit(ZStream strm, int level, int bits){
return deflateInit2(strm, level, Z_DEFLATED, bits, DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY);
}
示例11: inflateEnd
internal int inflateEnd(ZStream z){
if(blocks != null)
blocks.free(z);
blocks=null;
// ZFREE(z, z->state);
return Z_OK;
}
示例12: inflate
internal int inflate(ZStream z, int f){
int r;
int b;
if(z == null || z.istate == null || z.next_in == null)
return Z_STREAM_ERROR;
f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
r = Z_BUF_ERROR;
while (true){
//System.out.println("mode: "+z.istate.mode);
switch (z.istate.mode){
case METHOD:
if(z.avail_in==0)return r;r=f;
z.avail_in--; z.total_in++;
if(((z.istate.method = z.next_in[z.next_in_index++])&0xf)!=Z_DEFLATED){
z.istate.mode = BAD;
z.msg="unknown compression method";
z.istate.marker = 5; // can't try inflateSync
break;
}
if((z.istate.method>>4)+8>z.istate.wbits){
z.istate.mode = BAD;
z.msg="invalid window size";
z.istate.marker = 5; // can't try inflateSync
break;
}
z.istate.mode=FLAG;
goto case FLAG;
case FLAG:
if(z.avail_in==0)return r;r=f;
z.avail_in--; z.total_in++;
b = (z.next_in[z.next_in_index++])&0xff;
if((((z.istate.method << 8)+b) % 31)!=0){
z.istate.mode = BAD;
z.msg = "incorrect header check";
z.istate.marker = 5; // can't try inflateSync
break;
}
if((b&PRESET_DICT)==0){
z.istate.mode = BLOCKS;
break;
}
z.istate.mode = DICT4;
goto case DICT4;
case DICT4:
if(z.avail_in==0)return r;r=f;
z.avail_in--; z.total_in++;
z.istate.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L;
z.istate.mode=DICT3;
goto case DICT3;
case DICT3:
if(z.avail_in==0)return r;r=f;
z.avail_in--; z.total_in++;
z.istate.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L;
z.istate.mode=DICT2;
goto case DICT2;
case DICT2:
if(z.avail_in==0)return r;r=f;
z.avail_in--; z.total_in++;
z.istate.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L;
z.istate.mode=DICT1;
goto case DICT1;
case DICT1:
if(z.avail_in==0)return r;r=f;
z.avail_in--; z.total_in++;
z.istate.need += (z.next_in[z.next_in_index++]&0xffL);
z.adler = z.istate.need;
z.istate.mode = DICT0;
return Z_NEED_DICT;
case DICT0:
z.istate.mode = BAD;
z.msg = "need dictionary";
z.istate.marker = 0; // can try inflateSync
return Z_STREAM_ERROR;
case BLOCKS:
r = z.istate.blocks.proc(z, r);
if(r == Z_DATA_ERROR){
z.istate.mode = BAD;
z.istate.marker = 0; // can try inflateSync
break;
}
if(r == Z_OK){
r = f;
}
if(r != Z_STREAM_END){
//.........這裏部分代碼省略.........
示例13: deflateInit2
internal int deflateInit2(ZStream strm, int level, int method, int windowBits,
int memLevel, int strategy){
int noheader = 0;
// byte[] my_version=ZLIB_VERSION;
//
// if (version == null || version[0] != my_version[0]
// || stream_size != sizeof(z_stream)) {
// return Z_VERSION_ERROR;
// }
strm.msg = null;
if (level == Z_DEFAULT_COMPRESSION) level = 6;
if (windowBits < 0) { // undocumented feature: suppress zlib header
noheader = 1;
windowBits = -windowBits;
}
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL ||
method != Z_DEFLATED ||
windowBits < 9 || windowBits > 15 || level < 0 || level > 9 ||
strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
return Z_STREAM_ERROR;
}
strm.dstate = (Deflate)this;
this.noheader = noheader;
w_bits = windowBits;
w_size = 1 << w_bits;
w_mask = w_size - 1;
hash_bits = memLevel + 7;
hash_size = 1 << hash_bits;
hash_mask = hash_size - 1;
hash_shift = ((hash_bits+MIN_MATCH-1)/MIN_MATCH);
window = new byte[w_size*2];
prev = new short[w_size];
head = new short[hash_size];
lit_bufsize = 1 << (memLevel + 6); // 16K elements by default
// We overlay pending_buf and d_buf+l_buf. This works since the average
// output size for (length,distance) codes is <= 24 bits.
pending_buf = new byte[lit_bufsize*4];
pending_buf_size = lit_bufsize*4;
d_buf = lit_bufsize/2;
l_buf = (1+2)*lit_bufsize;
this.level = level;
//System.out.println("level="+level);
this.strategy = strategy;
this.method = (byte)method;
return deflateReset(strm);
}
示例14: inflateSync
internal int inflateSync(ZStream z){
int n; // number of bytes to look at
int p; // pointer to bytes
int m; // number of marker bytes found in a row
long r, w; // temporaries to save total_in and total_out
// set up
if(z == null || z.istate == null)
return Z_STREAM_ERROR;
if(z.istate.mode != BAD){
z.istate.mode = BAD;
z.istate.marker = 0;
}
if((n=z.avail_in)==0)
return Z_BUF_ERROR;
p=z.next_in_index;
m=z.istate.marker;
// search
while (n!=0 && m < 4){
if(z.next_in[p] == mark[m]){
m++;
}
else if(z.next_in[p]!=0){
m = 0;
}
else{
m = 4 - m;
}
p++; n--;
}
// restore
z.total_in += p-z.next_in_index;
z.next_in_index = p;
z.avail_in = n;
z.istate.marker = m;
// return no joy or set up to restart on a new block
if(m != 4){
return Z_DATA_ERROR;
}
r=z.total_in; w=z.total_out;
inflateReset(z);
z.total_in=r; z.total_out = w;
z.istate.mode = BLOCKS;
return Z_OK;
}
示例15: deflateReset
internal int deflateReset(ZStream strm){
strm.total_in = strm.total_out = 0;
strm.msg = null; //
strm.data_type = Z_UNKNOWN;
pending = 0;
pending_out = 0;
if(noheader < 0) {
noheader = 0; // was set to -1 by deflate(..., Z_FINISH);
}
status = (noheader!=0) ? BUSY_STATE : INIT_STATE;
strm.adler=strm._adler.adler32(0, null, 0, 0);
last_flush = Z_NO_FLUSH;
tr_init();
lm_init();
return Z_OK;
}