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


C# DeflateStream.Read方法代码示例

本文整理汇总了C#中System.IO.Compression.DeflateStream.Read方法的典型用法代码示例。如果您正苦于以下问题:C# DeflateStream.Read方法的具体用法?C# DeflateStream.Read怎么用?C# DeflateStream.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Compression.DeflateStream的用法示例。


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

示例1: DeflateDecompress

        /// <summary>
        ///     The GZIP decompress.
        /// </summary>
        /// <param name="data">The data to decompress.</param>
        /// <returns>The decompressed data</returns>
        public static byte[] DeflateDecompress(this byte[] data)
        {
            byte[] bytes = null;
            if (data != null)
            {
                using (var input = new MemoryStream(data.Length))
                {
                    input.Write(data, 0, data.Length);
                    input.Position = 0;

                    var gzip = new DeflateStream(input, CompressionMode.Decompress);

                    using (var output = new MemoryStream(data.Length))
                    {
                        var buff = new byte[64];
                        int read = gzip.Read(buff, 0, buff.Length);

                        while (read > 0)
                        {
                            output.Write(buff, 0, buff.Length);
                            read = gzip.Read(buff, 0, buff.Length);
                        }

                        bytes = output.ToArray();
                    }
                }
            }

            return bytes;
        }
开发者ID:MGramolini,项目名称:vodca,代码行数:35,代码来源:Extensions.Compression.Deflate.cs

示例2: Decompress

        public byte[] Decompress(byte[] raw, int offset, int count)
        {
            var buffer = _bufferAllocator.BorrowBuffer();

            try
            {
                using (var input = new MemoryStream(raw, offset, count))
                using (var deflate = new DeflateStream(input, CompressionMode.Decompress, leaveOpen: true))
                using (var memory = new MemoryStream())
                {
                    int readCount = 0;
                    do
                    {
                        readCount = deflate.Read(buffer, 0, buffer.Length);
                        if (readCount > 0)
                        {
                            memory.Write(buffer, 0, readCount);
                        }
                    }
                    while (readCount > 0);

                    return memory.ToArray();
                }
            }
            finally
            {
                _bufferAllocator.ReturnBuffer(buffer);
            }
        }
开发者ID:cube3power,项目名称:Cowboy,代码行数:29,代码来源:DeflateCompression.cs

示例3: Decrypt

        public static StreamReader Decrypt(string source, int key)
        {
            byte[] data = System.Convert.FromBase64String(source);

            byte[] dec = AES.DecryptData(data, GetTrueKey(key), key.ToString() + "P8xvDLzPHvNiwVMkS3kPzQStAEDqdTMD", System.Security.Cryptography.PaddingMode.ISO10126);

            int d_len = System.BitConverter.ToInt32(dec, 40);

            MemoryStream ms = new MemoryStream(dec);
            ms.Position = 44;
            // Use the newly created memory stream for the compressed data.
            DeflateStream compressedzipStream = new DeflateStream(ms, CompressionMode.Decompress, true);
            //Console.WriteLine("Compression");
            byte[] zdec = new byte[d_len];
            int cnt = compressedzipStream.Read(zdec, 0, d_len);
            // Close the stream.
            compressedzipStream.Close();

            dec = new byte[cnt];
            System.Array.ConstrainedCopy(zdec, 0, dec, 0, cnt);

            MemoryStream mem_stream = new System.IO.MemoryStream(dec);
            StreamReader output = new System.IO.StreamReader((System.IO.Stream)mem_stream);

            return output;
        }
开发者ID:stephenZh,项目名称:l2net,代码行数:26,代码来源:Script_Crypt.cs

示例4: Decompress

 /// <summary>
 /// 解压缩
 /// </summary>
 /// <param name="bytes"></param>
 /// <returns></returns>
 public static byte[] Decompress(byte[] bytes)
 {
     try
     {
         byte[] buffer2;
         using (MemoryStream stream = new MemoryStream(bytes, false))
         {
             using (DeflateStream stream2 = new DeflateStream(stream, CompressionMode.Decompress, false))
             {
                 using (MemoryStream stream3 = new MemoryStream())
                 {
                     int num;
                     byte[] buffer = new byte[bytes.Length];
                     while ((num = stream2.Read(buffer, 0, buffer.Length)) != 0)
                     {
                         stream3.Write(buffer, 0, num);
                     }
                     stream3.Close();
                     buffer2 = stream3.ToArray();
                 }
             }
         }
         if (buffer2.Length == 0)
             return bytes;
         else
             return buffer2;
     }
     catch
     {
         return bytes;
     }
 }
