Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RootStorage Delete Unable to delete content #94

Closed
wf-soft opened this issue Dec 3, 2022 · 4 comments
Closed

RootStorage Delete Unable to delete content #94

wf-soft opened this issue Dec 3, 2022 · 4 comments
Assignees

Comments

@wf-soft
Copy link

wf-soft commented Dec 3, 2022

var cf = new CompoundFile(@"D:\BaiduSyncdisk\WFsoft\Max文件研究\1.max", CFSUpdateMode.Update, CFSConfiguration.Default);
//Cf.RootStorage.GetStream("Scene").SetData(new byte[0]);
Cf.RootStorage.Delete("Scene");
Cf.Save(@"D:\BaiduSyncdisk\WFsoft\2.max");
Cf.Close();

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

@ironfede ironfede self-assigned this Dec 3, 2022
@ironfede ironfede added the bug label Dec 3, 2022
@wf-soft
Copy link
Author

wf-soft commented Dec 3, 2022

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

@ironfede ironfede added enhancement and removed bug labels Apr 21, 2023
@ironfede
Copy link
Owner

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

@ironfede
Copy link
Owner

Added example for #94

ironfede added a commit that referenced this issue Apr 21, 2023
@wf-soft
Copy link
Author

wf-soft commented Apr 22, 2023

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants