當前位置: 首頁>>代碼示例>>C#>>正文


C# ZStream.flush_pending方法代碼示例

本文整理匯總了C#中System.util.zlib.ZStream.flush_pending方法的典型用法代碼示例。如果您正苦於以下問題:C# ZStream.flush_pending方法的具體用法?C# ZStream.flush_pending怎麽用?C# ZStream.flush_pending使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.util.zlib.ZStream的用法示例。


在下文中一共展示了ZStream.flush_pending方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
//.........這裏部分代碼省略.........
開發者ID:nicecai,項目名稱:iTextSharp-4.1.6,代碼行數:101,代碼來源:Deflate.cs


注:本文中的System.util.zlib.ZStream.flush_pending方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。