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


C# BZip2InputStream.Read方法代码示例

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


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

示例1: BasicRoundTrip

		public void BasicRoundTrip()
		{
			MemoryStream ms = new MemoryStream();
			BZip2OutputStream outStream = new BZip2OutputStream(ms);
			
			byte[] buf = new byte[10000];
			System.Random rnd = new Random();
			rnd.NextBytes(buf);
			
			outStream.Write(buf, 0, buf.Length);
			outStream.Close();
			ms = new MemoryStream(ms.GetBuffer());
			ms.Seek(0, SeekOrigin.Begin);
			
			using (BZip2InputStream inStream = new BZip2InputStream(ms))
			{
				byte[] buf2 = new byte[buf.Length];
				int    pos  = 0;
				while (true) 
				{
					int numRead = inStream.Read(buf2, pos, 4096);
					if (numRead <= 0) 
					{
						break;
					}
					pos += numRead;
				}
			
				for (int i = 0; i < buf.Length; ++i) 
				{
					Assert.AreEqual(buf2[i], buf[i]);
				}
			}
		}
开发者ID:JoeCooper,项目名称:SharpZipLib.Portable,代码行数:34,代码来源:Bzip2Tests.cs

示例2: CreateEmptyArchive

		public void CreateEmptyArchive()
		{
			MemoryStream ms = new MemoryStream();
			BZip2OutputStream outStream = new BZip2OutputStream(ms);
			outStream.Close();
			ms = new MemoryStream(ms.GetBuffer());
			
			ms.Seek(0, SeekOrigin.Begin);
			
			using (BZip2InputStream inStream = new BZip2InputStream(ms)) 
			{
				byte[] buffer = new byte[1024];
				int    pos  = 0;
				while (true) 
				{
					int numRead = inStream.Read(buffer, 0, buffer.Length);
					if (numRead <= 0) 
					{
						break;
					}
					pos += numRead;
				}
			
				Assert.AreEqual(pos, 0);
			}
		}
开发者ID:JoeCooper,项目名称:SharpZipLib.Portable,代码行数:26,代码来源:Bzip2Tests.cs

示例3: Decompress

        public static byte[] Decompress(byte[] input, int uncompressedLength)
        {
            Contract.Requires(input != null);
            Contract.Requires(uncompressedLength >= 0);
            Contract.Ensures(Contract.Result<byte[]>() != null);
            Contract.Ensures(Contract.Result<byte[]>().Length == uncompressedLength);

            var output = new byte[uncompressedLength];

            using (var stream = new BZip2InputStream(new MemoryStream(input, false)))
                stream.Read(output, 0, uncompressedLength);

            return output;
        }
开发者ID:hanson-huang,项目名称:Encore,代码行数:14,代码来源:BZip2Decompressor.cs

示例4: UnzipString

    public static string UnzipString(string compbytes)
    {
        string result;
        MemoryStream m_msBZip2 = null;
        BZip2InputStream m_isBZip2 = null;
        try
        {
            m_msBZip2 = new MemoryStream(Convert.FromBase64String(compbytes));
            // read final uncompressed string size stored in first 4 bytes
            //
            using (BinaryReader reader = new BinaryReader(m_msBZip2, System.Text.Encoding.ASCII))
            {
                Int32 size = reader.ReadInt32();

                m_isBZip2 = new BZip2InputStream(m_msBZip2);
                byte[] bytesUncompressed = new byte[size];
                m_isBZip2.Read(bytesUncompressed, 0, bytesUncompressed.Length);
                m_isBZip2.Close();
                m_msBZip2.Close();

                result = Encoding.ASCII.GetString(bytesUncompressed);

                reader.Close();
            }
        }
        finally
        {
            if (m_isBZip2 != null)
            {
                m_isBZip2.Dispose();
            }
            if (m_msBZip2 != null)
            {
                m_msBZip2.Dispose();
            }
        }
        return result;
    }
开发者ID:Raj2509,项目名称:net.kibotu.sandbox.unity.dragnslay,代码行数:38,代码来源:ZipString.cs

示例5: UncompressBzip2File

 // TODO: Create a class Archive.cs and do all the archiving stuff there!
 public static bool UncompressBzip2File(string Filename, string To, Gtk.ProgressBar bar)
 {
     try{
         Console.WriteLine(Filename);
         BZip2InputStream bzipIn = new BZip2InputStream(File.OpenRead(Filename));
         FileStream streamWriter = File.Create(To+Path.GetFileNameWithoutExtension(Filename));
         long size=0;
         byte[] data = new byte[1024];
         while (true)
             {
             size = bzipIn.Read(data, 0, data.Length);
             if (size > 0) streamWriter.Write(data, 0, (int) size);
             else break;
         }
         streamWriter.Close();
         Console.WriteLine("Deflating the gzip file done!");
         return true;
     }
     catch(Exception e) {
         Console.WriteLine("An exception occured while deflating the bzip2 file: "+e.Message);
         return false;
     }
 }
