C# sharpziplib+;提取单个文件

C# sharpziplib+;提取单个文件,c#,sharpziplib,C#,Sharpziplib,每当我尝试获取文件时,输入流的长度(s.length)总是为零,我做错了什么?ZipEntry是有效的,并且具有适当的文件大小,等等 以下是我使用的代码: public static byte[] GetFileFromZip(string zipPath, string fileName) { byte[] ret = null; ZipFile zf = new ZipFile(zipPath); ZipEntry ze = zf.GetEntry(fileName)

每当我尝试获取文件时,输入流的长度(s.length)总是为零,我做错了什么?ZipEntry是有效的,并且具有适当的文件大小,等等

以下是我使用的代码:

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[s.Length];
        s.Read(ret, 0, ret.Length);
    }

    return ret;
}

输入流将没有长度。改用
ZipEntry.Size

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