deflateEnd() 공개 메소드

All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending output.
public deflateEnd ( ) : int
리턴 int
예제 #1
0
파일: zlib.cs 프로젝트: david50407/main
            internal static int Process(zlib.ZStream /*!*/ zst, MutableString str, zlib.FlushStrategy flush, bool compress,
                                        out MutableString /*!*/ result, ref MutableString trailingUncompressedData)
            {
                result = MutableString.CreateBinary();

                // add previously compressed data to the output:
                if (zst.next_out != null)
                {
                    result.Append(zst.next_out, 0, zst.next_out_index);
                }

                int err;
                int bufferStart = zst.next_out_index;

                err = Process(zst, str, flush, compress, ref trailingUncompressedData);
                result.Append(zst.next_out, bufferStart, zst.next_out_index - bufferStart);

                if (err == Z_STREAM_END && (flush == zlib.FlushStrategy.Z_FINISH || str == null))
                {
                    err = compress ? zst.deflateEnd() : zst.inflateEnd();
                }

                zst.next_out       = null;
                zst.next_out_index = 0;
                zst.avail_out      = 0;

                return(err);
            }
예제 #2
0
 /// <summary>
 /// Frees allocated resources.
 /// </summary>
 public void End()
 {
     z.deflateEnd();
     z.free();
     z = null;
 }
예제 #3
0
        public static string compress([BytesConversion]IList<byte> data,
            [DefaultParameterValue(Z_DEFAULT_COMPRESSION)]int level)
        {
            byte[] input = data.ToArray();
            byte[] output = new byte[input.Length + input.Length / 1000 + 12 + 1];

            ZStream zst = new ZStream();
            zst.next_in = input;
            zst.avail_in = input.Length;
            zst.next_out = output;
            zst.avail_out = output.Length;

            int err = zst.deflateInit(level);
            switch(err)
            {
                case (Z_OK):
                    break;
                
                case (Z_STREAM_ERROR):
                    throw PythonOps.CreateThrowable(error,
                                    "Bad compression level");
                
                default:
                    zst.deflateEnd();
                    zlib_error(zst, err, "while compressing data");
                    return null;
            }

            err = zst.deflate(FlushStrategy.Z_FINISH);

            if(err != Z_STREAM_END)
            {
                zst.deflateEnd();
                throw zlib_error(zst, err, "while compressing data");
            }

            err = zst.deflateEnd();

            if(err == Z_OK)
                return PythonAsciiEncoding.Instance.GetString(output, 0, (int)zst.total_out);
            else
                throw zlib_error(zst, err, "while finishing compression");
        }