当前位置: 首页>>代码示例>>C#>>正文


C# CompressionMode类代码示例

本文整理汇总了C#中CompressionMode的典型用法代码示例。如果您正苦于以下问题:C# CompressionMode类的具体用法?C# CompressionMode怎么用?C# CompressionMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CompressionMode类属于命名空间,在下文中一共展示了CompressionMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeflateStream

        public DeflateStream(Stream stream, CompressionMode mode, bool leaveOpen)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");
            
            switch (mode)
            {
                case CompressionMode.Decompress:
                    if (!stream.CanRead)
                    {
                        throw new ArgumentException(SR.NotReadableStream, "stream");
                    }
                    _inflater = CreateInflater();
                    break;

                case CompressionMode.Compress:
                    if (!stream.CanWrite)
                    {
                        throw new ArgumentException(SR.NotWriteableStream, "stream");
                    }
                    _deflater = CreateDeflater(null);
                    break;

                default:
                    throw new ArgumentException(SR.ArgumentOutOfRange_Enum, "mode");
            }

            _stream = stream;
            _mode = mode;
            _leaveOpen = leaveOpen;
            _buffer = new byte[DefaultBufferSize];
        }
开发者ID:hyjiacan,项目名称:corefx,代码行数:32,代码来源:DeflateStream.cs

示例2: LZ4NetStream

        internal LZ4NetStream(Stream innerStream, CompressionMode compressionMode, bool leaveInnerStreamOpen,
                              LZ4Codec codec)
        {
            if (innerStream == null)
            {
                throw new ArgumentNullException(nameof(innerStream));
            }
            switch (compressionMode)
            {
            case CompressionMode.Compress:
            case CompressionMode.Decompress:
                break;
            default:
                throw new ArgumentOutOfRangeException(nameof(compressionMode));
            }
            if (codec == null)
            {
                throw new ArgumentNullException(nameof(codec));
            }

            this.innerStream = innerStream;
            this.compressionMode = compressionMode;
            this.leaveInnerStreamOpen = leaveInnerStreamOpen;
            this.codec = codec;
        }
开发者ID:darting,项目名称:MetricSystem,代码行数:25,代码来源:LZ4NetStream.cs

示例3: TextureNative

        public TextureNative(SectionHeader header, Stream stream)
            : base(header, stream)
        {
            SectionHeader.Read(stream);
            var reader = new BinaryReader(stream);

            PlatformID = reader.ReadUInt32();
            FilterFlags = (Filter) reader.ReadUInt16();
            WrapV = (WrapMode) reader.ReadByte();
            WrapU = (WrapMode) reader.ReadByte();
            DiffuseName = reader.ReadString(32);
            AlphaName = reader.ReadString(32);
            Format = (RasterFormat) reader.ReadUInt32();

            if (PlatformID == 9) {
                var dxt = reader.ReadString(4);
                switch (dxt) {
                    case "DXT1":
                        Compression = CompressionMode.DXT1;
                        break;
                    case "DXT3":
                        Compression = CompressionMode.DXT3; break;
                    default:
                        Compression = CompressionMode.None; break;
                }
            } else {
                Alpha = reader.ReadUInt32() == 0x1;
            }

            Width = reader.ReadUInt16();
            Height = reader.ReadUInt16();
            BPP = (byte) (reader.ReadByte() >> 3);
            MipMapCount = reader.ReadByte();
            RasterType = reader.ReadByte();

            if (RasterType != 0x4) {
                throw new Exception("Unexpected RasterType, expected 0x04.");
            }

            if (PlatformID == 9) {
                Alpha = (reader.ReadByte() & 0x1) == 0x1;
            } else {
                Compression = (CompressionMode) reader.ReadByte();
            }

            ImageDataSize = reader.ReadInt32();

            ImageData = reader.ReadBytes(ImageDataSize);

            if ((Format & RasterFormat.ExtMipMap) != 0) {
                var tot = ImageDataSize;
                for (var i = 0; i < MipMapCount; ++i) {
                    tot += ImageDataSize >> (2 * i);
                }

                ImageLevelData = reader.ReadBytes(tot);
            } else {
                ImageLevelData = ImageData;
            }
        }
开发者ID:katalist5296,项目名称:SanAndreasUnity,代码行数:60,代码来源:TextureNative.cs

示例4: SnappyStream

        /// <summary>
        /// Initializes a new instance of the <see cref="SnappyStream"/> class.
        /// </summary>
        /// <param name="s">The stream.</param>
        /// <param name="mode">The compression mode.</param>
        /// <param name="leaveOpen">If set to <c>true</c> leaves the stream open when complete.</param>
        /// <param name="checksum"><c>true</c> if checksums should be written to the stream </param>
        public SnappyStream(Stream s, CompressionMode mode, bool leaveOpen, bool checksum)
        {
            stream = s;
            compressionMode = mode;
            leaveStreamOpen = leaveOpen;
            writeChecksums = checksum;

            if (compressionMode == CompressionMode.Decompress)
            {
                if (!stream.CanRead)
                    throw new InvalidOperationException("Trying to decompress and underlying stream not readable.");

                decompressor =  new SnappyDecompressor();

                CheckStreamIdentifier();
                CheckStreamHeader();
            }
            if (compressionMode == CompressionMode.Compress)
            {
                if (!stream.CanWrite)
                    throw new InvalidOperationException("Trying to compress and underlying stream is not writable.");

                compressor = new SnappyCompressor();

                stream.WriteByte(StreamIdentifier);
                stream.Write(StreamHeader, 0, StreamHeader.Length);
            }
        }
