private void SingleWriteReadMatchingSTREAMED(int size) { MemoryStream ms = new MemoryStream(size); CompoundFile cf = new CompoundFile(); ICFStorage st = cf.RootStorage.AddStorage("MyStorage"); ICFStream sm = st.AddStream("MyStream"); byte[] b = Helpers.GetBuffer(size); sm.SetData(b); cf.Save(ms); cf.Close(); CompoundFile cf2 = new CompoundFile(ms); ICFStorage st2 = cf2.RootStorage.GetStorage("MyStorage"); ICFStream sm2 = st2.GetStream("MyStream"); Assert.IsNotNull(sm2); Assert.IsTrue(sm2.Size == size); Assert.IsTrue(Helpers.CompareBuffer(sm2.GetData(), b)); cf2.Close(); }
public void Test_RE_WRITE_SMALLER_MINI_STREAM() { String filename = "report.xls"; CompoundFile cf = new CompoundFile(filename); ICFStream foundStream = cf.RootStorage.GetStream("\x05SummaryInformation"); int TEST_LENGTH = (int)foundStream.Size - 20; byte[] b = Helpers.GetBuffer(TEST_LENGTH); foundStream.SetData(b); cf.Save("RE_WRITE_SMALLER_MINI_STREAM.xls"); cf.Close(); cf = new CompoundFile("RE_WRITE_SMALLER_MINI_STREAM.xls"); byte[] c = cf.RootStorage.GetStream("\x05SummaryInformation").GetData(); Assert.IsTrue(c.Length == TEST_LENGTH); cf.Close(); if (File.Exists("RE_WRITE_SMALLER_MINI_STREAM.xls")) { File.Delete("RE_WRITE_SMALLER_MINI_STREAM.xls"); } }
public void Test_TRANSACTED_ADD_STREAM_TO_EXISTING_FILE() { String srcFilename = "report.xls"; String dstFilename = "reportOverwrite.xls"; File.Copy(srcFilename, dstFilename, true); CompoundFile cf = new CompoundFile(dstFilename, UpdateMode.Update, false, false); byte[] buffer = Helpers.GetBuffer(5000); ICFStream addedStream = cf.RootStorage.AddStream("MyNewStream"); addedStream.SetData(buffer); cf.Commit(); cf.Close(); if (File.Exists("reportOverwrite.xls")) { File.Delete("reportOverwrite.xls"); } }
public void Test_WRITE_MINISTREAM_READ_REWRITE_STREAM() { const int BIGGER_SIZE = 350; //const int SMALLER_SIZE = 290; const int MEGA_SIZE = 18000000; byte[] ba1 = Helpers.GetBuffer(BIGGER_SIZE, 1); byte[] ba2 = Helpers.GetBuffer(BIGGER_SIZE, 2); byte[] ba3 = Helpers.GetBuffer(BIGGER_SIZE, 3); byte[] ba4 = Helpers.GetBuffer(BIGGER_SIZE, 4); byte[] ba5 = Helpers.GetBuffer(BIGGER_SIZE, 5); //WRITE 5 (mini)streams in a compound file -- CompoundFile cfa = new CompoundFile(); ICFStream myStream = cfa.RootStorage.AddStream("MyFirstStream"); Assert.IsNotNull(myStream); myStream.SetData(ba1); Assert.IsTrue(myStream.Size == BIGGER_SIZE); ICFStream myStream2 = cfa.RootStorage.AddStream("MySecondStream"); Assert.IsNotNull(myStream2); myStream2.SetData(ba2); Assert.IsTrue(myStream2.Size == BIGGER_SIZE); ICFStream myStream3 = cfa.RootStorage.AddStream("MyThirdStream"); Assert.IsNotNull(myStream3); myStream3.SetData(ba3); Assert.IsTrue(myStream3.Size == BIGGER_SIZE); ICFStream myStream4 = cfa.RootStorage.AddStream("MyFourthStream"); Assert.IsNotNull(myStream4); myStream4.SetData(ba4); Assert.IsTrue(myStream4.Size == BIGGER_SIZE); ICFStream myStream5 = cfa.RootStorage.AddStream("MyFifthStream"); Assert.IsNotNull(myStream5); myStream5.SetData(ba5); Assert.IsTrue(myStream5.Size == BIGGER_SIZE); cfa.Save("WRITE_MINISTREAM_READ_REWRITE_STREAM.cfs"); cfa.Close(); // Now get the second stream and rewrite it smaller byte[] bb = Helpers.GetBuffer(MEGA_SIZE); CompoundFile cfb = new CompoundFile("WRITE_MINISTREAM_READ_REWRITE_STREAM.cfs"); ICFStream myStreamB = cfb.RootStorage.GetStream("MySecondStream"); Assert.IsNotNull(myStreamB); myStreamB.SetData(bb); Assert.IsTrue(myStreamB.Size == MEGA_SIZE); byte[] bufferB = myStreamB.GetData(); cfb.Save("WRITE_MINISTREAM_READ_REWRITE_STREAM_2ND.cfs"); cfb.Close(); CompoundFile cfc = new CompoundFile("WRITE_MINISTREAM_READ_REWRITE_STREAM_2ND.cfs"); ICFStream myStreamC = cfc.RootStorage.GetStream("MySecondStream"); Assert.IsTrue(myStreamC.Size == MEGA_SIZE, "DATA SIZE FAILED"); byte[] bufferC = myStreamC.GetData(); Assert.IsTrue(Helpers.CompareBuffer(bufferB, bufferC), "DATA INTEGRITY FAILED"); cfc.Close(); if (File.Exists("WRITE_MINISTREAM_READ_REWRITE_STREAM.cfs")) { File.Delete("WRITE_MINISTREAM_READ_REWRITE_STREAM.cfs"); } if (File.Exists("WRITE_MINISTREAM_READ_REWRITE_STREAM_2ND.cfs")) { File.Delete("WRITE_MINISTREAM_READ_REWRITE_STREAM_2ND.cfs"); } }