Whenever i try to get the file, the length of the input stream (s.Length) is always zero, what am i doing wrong? ZipEntry is valid and has the proper size of the file, etc.
Here is the code im using:
public static byte[] GetFileFromZip(string zipPath, string fileName)
{
byte[] ret = null;
ZipF开发者_如何学Goile zf = new ZipFile(zipPath);
ZipEntry ze = zf.GetEntry(fileName);
if (ze != null)
{
Stream s = zf.GetInputStream(ze);
ret = new byte[s.Length];
s.Read(ret, 0, ret.Length);
}
return ret;
}
The input stream will not have a length. Use ZipEntry.Size
instead.
public static byte[] GetFileFromZip(string zipPath, string fileName)
{
byte[] ret = null;
ZipFile zf = new ZipFile(zipPath);
ZipEntry ze = zf.GetEntry(fileName);
if (ze != null)
{
Stream s = zf.GetInputStream(ze);
ret = new byte[ze.Size];
s.Read(ret, 0, ret.Length);
}
return ret;
}
精彩评论