开发者ID:BackupTheBerlios,项目名称:gnomeartng-svn,代码行数:24,代码来源:CUtility.cs

示例6: loopread

        /// <summary>
        /// required for applying a binary patch
        /// </summary>
        private Int32 loopread(ref BZip2InputStream zipStream, ref byte[] buf, Int32 offset, Int32 nbytes)
        {
            Int32 ptr;
            Int32 lenread;

            ptr = 0;

            while (ptr < nbytes)
            {
                lenread = zipStream.Read(buf, offset + ptr, nbytes);

                if (lenread == 0)
                {
                    return ptr;
                }

                if (lenread == -1)
                {
                    return -1;
                }

                ptr = ptr + lenread;
            }

            return ptr;
        }
开发者ID:js1987,项目名称:openpetragit,代码行数:29,代码来源:PatchTools.cs

示例7: ReassemblePacket

        public static SteamPacket ReassemblePacket(List<byte[]> splitPackets, bool isCompressed, short uncompressedSize, int packetChecksum)
        {
            byte[] packetData, tmpData;
            packetData = new byte[0];

            foreach(byte[] splitPacket in splitPackets)
            {
                if(splitPacket == null)
                {
                    throw new Exception();
                }

                tmpData = packetData;
                packetData = new byte[tmpData.Length + splitPacket.Length];

                MemoryStream memStream = new MemoryStream(packetData);
                memStream.Write(tmpData, 0, tmpData.Length);
                memStream.Write(splitPacket, 0, splitPacket.Length);
            }

            if(isCompressed)
            {
                BZip2InputStream bzip2 = new BZip2InputStream(new MemoryStream(packetData));
                bzip2.Read(packetData, 0, uncompressedSize);

                Crc32 crc32 = new Crc32();
                crc32.Update(packetData);

                if(crc32.Value != packetChecksum)
                {
                    throw new Exception("CRC32 checksum mismatch of uncompressed packet data.");
                }
            }

            return SteamPacket.CreatePacket(packetData);
        }
开发者ID:King2500,项目名称:steam-condenser-csharp,代码行数:36,代码来源:SteamPacket.cs

示例8: DeCompress

		public byte[]  DeCompress(byte[] bytesToDecompress)
		{
			//Sets up the write data byte array (acts as a buffer array for the decompression, in 4096 byte blocks)
			byte[] writeData = new byte[4096];
			//Set up the initial Stream object (used a compact method by creating the memory stream form the byte-array and passing in all in one)
			Stream s2 = new BZip2InputStream(new MemoryStream(bytesToDecompress));
			//Stringbuilder which will hold the results of the decompression
			MemoryStream outStream = new MemoryStream();
			while(true)
			{
				//The business end, pops the next 4096 bytes from the Stream into the writeData buffer
				int size = s2.Read(writeData,0,writeData.Length);
				if(size>0)
				{
					outStream.Write(writeData,0,size);
				}
				else
				{
					break;
				}
			}
			s2.Close();
			byte[] outArr = outStream.ToArray();
			outStream.Close();
			return outArr;
		}
开发者ID:alexan1,项目名称:marketweb,代码行数:26,代码来源:ComDePress.cs

示例9: PassxDecode

        private string PassxDecode(string passx)
        {
            using (var input = new MemoryStream ()) {
                var passx_base64_decoded = Convert.FromBase64String (passx);
                input.Write (passx_base64_decoded, 0, passx_base64_decoded.Length);
                input.Seek (0, SeekOrigin.Begin);
                using (var output = new BZip2InputStream (input)) {
                    var passx_bzip2_decoded = new byte[1024];
                    output.Read (passx_bzip2_decoded, 0, passx_bzip2_decoded.Length);
                    return System.Text.Encoding.UTF8.GetString (passx_bzip2_decoded);
                }
            }

            return null;
        }
开发者ID:abock,项目名称:obs-tree-analyzer,代码行数:15,代码来源:OscRcAccountCollection.cs

示例10: DecompressBytes

    /// <summary>
    /// Decompresses a compressed string to a byte array
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    public static byte[] DecompressBytes(this byte[] data)
    {
        // exit if null
        if (data.IsNullOrEmpty())
            return null;

        using (MemoryStream msBZip2 = new MemoryStream(data))
        {
            // read final uncompressed string size stored in first 4 bytes
            using (BinaryReader reader = new BinaryReader(msBZip2))
            {
                int size = reader.ReadInt32();

                using (BZip2InputStream m_isBZip2 = new BZip2InputStream(msBZip2))
                {
                    byte[] bytesUncompressed = new byte[size];
                    m_isBZip2.Read(bytesUncompressed, 0, size);
                    return bytesUncompressed;
                }
            }
        }
    }