开发者ID:cicorias,项目名称:Snappy.Sharp,代码行数:35,代码来源:SnappyStream.cs

示例5: ZlibStreamConstructorTest

 public void ZlibStreamConstructorTest()
 {
     Stream stream = null; // TODO: Initialize to an appropriate value
     CompressionMode mode = new CompressionMode(); // TODO: Initialize to an appropriate value
     ZlibStream target = new ZlibStream(stream, mode);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
开发者ID:delfinof,项目名称:ssh.net,代码行数:7,代码来源:ZlibStreamTest.cs

示例6: BufferedDeflateStream

 public BufferedDeflateStream( int bufferSize, Stream stream, CompressionMode mode, bool leaveOpen )
     : base(stream, mode, leaveOpen)
 {
     buffer = new byte[ bufferSize ];
       bSize  = bufferSize;
       bPtr   = 0;
 }
开发者ID:bzamecnik,项目名称:grcis,代码行数:7,代码来源:BufferedDeflateStream.cs

示例7: ZOutputStream

 public ZOutputStream(Stream output, CompressionLevel level, bool nowrap)
     : this()
 {
     this._output = output;
     this._compressor = new Deflate(level, nowrap);
     this._compressionMode = CompressionMode.Compress;
 }
开发者ID:imbavirus,项目名称:TrinityCoreAdmin,代码行数:7,代码来源:ZOutputStream.cs

示例8: DeflateStream

        internal DeflateStream(Stream stream, CompressionMode mode, bool leaveOpen, bool usingGZip){                                                                                          
            _stream = stream;
            _mode = mode;
            _leaveOpen = leaveOpen;

            if(_stream == null ) {
                throw new ArgumentNullException("stream");
            }

            switch (_mode) {
            case CompressionMode.Decompress:
                if (!(_stream.CanRead)) {
                    throw new ArgumentException(SR.GetString(SR.NotReadableStream), "stream");
                }
                inflater = new Inflater(usingGZip);
                m_CallBack = new AsyncCallback(ReadCallback); 
                break;

            case CompressionMode.Compress:
                if (!(_stream.CanWrite)) {
                    throw new ArgumentException(SR.GetString(SR.NotWriteableStream), "stream");
                }
                deflater = new Deflater(usingGZip);
                m_AsyncWriterDelegate = new AsyncWriteDelegate(this.InternalWrite);
                m_CallBack = new AsyncCallback(WriteCallback); 
                break;    

            default:
                throw new ArgumentException(SR.GetString(SR.ArgumentOutOfRange_Enum), "mode");
            }           
            buffer = new byte[bufferSize];
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:32,代码来源:deflatestream.cs

示例9: DeflateStream

        internal DeflateStream(Stream stream, CompressionMode mode, bool leaveOpen, bool usingGZip)
        {
            this._stream = stream;
            this._mode = mode;
            this._leaveOpen = leaveOpen;
            if (this._stream == null) {
                throw new ArgumentNullException("stream");
            }
            switch (this._mode) {
                case CompressionMode.Decompress:
                    if (!this._stream.CanRead) {
                        throw new ArgumentException("The base stream is not readable.", "stream");
                    }
                    this.inflater = new Inflater(usingGZip);
                    this.m_CallBack = new AsyncCallback(this.ReadCallback);
                    break;

                case CompressionMode.Compress:
                    if (!this._stream.CanWrite) {
                        throw new ArgumentException("The base stream is not writeable.", "stream");
                    }
                    this.deflater = new Deflater(usingGZip);
                    this.m_AsyncWriterDelegate = new AsyncWriteDelegate(this.InternalWrite);
                    this.m_CallBack = new AsyncCallback(this.WriteCallback);
                    break;

                default:
                    throw new ArgumentException("Enum value was out of legal range.", "mode");
            }
            this.buffer = new byte[0x1000];
        }
开发者ID:lovenets,项目名称:hprose-dotnet,代码行数:31,代码来源:DeflateStream.cs

示例10: toCompressStream

 /// <summary>
 /// 根据压缩类型获取压缩数据流
 /// </summary>
 /// <param name="dataStream">原始数据流</param>
 /// <param name="mode">压缩模式</param>
 /// <param name="leaveOpen">是否流保留为打开状态</param>
 /// <param name="type">压缩类型</param>
 /// <returns>数据流</returns>
 private static Stream toCompressStream(this Stream dataStream, CompressionMode mode, bool leaveOpen, compression type)
 {
     Stream stream = dataStream;
     if (type == compression.GZip) stream = (Stream)new GZipStream(dataStream, mode, leaveOpen);
     else stream = (Stream)new DeflateStream(dataStream, mode, leaveOpen);
     return stream;
 }
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:15,代码来源:stream.cs

示例11: DeflateStream

        public DeflateStream(Stream stream, CompressionMode mode, bool leaveOpen)
        {
            this._stream = stream;
            this._mode = mode;
            this._leaveOpen = leaveOpen;
            if (this._stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            switch (this._mode)
            {
                case CompressionMode.Decompress:
                    if (!this._stream.CanRead)
                    {
                        throw new ArgumentException(SR.GetString("NotReadableStream"), "stream");
                    }
                    this.inflater = new Inflater();
                    this.m_CallBack = new AsyncCallback(this.ReadCallback);
                    break;

                case CompressionMode.Compress:
                    if (!this._stream.CanWrite)
                    {
                        throw new ArgumentException(SR.GetString("NotWriteableStream"), "stream");
                    }
                    this.deflater = new Deflater();
                    this.m_AsyncWriterDelegate = new AsyncWriteDelegate(this.InternalWrite);
                    this.m_CallBack = new AsyncCallback(this.WriteCallback);
                    break;

                default:
                    throw new ArgumentException(SR.GetString("ArgumentOutOfRange_Enum"), "mode");
            }
            this.buffer = new byte[0x1000];
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:35,代码来源:DeflateStream.cs

示例12: DeflateStream

		internal DeflateStream (Stream compressedStream, CompressionMode mode, bool leaveOpen, bool gzip) {
			if (compressedStream == null)
				throw new ArgumentNullException ("compressedStream");

			switch (mode) {
			case CompressionMode.Compress:
				if (!compressedStream.CanWrite)
					throw new ArgumentException ("The base stream is not writeable.");
				OutputStream outStream = new OutputStreamImpl(compressedStream);
				_writer = gzip ? new GZIPOutputStream (outStream) : new DeflaterOutputStream (outStream, new Deflater (Deflater.DEFAULT_COMPRESSION, true));
				break;
			case CompressionMode.Decompress:
				if (!compressedStream.CanRead)
					throw new ArgumentException ("The base stream is not readable.");
				InputStream inStream = new InputStreamImpl (compressedStream);
				_reader = gzip ? new GZIPInputStream (inStream) : new InflaterInputStream (inStream, new Inflater (true));
				break;
			default:
				throw new ArgumentException ("mode");
			}

			_baseStream = compressedStream;
			_leaveOpen = leaveOpen;
			_open = true;
		}
开发者ID:carrie901,项目名称:mono,代码行数:25,代码来源:DefalteStream.jvm.cs

示例13: zlibDeflate

 public static void zlibDeflate(
     string pathInput,
     string pathOutput,
     CompressionMode mode,
     CompressionLevel level
 )
 {
     using (Stream input = File.OpenRead(pathInput))
     using (Stream output = File.Create(pathOutput))
     using (Stream deflateStream = new DeflateStream(
         mode == CompressionMode.Compress ? output : input,
         mode, level, true))
     {
         byte[] buff = new byte[ZLIB_BUFF_SIZE];
         int n = 0;
         Stream toRead = mode == CompressionMode.Compress ?
             input : deflateStream;
         Stream toWrite = mode == CompressionMode.Compress ?
             deflateStream : output;
         while (0 != (n = toRead.Read(buff, 0, buff.Length)))
         {
             toWrite.Write(buff, 0, n);
         }
         deflateStream.Close();
         input.Close();
         output.Close();
     }
 }
开发者ID:alejandro-varela,项目名称:AleNet,代码行数:28,代码来源:ZlibHelper.cs

示例14: ZlibBaseStream

 public ZlibBaseStream(System.IO.Stream stream,
                       CompressionMode compressionMode,
                       CompressionLevel level,
                       ZlibStreamFlavor flavor,
                       bool leaveOpen)
     :this(stream, compressionMode, level, flavor,leaveOpen, ZlibConstants.WindowBitsDefault)
 { }
开发者ID:JohnMalmsteen,项目名称:mobile-apps-tower-defense,代码行数:7,代码来源:ZlibBaseStream.cs

示例15: CompressedStream

 /// <summary>
 /// 
 /// </summary>
 /// <param name="contentEncoding"></param>
 /// <param name="stream"></param>
 /// <param name="mode"></param>
 public CompressedStream(string contentEncoding, Stream stream, CompressionMode mode)
 {
     if (contentEncoding.IndexOf(_contentIsGZipToken, StringComparison.InvariantCultureIgnoreCase) != -1)
         _gzipStream = new GZipStream(stream, mode);
     else if (contentEncoding != null && contentEncoding.IndexOf(_contentIsDeflateToken, StringComparison.InvariantCultureIgnoreCase) != -1)
         _deflateStream = new DeflateStream(stream, mode);
 }
开发者ID:CalypsoSys,项目名称:Babalu_rProxy,代码行数:13,代码来源:CompressedStream.cs


注:本文中的CompressionMode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。