Posted By

rengber on 08/07/07


Tagged

archive zip hashTable SharpZipLib


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

ad5qa
umang_nine
LeeRJohnson


Building a Hashtable of File Contents from a Zip File Containing Multiple Files and Folders


 / Published in: C#
 

  1. public static Hashtable BuildFileTable(Stream s)
  2. {
  3. Hashtable retVal = new Hashtable();
  4. ZipInputStream zips = new ZipInputStream(s);
  5. ZipEntry ze = zips.GetNextEntry();
  6. while (ze != null)
  7. {
  8. if (ze.IsFile)
  9. {
  10. retVal.Add(ze.Name, GetContentFromZipEntry(ze, zips));
  11. }
  12. ze = zips.GetNextEntry();
  13. }
  14. return retVal;
  15. }
  16.  
  17. public static string GetContentFromZipEntry(ZipEntry ze, ZipInputStream zips)
  18. {
  19. string retVal = string.Empty;
  20. if (ze.Offset > int.MaxValue || ze.Size > int.MaxValue)
  21. {
  22. throw new ApplicationException("Files larger than 4gb not supported.");
  23. }
  24. Byte[] buffer = new byte[ze.Size];
  25. int numRead = zips.Read(buffer, Convert.ToInt32(ze.Offset), buffer.Length);
  26. MemoryStream ms = new MemoryStream(buffer);
  27. StreamReader sr = new StreamReader(ms);
  28. retVal = sr.ReadToEnd().Trim();
  29.  
  30. return retVal;
  31. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Ashwin on November 22, 2018

I want to know everything about alarm feature of windows 10 operating system desktop, and like to activate this also in to my desktop computer. Am getting ideas with this online tutorial turn off alarm windows 10 and found this place so informative. Each and every steps is clearly explained here that is so helpful.

You need to login to post a comment.