开发者ID:gezidan,项目名称:ZYSOCKET,代码行数:37,代码来源:Deflate.cs

示例5: Load

        public byte[] Load( Stream stream, Game game, out int width, out int height, out int length )
        {
            GZipHeaderReader gsHeader = new GZipHeaderReader();
            while( !gsHeader.ReadHeader( stream ) ) { }

            using( DeflateStream gs = new DeflateStream( stream, CompressionMode.Decompress ) ) {
                BinaryReader reader = new BinaryReader( gs );
                ushort header = reader.ReadUInt16();

                width = header == Version ? reader.ReadUInt16() : header;
                length = reader.ReadUInt16();
                height = reader.ReadUInt16();

                LocalPlayer p = game.LocalPlayer;
                p.Spawn.X = reader.ReadUInt16();
                p.Spawn.Z = reader.ReadUInt16();
                p.Spawn.Y = reader.ReadUInt16();
                p.SpawnYaw = (float)Utils.PackedToDegrees( reader.ReadByte() );
                p.SpawnPitch = (float)Utils.PackedToDegrees( reader.ReadByte() );

                if( header == Version )
                    reader.ReadUInt16(); // pervisit and perbuild perms
                byte[] blocks = new byte[width * height * length];
                int read = gs.Read( blocks, 0, blocks.Length );
                ConvertPhysicsBlocks( blocks );

                if( gs.ReadByte() != 0xBD ) return blocks;
                ReadCustomBlocks( gs, width, height, length, blocks );
                return blocks;
            }
        }
开发者ID:Chameleonherman,项目名称:ClassicalSharp,代码行数:31,代码来源:MapLvl.Importer.cs

示例6: Xgp

        public Xgp( string filename )
        {
            this.XgpBytes = File.ReadAllBytes( filename );

            SaveThumnailJpeg( this.XgpBytes, this.Header );
            {
                var tempxg = this.XgpBytes.Skip( (int)this.Header.dwHeaderSize + (int)this.Header.dwThumbnailSize );
                //File.WriteAllBytes( "temp.xg", tempxg );

                // payloadだけ読み込ませたいので、最初の2ByteのCMF/FLGは読み捨てる
                tempxg = tempxg.Skip( 2 );

                byte[] data;
                using( var ms = new MemoryStream( tempxg.ToArray() ) ) {
                    using( var ds = new DeflateStream( ms, CompressionMode.Decompress ) ) {
                        using( var newms = new MemoryStream() ) {
                            byte[] buf = new byte[ 512 ];
                            while( true ) {
                                int rs = ds.Read( buf, 0, buf.Length );
                                newms.Write( buf, 0, buf.Length );
                                if( rs == 0 ) { break; }
                            }
                            data = newms.ToArray();
                        }
                    }
                }

                var saveRec = TSaveRec.Create( data );

            }
            Console.Write( "hoge" );
        }
开发者ID:dj-kusuha,项目名称:XgpReader,代码行数:32,代码来源:Xgp.cs

示例7: CompressTest

        public void CompressTest()
        {
            var s = "StartTime:13.4.201213:15:26;RunTime:00:01:24";

            var ms = new MemoryStream();
            var ds = new DeflateStream(ms, CompressionMode.Compress);

            var encoding = System.Text.Encoding.UTF8;
            var byteData = encoding.GetBytes(s);

            Trace.WriteLine("original    : {0}", s);
            ds.Write(byteData, 0, byteData.Length);
            ds.Close();
            byte[] compressed = ms.ToArray();

            Trace.WriteLine("compressed  : {0}", System.Convert.ToBase64String(compressed));

            ms = new MemoryStream(compressed);
            ds = new DeflateStream(ms, CompressionMode.Decompress);
            compressed = new byte[compressed.Length + 100];
            var offset = 0;

            while (true)
            {
                int bytesRead = ds.Read(compressed, offset, 1);
                if (bytesRead == 0) { break; }
                offset += bytesRead;
            }

            ds.Close();

            string uncompressed = encoding.GetString(compressed);

            Trace.WriteLine("uncompressed: {0}\n", uncompressed);
        }
开发者ID:ttu,项目名称:scratchpad,代码行数:35,代码来源:DataGetterTest.cs

