代码之家  ›  专栏  ›  技术社区  ›  schmoopy

sharpziplib+提取单个文件

  •  3
  • schmoopy  · 技术社区  · 16 年前

    以下是我使用的代码:

    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;
    }
    
    1 回复  |  直到 16 年前
        1
  •  10
  •   Samuel Neff    16 年前

    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;
    }
    
    推荐文章