2014-06-20 1 views
1

DotNetZip 1.9.3 라이브러리를 사용하고 있으며 BZip2와 AES256을 모두 사용하여 1 개의 아카이브에 1 개의 항목을 넣었습니다. ZipOutputStream 제대로 작동하지만 ZipInputStream 잘못된 BZip2 헤더를 가져옵니다. commom deflate 알고리즘을 사용하면 모든 것이 정상입니다.DotNetZip ZipInputStream 문제

protected override Stream OnCreateStream(string path) 
{ 
    var encryptedStream = new ZipOutputStream(base.OnCreateStream(path)) 
    { 
     Password = this.Password, 
     Encryption = EncryptionAlgorithm.WinZipAes256, 
    //  CompressionMethod = CompressionMethod.BZip2, 
    }; 
    var entry = encryptedStream.PutNextEntry("_"); 
    return encryptedStream; 
} 

을 그리고 작업이 완료되면 나는 항상 ZipOutputStream이 처분 :

나는 (파일 스트림에서) ZipOutputStream이를 만듭니다. I 주석 압축 방법 및 ZipInputStream을 읽으려고하면 내가 예외를 얻을

protected override Stream OnCreateStream(string path) 
{ 
    ZipInputStream stream = new ZipInputStream(base.OnCreateStream(path)) 
    { 
     Password = this.Password 
    }; 
    var entry = stream.GetNextEntry(); 
    return stream; 
} 

:

Not a valid BZip2 stream. byte 1, expected '90', got '107' 
    в Ionic.BZip2.BZip2InputStream.CheckMagicChar(Char expected, Int32 position) 
    в Ionic.BZip2.BZip2InputStream.init() 
    в Ionic.BZip2.BZip2InputStream..ctor(Stream input, Boolean leaveOpen) 
    в Ionic.Zip.ZipEntry.GetExtractDecompressor(Stream input2) 
    в Ionic.Zip.ZipEntry.InternalOpenReader(String password) 
    в Ionic.Zip.ZipInputStream.SetupStream() 
    в Ionic.Zip.ZipInputStream.Read(Byte[] buffer, Int32 offset, Int32 count) 
    в System.IO.StreamReader.ReadBuffer(Char[] userBuffer, Int32 userOffset, Int32 desiredChars, Boolean& readToUserBuffer) 
    в System.IO.StreamReader.Read(Char[] buffer, Int32 index, Int32 count) 

어떤 아이디어를

스트림 우편 아카이브를 읽어?

답변

2

내가 꽤 오래된 주제를 알고 있지만,이 솔루션에 대한 인터넷 검색을 누군가를 위해 여전히 유용 할 수 있습니다.

압축 속성 설정자를 호출하는 순서가 중요하다는 것을 알고 있습니다. AddEntry이 DotNetZip에 의해 읽을 ZIP 파일을 만드는 전에

zip.CompressionMethod = CompressionMethod.BZip2; 
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression; 

세트. 바로 저장하기 전에 CompressionMethodCompressionLevel 인 설정의 오른쪽 장소 :

using (var zip = new ZipFile(zipPath, Encoding.UTF8)) 
{ 
    // set zip properties except compression ones 
    zip.Encryption = EncryptionAlgorithm.WinZipAes256; 
    zip.Password = "pass"; 

    // add entries 
    zip.AddEntry("whatever", stream); 

    // set compression just before Save() 
    zip.CompressionMethod = CompressionMethod.BZip2; 
    zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression; 

    zip.Save(); 
} 
+0

이 내가 가진 EXAKT 문제였다. 재미있는 점은 압축 파일과 압축 방법을 사용하면 저장하기 직전에 파일이 10-20 % 더 커집니다.하지만 읽을 수도 있습니다. – JensB

0

이것은 아마도 문제에 힌트 :

gzip 같은

는,의 bzip2는 데이터 압축기이다. 타르 (tar) 또는 ZIP와 같은 아카이버가 아닙니다. 프로그램 자체는 여러 파일, 암호화 또는 아카이브 분할을위한 기능이 없지만, UNIX의 전통에서는 이러한 작업을 위해 별도의 외부 유틸리티 인 tar 및 GnuPG에 의존합니다.

출처 : Wikipedia