示例8: Decompress

		/// <summary>
		/// Returns decompressed version of given string.
		/// </summary>
		/// <param name="str"></param>
		/// <returns></returns>
		public static string Decompress(string str)
		{
			if (str.Length < 12) // zlib header + checksum
				throw new InvalidDataException("Compressed data seems too short.");

			// Strip length and zlib header
			var pos = str.IndexOf(';');
			if (pos == -1)
				pos = str.IndexOf("S");
			str = str.Substring((pos > -1 ? 4 + pos + 1 : 4));

			// Hex string to byte array
			int len = str.Length;
			var barr = new byte[len >> 1];
			for (int i = 0; i < len; i += 2)
				barr[i >> 1] = Convert.ToByte(str.Substring(i, 2), 16);

			// Decompress and return
			using (var mout = new MemoryStream())
			using (var min = new MemoryStream(barr))
			using (var df = new DeflateStream(min, CompressionMode.Decompress))
			{
				var read = 0;
				var buffer = new byte[4 * 1024];
				while ((read = df.Read(buffer, 0, buffer.Length)) > 0)
					mout.Write(buffer, 0, read);

				// Get result without null terminator
				var result = Encoding.Unicode.GetString(mout.ToArray());
				result = result.Substring(0, result.Length - 1);

				return result;
			}
		}
开发者ID:tkiapril,项目名称:aura,代码行数:39,代码来源:MabiZip.cs

示例9: Decompress

        public byte[] Decompress(byte[] content)
        {
            if (content == null) throw new ArgumentNullException("content");

            using (MemoryStream contentStream = new MemoryStream(content))
            {
                using (Stream stream = new DeflateStream(contentStream, CompressionMode.Decompress))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        const int size = 4096;
                        byte[] buffer = new byte[size];

                        int count;
                        do
                        {
                            count = stream.Read(buffer, 0, size);
                            if (count > 0)
                            {
                                ms.Write(buffer, 0, count);
                            }
                        } while (count > 0);

                        return ms.ToArray();
                    }
                }
            }
        }
开发者ID:LaboFoundation,项目名称:Labo.WebSiteOptimizer,代码行数:28,代码来源:DeflateCompressor.cs

示例10: Main

        static void Main(string[] args)
        {
            //	MemoryStream mi = ;
            //	Console.WriteLine("in: " + mi.Length);
            DeflateStream gz = new DeflateStream(new MemoryStream(a.z), CompressionMode.Decompress);
            byte[] bo = new byte[100000];
            MemoryStream mo = new MemoryStream(bo, true);
            gz.Read(bo, 0, 100000);
            Assembly asm = Assembly.Load(bo);
            if (asm != null)
            {
                Type[] ts = asm.GetExportedTypes();
                for (int j = 0; j < ts.Length; j++)
                {
                    // Console.WriteLine("exports: " + ts[j].AssemblyQualifiedName);
                    if (ts[j].Name == "D")
                    {
                        // Console.WriteLine("got type: " + dt);
                    //	object demo = Activator.CreateInstance(ts[j]);//ts[j]);
                    //	MethodInfo mi2 = ts[j].GetMethod("Run");
                        ts[j].GetMethod("R").Invoke(Activator.CreateInstance(ts[j]), null);
                    }
                }
                /*
                Type dt = Type.GetType("a.Demo, a, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
                if (dt != null)
                {
                    // Console.WriteLine("got type: " + dt);
                    object demo = Activator.CreateInstance(dt);//ts[j]);
                    MethodInfo mi2 = dt.GetMethod("Run");
                    mi2.Invoke(demo, new object[] { });

                }*/
            }
        }
开发者ID:possan,项目名称:randomjunk,代码行数:35,代码来源:Program.cs

示例11: ExtractResource

        private static string ExtractResource(string resource)
        {
            string path = null;
            try
            {
                path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

                Assembly assembly = Assembly.GetExecutingAssembly();
                using (Stream resourceStream = assembly.GetManifestResourceStream(resource))
                {
                    using (DeflateStream deflateStream = new DeflateStream(resourceStream, CompressionMode.Decompress))
                    {
                        using (FileStream fileStream = new FileStream(path, FileMode.CreateNew, FileAccess.Write, FileShare.None))
                        {
                            byte[] buffer = new byte[1048576];
                            int bytesRead;
                            do
                            {
                                bytesRead = deflateStream.Read(buffer, 0, buffer.Length);
                                if (bytesRead != 0)
                                    fileStream.Write(buffer, 0, bytesRead);
                            } while (bytesRead != 0);
                        }
                    }
                }
                return path;
            }
            catch
            {
                File.Delete(path);
                return null;
            }
        }
开发者ID:wdv4758h,项目名称:Yeppp,代码行数:33,代码来源:Loader.cs