开发者ID:rocketgames,项目名称:Extension-Methods-for-Unity,代码行数:27,代码来源:CompressionExtensions.cs

示例11: UncompressBuffer

        public byte[] UncompressBuffer(ref byte[] buffer)
        {
            MemoryStream Compressed = new MemoryStream(buffer);
            MemoryStream UnCompressed = new MemoryStream();

            try
            {
                BZip2InputStream zisUncompressed = new BZip2InputStream(Compressed);
                int size;
                byte[] data = new byte[4096];
                do
                {
                    size = zisUncompressed.Read(data, 0, data.Length);
                    UnCompressed.Write(data, 0, size);
                }while (size > 0);

                zisUncompressed.Close();
                Compressed.Close();
                byte []bUncompressedData = UnCompressed.GetBuffer();
                UnCompressed.Close();
                return bUncompressedData;
            }
            catch(Exception ex)
            {
                WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Module ::: AppShare public byte[] UncompressBuffer(ref byte[] buffer)",ex,"",false);
            }
            return null;
        }
开发者ID:zaeem,项目名称:FlexCollab,代码行数:28,代码来源:AppSharing.cs

示例12: DecompressBlock

        public static int DecompressBlock(byte[] inBuffer, int inLength, byte[] outBuffer, bool multi)
        {
            byte[] tempBuffer;

            if (!multi) return DclCompression.DecompressBlock(inBuffer, 0, inLength, outBuffer);
            else // Examinate first byte for finding compression methods used
            {
                switch (inBuffer[0])
                {
                    case 0x01: // Huffman
                        throw new MpqCompressionNotSupportedException(0x01, "Huffman");
                    case 0x02: // Zlib (Deflate/Inflate)
            #if USE_SHARPZIPLIB // Use SharpZipLib's Deflate implementation
                        Inflater.Reset(); // The first property read will initialize the field…
                        inflater.SetInput(inBuffer, 1, inLength - 1);
                        return inflater.Inflate(outBuffer);
            #else // Use .NET 2.0's built-in inflate algorithm
                        using (var inStream = new MemoryStream(inBuffer, 3, inLength - 7, false, false))
                        using (var outStream = new DeflateStream(inStream, CompressionMode.Decompress))
                            outStream.Read(outBuffer, 0, outBuffer.Length);
            #endif
                    case 0x08: // PKWare DCL (Implode/Explode)
                        return DclCompression.DecompressBlock(inBuffer, 1, inLength - 1, outBuffer);
                    case 0x10: // BZip2
            #if USE_SHARPZIPLIB // Use SharpZipLib for decompression
                        using (var inStream = new MemoryStream(inBuffer, 1, inLength - 1, false, false))
                        using (var outStream = new BZip2InputStream(inStream))
                            return outStream.Read(outBuffer, 0, outBuffer.Length);
            #else
                        throw new CompressionNotSupportedException("BZip2");
            #endif
                    case 0x12: // LZMA
                        using (var inStream = new MemoryStream(inBuffer, 1, inLength - 1, false, false))
                        using (var outStream = new MemoryStream(outBuffer, true))
                        {
                            lzmaDecoder.Code(inStream, outStream, inStream.Length, outStream.Length, null);
                            return checked((int)outStream.Position);
                        }
                    case 0x20: // Sparse
                        return SparseCompression.DecompressBlock(inBuffer, 1, inLength - 1, outBuffer);
                    case 0x22: // Sparse + Deflate
            #if USE_SHARPZIPLIB // Use SharpZipLib's Deflate implementation
                        Inflater.Reset(); // The first property read will initialize the field…
                        inflater.SetInput(inBuffer, 1, inLength - 1);
                        tempBuffer = CommonMethods.GetSharedBuffer(outBuffer.Length);
                        return SparseCompression.DecompressBlock(tempBuffer, 0, inflater.Inflate(tempBuffer), outBuffer);
            #else // Use .NET 2.0's built-in inflate algorithm
                        using (var inStream = new MemoryStream(inBuffer, 3, inLength - 7, false, false))
                        using (var inoutStream = new DeflateStream(inStream, CompressionMode.Decompress))
                        using (var outStream = new SparseInputStream(inoutStream))
                            return outStream.Read(outBuffer, 0, outBuffer.Length);
            #endif
                    case 0x30: // Sparse + BZip2
            #if USE_SHARPZIPLIB // Use SharpZipLib for decompression
                        using (var inStream = new MemoryStream(inBuffer, 1, inLength - 1, false, false))
                        using (var inoutStream = new BZip2InputStream(inStream))
                        using (var outStream = new SparseInputStream(inoutStream))
                            return outStream.Read(outBuffer, 0, outBuffer.Length);
            #else
                        throw new CompressionNotSupportedException("Sparse + BZip2");
            #endif
                    case 0x40: // Mono IMA ADPCM
                        throw new MpqCompressionNotSupportedException(0x40, "Mono IMA ADPCM");
                    case 0x41: // Mono IMA ADPCM + Huffman
                        throw new MpqCompressionNotSupportedException(0x41, "Mono IMA ADPCM + Huffman");
                    case 0x48: // Mono IMA ADPCM + Implode
                        throw new MpqCompressionNotSupportedException(0x48, "Mono IMA ADPCM + Implode");
                    case 0x80: // Stereo IMA ADPCM
                        throw new MpqCompressionNotSupportedException(0x80, "Stereo IMA ADPCM");
                    case 0x81: // Stereo IMA ADPCM + Huffman
                        throw new MpqCompressionNotSupportedException(0x81, "Stereo IMA ADPCM + Huffman");
                    case 0x88: // Stereo IMA ADPCM + Implode
                        throw new MpqCompressionNotSupportedException(0x88, "Stereo IMA ADPCM + Implode");
                    default:
                        throw new MpqCompressionNotSupportedException(inBuffer[0]);
                }
            }
        }
