adamhathcock / sharpcompress

SharpCompress is a fully managed C# library to deal with many compression types and formats.
MIT License
2.27k stars 480 forks source link

how to change ZipEntry Name? #140

Closed andyhebear closed 8 years ago

andyhebear commented 8 years ago

how to change ZipEntry Name? ZipArchive za=ZipArchive.Open("test.zip"); string oldName="zt/test_old.txt"; string newName="zt2/test.txt"; SharpCompress.Archive.Zip.ZipArchiveEntry findfile=null; foreach (var ze in za.Entries) { if (ze.IsDirectory) continue; if (string.Compare(ze.Key, oldName) == 0) { findfile = ze; break; } } if (findfile != null) { MemoryStream ms=GetUnCompressStream(findfile);
za.AddEntry(newName, ms,true,ms.Length,findfile.LastModifiedTime); za.RemoveEntry(findfile); findfile.Close(); }

this method is Unfriendly.

And consumes a lot of performance.

andyhebear commented 8 years ago

and how to change dir name in Zip? there has fast way?

adamhathcock commented 8 years ago

You can't change names without rebuilding the entire zip file.

I could probably change something to get around recompressing but that's a lot of work for a minor use-case. You're welcome to try with a PR.