Exemplo n.º 1
0
 public void SaveToCompressedStream(System.IO.Stream aData)
 {
     using (var gzipOut = new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(aData))
     {
         gzipOut.IsStreamOwner = false;
         SaveToStream(gzipOut);
         gzipOut.Close();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static byte[] CompressBytes(byte[] data)
        {
            var o = new MemoryStream();
            var s = new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(o);

            s.Write(data, 0, data.Length);
            s.Close();
            o.Flush();
            o.Close();
            return(o.ToArray());
        }
Exemplo n.º 3
0
        public string Zip(string uncompressedString)
        {
            byte[]       bytData = System.Text.Encoding.Unicode.GetBytes(uncompressedString);
            MemoryStream ms      = new MemoryStream();
            Stream       s       = new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(ms);

            s.Write(bytData, 0, bytData.Length);
            s.Close();
            byte[] compressedData = (byte[])ms.ToArray();
            return(System.Convert.ToBase64String(compressedData, 0, compressedData.Length));
        }
Exemplo n.º 4
0
        private static void SerializeTo(VocalIndexObject Object, string FilePath)
        {
            FileStream msObj = new FileStream(FilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);

            ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream boz = new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(msObj);
            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(VocalIndexObject));

            js.WriteObject(boz, Object);
            boz.Flush();
            boz.Close();
            msObj.Close();
        }
Exemplo n.º 5
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();
        }
        /// <summary>
        /// 压缩
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static string Compress(string param)
        {
            byte[] data = System.Text.Encoding.UTF8.GetBytes(param);
            //byte[] data = Convert.FromBase64String(param);
            MemoryStream ms     = new MemoryStream();
            Stream       stream = new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(ms);

            try
            {
                stream.Write(data, 0, data.Length);
            }
            finally
            {
                stream.Close();
                ms.Close();
            }
            return(Convert.ToBase64String(ms.ToArray()));
        }
Exemplo n.º 7
0
		public void SaveToCompressedStream(System.IO.Stream aData)
		{
			using (var gzipOut = new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(aData))
			{
				gzipOut.IsStreamOwner = false;
				SaveToStream(gzipOut);
				gzipOut.Close();
			}
		}