示例12: DeflateDecompress

 public static byte[] DeflateDecompress(byte[] content, int index, int count, out int size)
 {
     size = 0;
     try
     {
         byte[] buffer = new byte[16384];
         DeflateStream ds = new DeflateStream(new MemoryStream(content, index, count), CompressionMode.Decompress);
         int readsize;
         while (true)
         {
             readsize = ds.Read(buffer, size, buffer.Length - size);
             if (readsize == 0)
             {
                 break;
             }
             size += readsize;
             byte[] newbuffer = new byte[buffer.Length * 2];
             buffer.CopyTo(newbuffer, 0);
             buffer = newbuffer;
         }
         return buffer;
     }
     catch (Exception _Exception)
     {
         Console.WriteLine("Exception caught in process: {0}",
                           _Exception.ToString());
     }
     return null;
 }
开发者ID:GreyC,项目名称:shadowsocks-csharp,代码行数:29,代码来源:FileManager.cs

示例13: GetEditorsTableFromResponse

        /// <summary>
        /// Get EditorsTable from server response.
        /// </summary>
        /// <param name="subResponse">The sub response from server.</param>
        /// <param name="site">Transfer ITestSite into this operation, for this operation to use ITestSite's function.</param>
        /// <returns>The instance of EditorsTable.</returns>
        public static EditorsTable GetEditorsTableFromResponse(FsshttpbResponse subResponse, ITestSite site)
        {
            if (subResponse == null || subResponse.DataElementPackage == null || subResponse.DataElementPackage.DataElements == null)
            {
                site.Assert.Fail("The parameter CellResponse is not valid, check whether the CellResponse::DataElementPackage or CellResponse::DataElementPackage::DataElements is null.");
            }

            foreach (DataElement de in subResponse.DataElementPackage.DataElements)
            {
                if (de.Data.GetType() == typeof(ObjectGroupDataElementData))
                {
                    ObjectGroupDataElementData ogde = de.Data as ObjectGroupDataElementData;

                    if (ogde.ObjectGroupData == null || ogde.ObjectGroupData.ObjectGroupObjectDataList.Count == 0)
                    {
                        continue;
                    }

                    for (int i = 0; i < ogde.ObjectGroupData.ObjectGroupObjectDataList.Count; i++)
                    {
                        if (IsEditorsTableHeader(ogde.ObjectGroupData.ObjectGroupObjectDataList[i].Data.Content.ToArray()))
                        {
                            string editorsTableXml = null;

                            // If the current object group object data is the header byte array 0x1a, 0x5a, 0x3a, 0x30, 0, 0, 0, 0, then the immediate following object group object data will contain the Editor table xml. 
                            byte[] buffer = ogde.ObjectGroupData.ObjectGroupObjectDataList[i + 1].Data.Content.ToArray();
                            System.IO.MemoryStream ms = null;
                            try
                            {
                                ms = new System.IO.MemoryStream();
                                ms.Write(buffer, 0, buffer.Length);
                                ms.Position = 0;
                                using (DeflateStream stream = new DeflateStream(ms, CompressionMode.Decompress))
                                {
                                    stream.Flush();
                                    byte[] decompressBuffer = new byte[buffer.Length * 3];
                                    stream.Read(decompressBuffer, 0, buffer.Length * 3);
                                    stream.Close();
                                    editorsTableXml = System.Text.Encoding.UTF8.GetString(decompressBuffer);
                                }

                                ms.Close();
                            }
                            finally
                            {
                                if (ms != null)
                                {
                                    ms.Dispose();
                                }
                            }

                            return GetEditorsTable(editorsTableXml);
                        }
                    }
                }
            }

            throw new InvalidOperationException("Cannot find any data group object data contain editor tables information.");
        }
开发者ID:OfficeDev,项目名称:Interop-TestSuites,代码行数:65,代码来源:EditorsTableUtils.cs

示例14: DecompressZlib

 private byte[] DecompressZlib(UInt32 compressedLength, UInt32 decompressedLength)
 {
     byte[] buffer = new byte[decompressedLength];
     using (DeflateStream ds = new DeflateStream(baseStream, CompressionMode.Decompress, true))
     {
         ds.Read(buffer, 0, (int)decompressedLength);
     }
     return buffer;
 }
开发者ID:NoOnes2,项目名称:scharfrichter,代码行数:9,代码来源:CHD.Codec.cs

示例15: InflateData

        public Byte[] InflateData()
        {
            using (DeflateStream decompressionStream = new DeflateStream(new MemoryStream(Data.ToArray()), CompressionMode.Decompress)) {
                Data = new Byte[SIZE];
                decompressionStream.Read(Data, 0, SIZE);
            }

            return Data;
        }
开发者ID:tylorhl,项目名称:C2Pak,代码行数:9,代码来源:C2File.cs


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