Cannot Add Empty Directories to Archives #669

Closed
opened 2026-01-29 22:15:31 +00:00 by claunia · 0 comments
Owner

Originally created by @adanddev on GitHub (Nov 20, 2024).

Originally assigned to: @Copilot on GitHub.

Description
Currently, SharpCompress lacks support for adding empty directories to archives. When using IWriter or IWritableArchive interfaces 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:

  • Deployment packages where empty folders are placeholders for future files.
  • Compression of directories with empty folders that need to be preserved, ensuring consistency in archive content.
  • Development and build systems that rely on specific folder structures, including empty directories, to function correctly.

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

archive.AddDirectoryEntry(relativePath);

or ensuring that calling AddEntry with Stream.Null and 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.

Originally created by @adanddev on GitHub (Nov 20, 2024). Originally assigned to: @Copilot on GitHub. **Description** Currently, SharpCompress lacks support for adding empty directories to archives. When using `IWriter` or `IWritableArchive `interfaces 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: - Deployment packages where empty folders are placeholders for future files. - Compression of directories with empty folders that need to be preserved, ensuring consistency in archive content. - Development and build systems that rely on specific folder structures, including empty directories, to function correctly. **Proposed Solution** Consider adding a way to support empty directory entries in `IWriter `or `IWritableArchive`, allowing a `Stream.Null` or a specific method for empty directories, similar to: `archive.AddDirectoryEntry(relativePath);` or ensuring that calling `AddEntry `with `Stream.Null `and 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.
claunia added the enhancementup for grabs labels 2026-01-29 22:15:31 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#669