The compression software reports an error when opening the zip file. #530

Closed
opened 2026-01-29 22:13:23 +00:00 by claunia · 5 comments
Owner

Originally created by @suoyukii on GitHub (Aug 4, 2022).

Bandizip and Windows OS Explorer prompt an error after opening the zip file.

P1$3W6QI9R%O9BFU40C4TJE


Version
Windows 11 21H2 (22000.832)
CPU AMD Ryzen 5 5600X
SDK 6.0.302
Runtime 6.0.7
SharpCompress 0.32.2

Code:

void CompressionFile(string file_path, string zip_path)
{
    try
    {
        //ArchiveEncoding ArchiveEncoding = new();
        //ArchiveEncoding.Default = Encoding.UTF8;
        //WriterOptions options = new(CompressionType.Deflate);
        //options.ArchiveEncoding = ArchiveEncoding;

        FileStream zip = File.OpenWrite(zip_path);
        IWriter zip_writer = WriterFactory.Open(zip, ArchiveType.Zip, CompressionType.Deflate);
        //IWriter zip_writer = WriterFactory.Open(zip, ArchiveType.Zip, options);

        if (File.Exists(file_path))
        {
            zip_writer.Write(new FileInfo(file_path).Name, file_path);
        }
        else if (Directory.Exists(file_path))
        {
            zip_writer.WriteAll(file_path, "*", SearchOption.AllDirectories);
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        Console.WriteLine(ex.StackTrace);
    }
}
Originally created by @suoyukii on GitHub (Aug 4, 2022). Bandizip and Windows OS Explorer prompt an error after opening the zip file. ![P1$3W6QI9R%O9BFU40C4TJE](https://user-images.githubusercontent.com/16282726/182791355-37cd3121-7efb-4689-82a1-791531a90c55.png) --- ||Version| |-|-| |Windows 11|21H2 (22000.832)| |CPU|AMD Ryzen 5 5600X| |SDK|6.0.302| |Runtime|6.0.7| |SharpCompress|0.32.2| Code: ```csharp void CompressionFile(string file_path, string zip_path) { try { //ArchiveEncoding ArchiveEncoding = new(); //ArchiveEncoding.Default = Encoding.UTF8; //WriterOptions options = new(CompressionType.Deflate); //options.ArchiveEncoding = ArchiveEncoding; FileStream zip = File.OpenWrite(zip_path); IWriter zip_writer = WriterFactory.Open(zip, ArchiveType.Zip, CompressionType.Deflate); //IWriter zip_writer = WriterFactory.Open(zip, ArchiveType.Zip, options); if (File.Exists(file_path)) { zip_writer.Write(new FileInfo(file_path).Name, file_path); } else if (Directory.Exists(file_path)) { zip_writer.WriteAll(file_path, "*", SearchOption.AllDirectories); } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } } ```
Author
Owner

@adamhathcock commented on GitHub (Aug 4, 2022):

you're not calling dispose on anything

@adamhathcock commented on GitHub (Aug 4, 2022): you're not calling dispose on anything
Author
Owner

@suoyukii commented on GitHub (Aug 4, 2022):

I used this code to compress and package a directory with files, and then opened it with Bandizip and Explorer and reported an error.
I can send you the zip file with the problem for analysis, and you may understand.

@suoyukii commented on GitHub (Aug 4, 2022): I used this code to compress and package a directory with files, and then opened it with Bandizip and Explorer and reported an error. I can send you the zip file with the problem for analysis, and you may understand.
Author
Owner

@suoyukii commented on GitHub (Aug 4, 2022):

cat.zip

@suoyukii commented on GitHub (Aug 4, 2022): [cat.zip](https://github.com/adamhathcock/sharpcompress/files/9259674/cat.zip)
Author
Owner

@adamhathcock commented on GitHub (Aug 4, 2022):

you need to dispose the writer and all your stream objects.

@adamhathcock commented on GitHub (Aug 4, 2022): you need to dispose the writer and all your stream objects.
Author
Owner

@suoyukii commented on GitHub (Aug 4, 2022):

@adamhathcock Thank you!

@suoyukii commented on GitHub (Aug 4, 2022): @adamhathcock Thank you!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#530