adamhathcock / sharpcompress

SharpCompress is a fully managed C# library to deal with many compression types and formats.
MIT License
2.29k stars 482 forks source link

Cannot Add Empty Directories to Archives #881

Open adanddev opened 1 week ago

adanddev commented 1 week ago

Description Currently, SharpCompress lacks support for adding empty directories to archives. When using IWriter or IWritableArchiveinterfaces to add entries, there is no straightforward way to include empty directories, as the library appears to ignore directory entries that lack files. This limits use cases where the exact directory structure, including empty folders, is essential, such as preserving the file structure during compression or in deployment packages.

Motivation Including empty directories is important in scenarios where the directory structure needs to be faithfully recreated after decompression. This is especially useful for:

Proposed Solution Consider adding a way to support empty directory entries in IWriteror IWritableArchive, allowing a Stream.Null or a specific method for empty directories, similar to:

archive.AddDirectoryEntry(relativePath);

or ensuring that calling AddEntrywith Stream.Nulland size: 0 explicitly adds an empty directory entry.

Alternative Workaround Currently, the only workaround is to create a temporary file in each empty directory or use a marker file to ensure that the directory is not skipped, which is not ideal and requires post-extraction cleanup.

Thank you for considering this feature enhancement.