This project is read-only.

What context is AddFileFromString() available in?

Jan 9, 2010 at 10:32 PM

I'm using the current 1.9 code build of Ionic.Zip.dll. I've seen a couple of references to a method called AddFileFromString() here in the discussions but it doesn't seem to be available to me and I can't find any documentation references to it in the CHM file. Is it only available in special contexts? It would be very useful for what I'm working on and I'd really like to be able to use it if possible.

Jan 10, 2010 at 5:16 AM

Sorry, just after posting I noticed the new syntax, question closed:

ZipEntry e = zip.AddEntry("README.txt", "", content);

Jan 10, 2010 at 3:47 PM

Actually, that was the syntax in v1.8.  But the middle param is completely useless, so in v1.9, the syntax is

ZipEntry e = zip.AddEntry("Filename.txt", "This is the string content for the entry."); 

If there are examples showing that other syntax, let me know, I'd like to update them.

Jan 11, 2010 at 7:12 AM
Edited Jan 11, 2010 at 7:15 AM

Hi Cheeso,

I realized that the syntax had changed as soon as I actually tried it out... :-)) Yes, there are a few examples in the CHM, you'll find them if you search for AddEntry I think (I'm not on the computer with VS at the moment). There's also a programming example showing AddFileFromString() in the code, if you do a full text search in the CHM you'll find that too.

I have a small speed question: I'm writing a utility that renames all the files in a zip by adding/removing/changing a prefix/suffix and then updates the hyperlinks between the files in all the files. At the moment I'm doing this by reading the file content out to strings, processing the hyperlinks in each string individually and assigning the new strings to the zip with UpdateEntry. Then I perform the rename at the end and do the zip.Save() in one operation.

Currently this takes about 20 seconds on an Athlon X2 for a zip containing over 600 files with a lot of links (processing 2x 600 potential link types in each file), which is OK, but some users will have zips containing thousands of files. Would I get a significant speed advantage if I read the entire zip out to a single uncompressed zip in a single stream and work on it there? I'm not yet even sure if this is possible and before I spend the time to figure out how to do it, it would be good to know whether it will really be worth it...


Jan 11, 2010 at 7:54 AM

Thanks, Tim, I'll get those stale examples corrected.

On the speed thing, I would be guessing.  Best way to know is to just test it. But I would think adding an entry and then updating it would be less efficient than just modifying the string before adding the entry.   But I don't know if that works for you.  

Good luck.



Jan 11, 2010 at 8:13 AM

Thanks for the information. The entries already exist so they do need to be updated, but I've reduced the I/O overheads as far as is possible while still working on discrete files. It's definitely a lot faster than what I was originally doing, which was individual streaming and an individual zip.Save() on each entry.. ;). For the moment it's fast enough, I'll look into the other options later.

Congratulations on the 1.9 release, it's looking great! I'll be sending some moolah your way as soon as this utility starts producing some of its own...