mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-06 13:34:58 +00:00
Can't open Zip archive #202
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Sigurd2656 on GitHub (Jun 26, 2017).
I'm passing a memory stream which I get from byte array which is zip archive with one MS word file. It works fine if I compress this file to *.7z or *.rar.
var archive = ArchiveFactory.Open(archiveMemStream);On this step I get InvalidOperationException. Additional information: Cannot determine compressed stream type. Supported Archive Formats: Zip, GZip, Tar, Rar, 7Zip, LZip
@adamhathcock commented on GitHub (Jun 26, 2017):
Need more code and probably a sample file.
Are you resetting the memory streams position after loading it?
@Sigurd2656 commented on GitHub (Jun 27, 2017):
Well, no. Now I do and it works fine with zip as well. It's strange since other formats worked.
Here is the simplified test code I worked with, I'll leave it for history.
`public static IEnumerable DecompressArchive(byte[] compressedBytes)
{
var outputFiles = new List();
And thank you for great product.
Edit: I've noticed that decompressed file size is slightly larger than if it was decompressed conventional way with winrar or 7zip. But file is not corrupted and opens without errrors.
@adamhathcock commented on GitHub (Jun 27, 2017):
Make sure you're not writing extra bytes to the file. You don't need to write to a memory stream usually.
@Sigurd2656 commented on GitHub (Jun 28, 2017):
Yeah, I figured out that buffer obviously has some extra bytes and fixed that. I'm using stream because I have to write directly to DB, without using HDD, since I get those zips and rars through http GETs as byte arrays.
And one more issue. I've heard how bad zip's locale situation is, my filenames inside zip have Cyrillic characters in their names and I've tried all known to me encodings for ArchiveEncoding.Default property, but entry.Key is still malformed.
Example file link.
www.e-disclosure.ru/portal/FileLoad.ashx?Fileid=1175800
@adamhathcock commented on GitHub (Jun 28, 2017):
Are you sure the file is encoding properly? Just need sharpcompress to decode properly?
@Sigurd2656 commented on GitHub (Jun 28, 2017):
Well, I made it. All I had to do is
SharpCompress.Common.ArchiveEncoding.Default = Encoding.GetEncoding(866);for .zip archives with russian filenames inside. Which is Cyrillic DOS (yes, that old) codepage.
The problem was that zip still uses DOS codepages to encode filenames.
Now, instead of
��⠢ �� ���� ������।������ ������.pdfI get normal
Устав АО Газпром газораспределение Обнинск.pdfAnd thanks for the help.
@adamhathcock commented on GitHub (Jun 28, 2017):
Glad it worked out