Closed wf-soft closed 1 year ago
When I use CFSConfiguration.EraseFreeSectors is used, it just replaces byte with 0xFF, and cannot free space to reduce the file size. Then using SetData will cause the file to be larger each time it is modified
Sorry for the delayed response @wf-soft. Current implementation doesn't reduce size without an explicit call to
CompoundFile.ShrinkCompoundFile(filename);
I've added a test to give an example of a possible strategy for file size reduction
String filename = "_Test.ppt";
String filename2 = "MyFile4.dat";
if (File.Exists(filename2))
File.Delete(filename2);
if (File.Exists(filename))
{
File.Copy(filename, filename2);
}
var cf = new CompoundFile(filename2, CFSUpdateMode.Update, CFSConfiguration.EraseFreeSectors);
cf.RootStorage.Delete("PowerPoint Document");
cf.Commit();
cf.Close();
CompoundFile.ShrinkCompoundFile(filename2);
long length = new System.IO.FileInfo(filename).Length;
long length2 = new System.IO.FileInfo(filename2).Length;
Assert.IsTrue(length > length2);
I hope this example may clarify the point. Best Regards, Federico
Added example for #94
@ironfede What I am currently using is to copy the content to a new CompoundFile and save it. I will try your solution, Thank you for your answer
In this way, I can only delete the block name, but not the data. When I use SetData and then Commit, the file will keep growing every time I save it