Exemplo n.º 1
0
        /// <summary>
        /// Compress <paramref name="instream">input stream</paramref> sending
        /// result to <paramref name="outputstream">output stream</paramref>
        /// </summary>
        /// <param name="outstream"></param>
        /// <param name="instream"></param>
        /// <param name="strength">Strngth of the Compression</param>
        /// <remarks>I had to change the Origial Compression Methode in a way that it woun't close
        /// the <paramref name="instream">input stream</paramref> and that it seeks to the Beginning
        /// of it on startup</remarks>
        protected static void Compress(Stream instream, Stream outstream, CompressionStrength strength)
        {
            System.IO.Stream bos = outstream;
            System.IO.Stream bis = instream;
            bis.Seek(0, System.IO.SeekOrigin.Begin);
            int ch = bis.ReadByte();

            ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream bzos = new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(bos, (int)strength);
            while (ch != -1)
            {
                bzos.WriteByte((byte)ch);
                ch = bis.ReadByte();
            }
            bzos.Close();
        }