c# - Zip Archive: Entry name problems -


i experienced 2 problems zip archive want share here , ask experience well:

  1. duplicate directories if create 2 or more directories of same name in archive(below root) archive contains both directories (when looking in entries) every zip-application (also windows) shows me 1 directory. did this:

    using (ziparchive = zipfile.open("d:\\zip.zip", ziparchivemode.update)) {     ziparchiveentry e1 = a.createentry("dir1/");     ziparchiveentry e2 = a.createentry("dir1/");      foreach (var afile in a.entries)     {         console.writeline(afile.fullname);     } } 

the level doesn't matter, if go 1 level down ("dir1/dir2/") same happens.

  1. missing entries mistake put slash first character of directory or filename. both entries visible in entries property, not visible on zip-applications (also windows):

    using (ziparchive = zipfile.open("d:\\zip.zip", ziparchivemode.update)) {     ziparchiveentry e1 = a.createentry("/dir1");     ziparchiveentry e2 = a.createentry("/dir1.txt");      foreach (var afile in a.entries)     {         console.writeline(afile.fullname);     } } 

have of ever experienced problem? problem zip can it, no application able display it, or mistake not handled creation routines?

thanks martin

both of these behaviors normal. arise misunderstanding of how .zip archives work, , how ziparchive in particular operates.


first, mentioned in answer other ziparchive question, there not "directory" per se in .zip archive. exist virtue of entries created directory names in names.

so if add entry named dir1/dir2/test1.txt, "directories" named dir1 , dir2. if delete entry, directories disappear.

so when think creating directories, you're creating new entries. , documentation says, can create more 1 entry same name. of course, happen in case depends on tool use open archive. many (as you've found) show first item.

the solution not try create directories. doesn't work. write entries directory paths want. directories "created" implicitly virtue of actual items being named being in directories.


far leading / character goes, specification file paths in .zip archive should "relative", should not include leading / character. the msdn documentation calls out specifically:

the entryname string should reflect relative path of entry want create within zip archive. there no restriction on string provide. however, if not formatted relative path, entry created, may exception when extract contents of zip archive.

it seems in case, no exception occurs, don't have access archive entry when archive opened in other tools. solution is, "don't that".


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -