Link-HRSystems
asked on
Trying to extract a file from a zip file (SharpZLib) using a Memory Stream, and then save the entry as a byte array
Hello please could someone help me try and make sense of SharpZLib. What I am trying to do is extract a file from a list of files, and then saving this entry as a byte[]. The problem is I am having problems actually working out how to do this using the component. Most examples I have looked at relate to saving the entry to disk, and this is not possible as I am using ASP 2.0.
This is my code as it stands:
zipFile = new ICSharpCode.SharpZipLib.Zi p.ZipFile( this.edtFilename.PostedFil e.InputStr eam );
foreach ( ZipEntry entry in zipFile )
{
Stream stream = new MemoryStream();
stream = zipFile.GetInputStream(ent ry);
Byte[] bytes;
bytes = ReadFully(stream);
}
However when I use this example code, the GetInputStream stream length is 0. The output stream has to be stored in memory as we write the zip entry file as byte[] to the database.
Any help is appreciated, thanks.
This is my code as it stands:
zipFile = new ICSharpCode.SharpZipLib.Zi
foreach ( ZipEntry entry in zipFile )
{
Stream stream = new MemoryStream();
stream = zipFile.GetInputStream(ent
Byte[] bytes;
bytes = ReadFully(stream);
}
However when I use this example code, the GetInputStream stream length is 0. The output stream has to be stored in memory as we write the zip entry file as byte[] to the database.
Any help is appreciated, thanks.
ASKER
Hi, the example works for a FileStream though. I am unable to use a file stream due to the application being ASP.net based. The problem I am having is trying to get the output stream from an extracted file and all examples I have looked at, seem to rely on the output being a file stream. Is it possible you could convert the above method to work with MemoryStreams only? Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's just what I needed, thank you. Streams totally baffle me sometimes :)
ASKER
That's just what I needed, thank you. Streams totally baffle me sometimes :)
If you want to extract all it is very similar:
Code:
Open in new window