2010-06-04 5 views
2

파일을 가져올 때마다 입력 스트림의 길이 (s.Length)가 항상 0입니다. 내가 뭘 잘못 했습니까? ZipEntry를 유효 및 사용 코드 IM 여기서 파일의 적절한 크기 등sharpziplib + 단일 파일 압축

를 갖는다 :

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

답변

9

입력 스트림의 길이가없는 것이다. 대신 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; 
} 
+0

감사합니다. – schmoopy