Return to Snippet

Revision: 3530
at August 7, 2007 21:28 by rengber


Updated Code
public static Hashtable BuildFileTable(Stream s)
        {
            Hashtable retVal = new Hashtable();
            ZipInputStream zips = new ZipInputStream(s);
            ZipEntry ze = zips.GetNextEntry();
            while (ze != null)
            {
                if (ze.IsFile)
                {
                    retVal.Add(ze.Name, GetContentFromZipEntry(ze, zips));
                }
                ze = zips.GetNextEntry();
            }
            return retVal;
        }

        public static string GetContentFromZipEntry(ZipEntry ze, ZipInputStream zips)
        {
            string retVal = string.Empty;
            if (ze.Offset > int.MaxValue || ze.Size > int.MaxValue)
            {
                throw new ApplicationException("Files larger than 4gb not supported.");
            }
            Byte[] buffer = new byte[ze.Size];
            int numRead = zips.Read(buffer, Convert.ToInt32(ze.Offset), buffer.Length);
            MemoryStream ms = new MemoryStream(buffer);
            StreamReader sr = new StreamReader(ms);
            retVal = sr.ReadToEnd().Trim();

            return retVal;
        }

Revision: 3529
at August 7, 2007 21:28 by rengber


Initial Code
public static Hashtable BuildFileTable(Stream s)
        {
            Hashtable retVal = new Hashtable();
            ZipInputStream zips = new ZipInputStream(s);
            ZipEntry ze = zips.GetNextEntry();
            while (ze != null)
            {
                if (ze.IsFile)
                {
                    retVal.Add(ze.Name, GetContentFromZipEntry(ze, zips));
                }
                ze = zips.GetNextEntry();
            }
            return retVal;
        }

        public static string GetContentFromZipEntry(ZipEntry ze, ZipInputStream zips)
        {
            string retVal = string.Empty;
            if (ze.Offset > int.MaxValue || ze.Size > int.MaxValue)
            {
                throw new ApplicationException("Files larger than 4gb not supported.");
            }
            Byte[] buffer = new byte[ze.Size];
            int numRead = zips.Read(buffer, Convert.ToInt32(ze.Offset), buffer.Length);
            MemoryStream ms = new MemoryStream(buffer);
            StreamReader sr = new StreamReader(ms);
            retVal = sr.ReadToEnd().Trim();

            return retVal;
        }

Initial URL


Initial Description


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

Initial Tags


Initial Language
C#