public static byte[] Zip(byte[] data)
        {
            MemoryStream mstream = new MemoryStream();
            BZip2OutputStream zipOutStream = new BZip2OutputStream(mstream);
            zipOutStream.Write(data, 0, data.Length);
            zipOutStream.Finalize();
            zipOutStream.Close();

            byte[] result = mstream.ToArray();
            mstream.Close();

            return result;
        }

        public static byte[] Unzip(byte[] data)
        {
            MemoryStream mstream = new MemoryStream(data);
            BZip2InputStream zipInputStream = new BZip2InputStream(mstream);
            byte[] byteUncompressed = new byte[zipInputStream.Length];
            zipInputStream.Read(byteUncompressed, 0, (int)byteUncompressed.Length);

            zipInputStream.Close();
            mstream.Close();

            return byteUncompressed;
        }

posted on 2008-11-21 01:27  痞子再  阅读(523)  评论(0编辑  收藏  举报