开发者ID:sgraf812,项目名称:crystalmpq,代码行数:78,代码来源:CommonMethods.Compression.cs

示例13: ProcessFile

		/// <summary>
		///     Processes a file buffer.
		///     Will decompress, and find an appropriate extension for it if possible.
		/// </summary>
		private static void ProcessFile(ref byte[] buffer, out string extension)
		{
			extension = "";

			//decompress gzip
			if (buffer.Length > 5 && (buffer[4] << 8) + buffer[5] == 0x1f8b) //gzip
			{
				//remove another 4 non-file bytes
				var tempBuffer = new byte[buffer.Length - 4];
				Array.Copy(buffer, 4, tempBuffer, 0, buffer.Length - 4);
				buffer = tempBuffer;

				var decompressionStream = new GZipStream(new MemoryStream(buffer), CompressionMode.Decompress);

				int readBytes;
				tempBuffer = new byte[0];

				do
				{
					var readBuffer = new byte[100000];
					readBytes = decompressionStream.Read(readBuffer, 0, 100000);

					var storedBytes = tempBuffer.Length;
					Array.Resize(ref tempBuffer, tempBuffer.Length + readBytes);
					Array.Copy(readBuffer, 0, tempBuffer, storedBytes, readBytes);
				} while (readBytes == 100000);

				buffer = tempBuffer;
			}

			//decompress bzip2
			if (buffer.Length > 9 && buffer[4] == 0x31 && buffer[5] == 0x41 && buffer[6] == 0x59 && buffer[7] == 0x26 &&
			    buffer[8] == 0x53 && buffer[9] == 0x59) //bzip2
			{
				//remove another 4 non-file bytes
				var tempBuffer = new byte[buffer.Length - 4];
				Array.Copy(buffer, 4, tempBuffer, 0, buffer.Length - 4);
				buffer = tempBuffer;

				//prepend file header
				byte[] magic =
				{
					0x42, 0x5a, //BZ (signature)
					0x68, //h (version)
					0x31 //*100kB block-size
				};

				tempBuffer = new byte[magic.Length + buffer.Length];
				magic.CopyTo(tempBuffer, 0);
				buffer.CopyTo(tempBuffer, magic.Length);
				buffer = tempBuffer;

				var decompressionStream = new BZip2InputStream(new MemoryStream(buffer));

				int readBytes;
				tempBuffer = new byte[0];

				do
				{
					var readBuffer = new byte[100000];
					readBytes = decompressionStream.Read(readBuffer, 0, 100000);

					var storedBytes = tempBuffer.Length;
					Array.Resize(ref tempBuffer, tempBuffer.Length + readBytes);
					Array.Copy(readBuffer, 0, tempBuffer, storedBytes, readBytes);
				} while (readBytes == 100000);

				buffer = tempBuffer;
			}

			//detect appropriate extension
			if (buffer.Length > 3 && (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3] == 0x4f676753)
				extension = ".ogg";
			else if (buffer.Length > 3 && (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3] == 0x4a414741)
				extension = ".jaga";
			else if (buffer.Length > 3 && (uint)(buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3] == 0x89504e47)
				extension = ".png";
		}
开发者ID:Vishrs,项目名称:RuneScapeCacheTools,代码行数:82,代码来源:CacheExtractJob.cs


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