开发者

sharpziplib + extracting single file

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