Esempio n. 1
0
		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);
			}
		}
Esempio n. 2
0
		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]);
				}
			}
		}
Esempio n. 3
0
        /// <summary>
        /// Decompress <paramref name="inStream">input</paramref> writing 
        /// decompressed data to the <paramref name="outStream">output stream</paramref>
        /// </summary>
        /// <param name="inStream">The stream containing data to decompress.</param>
        /// <param name="outStream">The stream to write decompressed data to.</param>
        /// <remarks>Both streams are closed on completion</remarks>
        public static void Decompress(Stream inStream, Stream outStream) 
        {
            if ( inStream == null ) {
                throw new ArgumentNullException("inStream");
            }
			
            if ( outStream == null ) {
                throw new ArgumentNullException("outStream");
            }
			
            using ( outStream ) {
                using ( var bzis = new BZip2InputStream(inStream) ) {
                    var ch = bzis.ReadByte();
                    while (ch != -1) {
                        outStream.WriteByte((byte)ch);
                        ch = bzis.ReadByte();
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Decompress <paramref name="inStream">input</paramref> writing
        /// decompressed data to the <paramref name="outStream">output stream</paramref>
        /// </summary>
        /// <param name="inStream">The stream containing data to decompress.</param>
        /// <param name="outStream">The stream to write decompressed data to.</param>
        /// <remarks>Both streams are closed on completion</remarks>
        public static void Decompress(Stream inStream, Stream outStream)
        {
            if (inStream == null)
            {
                throw new ArgumentNullException("inStream");
            }

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

            using ( outStream ) {
                using (var bzis = new BZip2InputStream(inStream)) {
                    var ch = bzis.ReadByte();
                    while (ch != -1)
                    {
                        outStream.WriteByte((byte)ch);
                        ch = bzis.ReadByte();
                    }
                }
            }
        }