Archives with compressed empty files can not be opened with standart Mac Archive Utility #203

Open
opened 2026-01-29 22:08:19 +00:00 by claunia · 3 comments
Owner

Originally created by @KvanTTT on GitHub (Jul 3, 2017).

Originally assigned to: @adamhathcock on GitHub.

The archive empty_file.zip from 7z can be opened with Mac "Archive Utility" unlike archive
empty_file_sharpcompress.zip that has been compressed with SharpCompress using ZipWriter. 7z unpack such files fine.

I'm trying to open this archive but get the error "Error opening a zip file: No such file or directory".

Current workaround: check size of every file and ignore zero-length files:

using (var sourceFileStream = new FileStream(fileName, FileMode.Open))
{
    if (sourceFileStream.Length != 0)
    {
        zipWriter.Write(originFileName, sourceFileStream);
    }
}
Originally created by @KvanTTT on GitHub (Jul 3, 2017). Originally assigned to: @adamhathcock on GitHub. The archive [empty_file.zip](https://github.com/adamhathcock/sharpcompress/files/1120475/empty_file.zip) from 7z can be opened with Mac "Archive Utility" unlike archive [empty_file_sharpcompress.zip](https://github.com/adamhathcock/sharpcompress/files/1120476/empty_file_sharpcompress.zip) that has been compressed with SharpCompress using [`ZipWriter`](https://github.com/adamhathcock/sharpcompress/blob/master/src/SharpCompress/Writers/Zip/ZipWriter.cs). 7z unpack such files fine. I'm trying to open this archive but get the error "Error opening a zip file: No such file or directory". Current workaround: check size of every file and ignore zero-length files: ```CSharp using (var sourceFileStream = new FileStream(fileName, FileMode.Open)) { if (sourceFileStream.Length != 0) { zipWriter.Write(originFileName, sourceFileStream); } } ```
claunia added the bug label 2026-01-29 22:08:19 +00:00
Author
Owner

@adamhathcock commented on GitHub (Jul 5, 2017):

I'm currently on holiday for a while. I'll have to fix look to fix this afterwards.

@adamhathcock commented on GitHub (Jul 5, 2017): I'm currently on holiday for a while. I'll have to fix look to fix this afterwards.
Author
Owner

@adamhathcock commented on GitHub (Jul 17, 2017):

Is this the complete code sample that you use with empty_file.zip? It looks incorrect.

I don't have an issue writing to a null stream or anything.

@adamhathcock commented on GitHub (Jul 17, 2017): Is this the complete code sample that you use with empty_file.zip? It looks incorrect. I don't have an issue writing to a null stream or anything.
Author
Owner

@KvanTTT commented on GitHub (Oct 12, 2017):

Sure! Here is a full C# code with input empty_file and output empty_file_sharpcompress.zip archive.

Program.cs
using SharpCompress.Common;
using SharpCompress.Writers.Zip;
using System.IO;

namespace EmptyFileAndMacArchiveUtility
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputFileName = "empty_file";
            string outputArchiveName = "empty_file_sharpcompress.zip";

            using (var writeStream = new FileStream(outputArchiveName, FileMode.Create))
            {
                using (var zipWriter = new ZipWriter(writeStream, new ZipWriterOptions(CompressionType.Deflate)))
                {
                    using (var sourceFileStream = new FileStream(inputFileName, FileMode.Open))
                    {
                        //if (sourceFileStream.Length != 0) // Comment to get rid of "No such file or directory" error.
                        {
                            zipWriter.Write(inputFileName, sourceFileStream, new ZipWriterEntryOptions());
                        }
                    }
                }
            }
        }
    }
}

With above code I'm getting the following error on Mac:

Unable to expand, No such file or directory.

7z extracts such archive without problems.

@KvanTTT commented on GitHub (Oct 12, 2017): Sure! Here is a full C# code with input `empty_file` and output `empty_file_sharpcompress.zip` archive. <details> <summary>Program.cs</summary> ```CSharp using SharpCompress.Common; using SharpCompress.Writers.Zip; using System.IO; namespace EmptyFileAndMacArchiveUtility { class Program { static void Main(string[] args) { string inputFileName = "empty_file"; string outputArchiveName = "empty_file_sharpcompress.zip"; using (var writeStream = new FileStream(outputArchiveName, FileMode.Create)) { using (var zipWriter = new ZipWriter(writeStream, new ZipWriterOptions(CompressionType.Deflate))) { using (var sourceFileStream = new FileStream(inputFileName, FileMode.Open)) { //if (sourceFileStream.Length != 0) // Comment to get rid of "No such file or directory" error. { zipWriter.Write(inputFileName, sourceFileStream, new ZipWriterEntryOptions()); } } } } } } } ``` </details> <br> With above code I'm getting the following error on Mac: ![Unable to expand, No such file or directory](https://user-images.githubusercontent.com/1150330/31522550-0d3e9ace-afb7-11e7-86c0-1fbc6d136ec3.png). 7z extracts such archive without problems.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#203