• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# CompressionMode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: LZ4Stream

        /// <summary>Initializes a new instance of the <see cref="LZ4Stream" /> class.</summary>
        /// <param name="innerStream">The inner stream.</param>
        /// <param name="compressionMode">The compression mode.</param>
        /// <param name="highCompression">if set to <c>true</c> [high compression].</param>
        /// <param name="blockSize">Size of the block.</param>
        public LZ4Stream(
			Stream innerStream,
			CompressionMode compressionMode,
			bool highCompression = false,
			int blockSize = 1024*1024)
            : this(innerStream, ToLZ4StreamMode(compressionMode), highCompression, blockSize)
        {
        }
开发者ID:robervkts,项目名称:lz4net,代码行数:13,代码来源:LZ4Stream.windows.cs


示例17: SforceServiceWrapper

        /// <summary>
        /// This constructor will create a request that has has it's initial compression
        /// attributes set to the parameter values.
        /// </summary>
        /// <param name="responseCompression">
        /// Set to true to send a zipped request, false to send plain response.
        /// </param>
        /// <param name="requestCompression">
        /// Set to Automatic to use automatic acceptance of zipped/uncompressed response (accept zipped in most cases), Plain to accept plain responses only.
        /// </param>
        public SforceServiceWrapper(CompressionMode requestCompression, CompressionMode responseCompression)
        {
            RequestCompression = requestCompression;
            ResponseCompression = responseCompression;

            this.EnableDecompression = true;
            this.Timeout = soapTimeout;
        }
开发者ID:ianhuang,项目名称:SFDC-Net-Connector,代码行数:18,代码来源:SforceServiceWrapper.cs


示例18: ZlibStream

        /// <summary>
        /// Initializes a new instance of the <see cref="ZlibStream"/> class by using the specified stream and compression mode, and optionally leaves the stream open.
        /// </summary>
        /// <param name="stream">The stream to compress or decompress.</param>
        /// <param name="mode">One of the enumeration values that indicates whether to compress or decompress the stream.</param>
        /// <param name="leaveOpen">true to leave the stream open after disposing the DeflateStream object; otherwise, false.</param>
        public ZlibStream(Stream stream, CompressionMode mode, bool leaveOpen)
            : base(stream, mode, true)
        {
            _stream = stream;
            _leaveOpen = leaveOpen;

            WriteHeader();
        }
开发者ID:HimanshPal,项目名称:Cimbalino-Toolkit,代码行数:14,代码来源:ZlibStream.cs


示例19: GZipStream

 /// <summary>Create a <c>GZipStream</c> using the specified <c>CompressionMode</c> and the specified <c>CompressionLevel</c>, and explicitly specify whether the stream should be left open after Deflation or Inflation.</summary>
 /// <remarks><para>This constructor allows the application to request that the captive stream remain open after the deflation or inflation occurs.  By default, after<c>Close()</c> is called on the stream, the captive stream is also closed. In some cases this is not desired, for example if the stream is a memory stream that will be re-read after compressed data has been written to it.  Specify true for the <paramref name="leaveOpen" /> parameter to leave the stream open.</para><para>As noted in the class documentation, the <c>CompressionMode</c> (Compress or Decompress) also establishes the "direction" of the stream.  A<c>GZipStream</c> with <c>CompressionMode.Compress</c> works only through<c>Write()</c>.  A <c>GZipStream</c> with <c>CompressionMode.Decompress</c> works only through <c>Read()</c>.</para></remarks>
 /// <example>
 ///   This example shows how to use a <c>GZipStream</c> to compress data.
 ///   <code>using (System.IO.Stream input = System.IO.File.OpenRead(fileToCompress)) { using (var raw = System.IO.File.Create(outputFile)) { using (Stream compressor = new GZipStream(raw, CompressionMode.Compress, CompressionLevel.BestCompression, true)) { byte[] buffer = new byte[WORKING_BUFFER_SIZE]; int n; while ((n= input.Read(buffer, 0, buffer.Length)) != 0) { compressor.Write(buffer, 0, n); } } } }</code>
 ///   <code lang = "VB">
 ///     Dim outputFile As String = (fileToCompress &amp; ".compressed") Using input As Stream =
 ///     File.OpenRead(fileToCompress) Using raw As FileStream = File.Create(outputFile) Using compressor As
 ///     Stream = New GZipStream(raw, CompressionMode.Compress, CompressionLevel.BestCompression, True) Dim
 ///     buffer As Byte() = New Byte(4096) {} Dim n As Integer = -1 Do While (n &lt;&gt; 0) If (n &gt; 0) Then
 ///     compressor.Write(buffer, 0, n) End If n = input.Read(buffer, 0, buffer.Length) Loop End Using End Using
 ///     End Using
 ///   </code>
 /// </example>
 /// <param name="stream">The stream which will be read or written.</param>
 /// <param name="mode">Indicates whether the GZipStream will compress or decompress.</param>
 /// <param name="level">A tuning knob to trade speed for effectiveness.</param>
 /// <param name="leaveOpen">true if the application would like the stream to remain open after inflation/deflation.</param>
 public GZipStream(
     Stream stream, 
     CompressionMode mode, 
     CompressionLevel level = CompressionLevel.Default, 
     bool leaveOpen = false)
 {
     this.baseStream = new ZlibBaseStream(stream, mode, level, ZlibStreamFlavor.Gzip, leaveOpen);
 }
开发者ID:robertbaker,项目名称:SevenUpdate,代码行数:26,代码来源:GZipStream.cs


示例20: BuildStrategy

 public static IInitStrategy BuildStrategy(CompressionMode mode)
 {
     switch (mode)
     {
         case CompressionMode.Compress: return new CompressInit();
         case CompressionMode.Decompress: return new DecompressInit();
         default: throw new ArgumentOutOfRangeException("mode");
     }
 }
开发者ID:vladimir-shmidt,项目名称:GZipFileCompressor,代码行数:9,代码来源:InitStrategyFactory.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CompressionStrategy类代码示例发布时间:2022-05-24
下一篇:
C# CompressionMethod类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap