private void btnExpandData_Click(object sender, System.EventArgs e) { // open memory stream on saved data MemoryStream ms = new MemoryStream(m_CompressedData); // attach decompressor stream to memory stream C1ZStreamReader sr = new C1ZStreamReader(ms); // read uncompressed data BinaryReader br = new BinaryReader(sr); int count = br.ReadInt32(); for (int i = 0; i < count; i++) { int deg = br.ReadInt32(); double rad = br.ReadDouble(); double sin = br.ReadDouble(); double cos = br.ReadDouble(); } // done, tell user about it string msg = string.Format("Read table with {0} points from stream with {1} bytes.", count, m_CompressedData.Length); label1.Text = msg; }
/// <summary> /// 解压缩对象 /// </summary> /// <returns></returns> public static object Decompression(object data) { object obj = null; C1ZStreamReader zipStream = null; MemoryStream memStream = null; try { if (data != null) { memStream = new MemoryStream((byte[])data); zipStream = new C1ZStreamReader(memStream); obj = new BinaryFormatter().Deserialize(zipStream); } } catch (Exception ex) { throw ex; } finally { if (zipStream != null) { zipStream.Close(); } if (memStream != null) { memStream.Close(); } } return(obj); }
public static string ExpandString(byte[] buffer) { // turn buffer into a memory stream MemoryStream ms = new MemoryStream(buffer); // attach decompressor stream to memory stream C1ZStreamReader sr = new C1ZStreamReader(ms); // read uncompressed data StreamReader reader = new StreamReader(sr); return(reader.ReadToEnd()); }
private static bool ExpandFile(string dstFile, string srcFile) { // prepare to expand file bool retval = true; FileStream srcStream = null; FileStream dstStream = null; try { // open the files srcStream = new FileStream(srcFile, FileMode.Open, FileAccess.Read); dstStream = new FileStream(dstFile, FileMode.Create, FileAccess.Write); // open expander stream on compressed source C1ZStreamReader sr = new C1ZStreamReader(srcStream); // copy expander stream into destination file StreamCopy(dstStream, sr); } catch // exception? tell caller we failed { retval = false; } finally // always close our streams { if (srcStream != null) { srcStream.Close(); } if (dstStream != null) { dstStream.Close(); } } // done return(retval); }
void btnLoadCompressed_Click(object sender, System.EventArgs e) { // clear grid, show status Cursor = Cursors.WaitCursor; dataGrid1.DataSource = null; statusBar1.Text = "Loading DataTable from compressed file..."; // deserialize from regular file string fn = Application.StartupPath + FN_COMPRESSED; FileStream fs = new FileStream(fn, FileMode.Open); C1ZStreamReader decompressor = new C1ZStreamReader(fs); BinaryFormatter bf = new BinaryFormatter(); long ticks = DateTime.Now.Ticks; DataTable dt = (DataTable)bf.Deserialize(decompressor); long ms = (DateTime.Now.Ticks - ticks) / TimeSpan.TicksPerMillisecond; fs.Close(); // show result Cursor = Cursors.Default; dataGrid1.DataSource = dt; statusBar1.Text = "Loaded data from compressed file in " + ms.ToString() + " ms."; }
public static bool uncompress(Stream stream_0, string string_0) { bool flag = true; FileStream baseStream = null; try { baseStream = new FileStream(string_0, FileMode.Open, FileAccess.Read); C1ZStreamReader reader = new C1ZStreamReader(baseStream); uncompress_write(stream_0, reader); } catch { flag = false; } finally { if (baseStream != null) { baseStream.Close(); } } return(flag); }
/// <summary> /// Opens a serialize test collection from a stream. /// </summary> /// <param name="stream"> The stream to load the TestCollection.</param> /// <returns> A TestCollection.</returns> public TestCollection OpenTemplate(Stream stream) { // Decompressed zip C1ZStreamReader openZip = new C1ZStreamReader(stream); // Desearialize BinaryFormatter bf = new BinaryFormatter(); TestCollection tests = (TestCollection)bf.Deserialize(openZip); stream.Close(); return tests; }