[PR #709] [MERGED] Generalized factories to readers and writers. #1177

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

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/709
Author: @vpenades
Created: 11/29/2022
Status: Merged
Merged: 12/6/2022
Merged by: @adamhathcock

Base: masterHead: master


📝 Commits (6)

  • 8775b65 Generalized factories to readers and writers.
  • ca3d088 generalized multipart archive interface
  • a223930 Generalized archive creation
  • 37c7251 added additional TAR extensions
  • 17dab3d small refactor
  • 891d5d3 commented unsupported extensions

📊 Changes

20 files changed (+990 additions, -514 deletions)

View changed files

📝 src/SharpCompress/Archives/ArchiveFactory.cs (+53 -104)
src/SharpCompress/Archives/GZip/GZipArchiveFactory.cs (+0 -51)
📝 src/SharpCompress/Archives/IArchiveFactory.cs (+7 -38)
src/SharpCompress/Archives/IMultiArchiveFactory.cs (+40 -0)
src/SharpCompress/Archives/IWriteableArchiveFactory.cs (+27 -0)
src/SharpCompress/Archives/Rar/RarArchiveFactory.cs (+0 -52)
src/SharpCompress/Archives/SevenZip/SevenZipArchiveFactory.cs (+0 -51)
src/SharpCompress/Archives/Tar/TarArchiveFactory.cs (+0 -52)
src/SharpCompress/Archives/Zip/ZipArchiveFactory.cs (+0 -62)
src/SharpCompress/Factories/Factory.cs (+92 -0)
src/SharpCompress/Factories/GZipFactory.cs (+143 -0)
src/SharpCompress/Factories/IFactory.cs (+55 -0)
src/SharpCompress/Factories/RarFactory.cs (+93 -0)
src/SharpCompress/Factories/SevenZipFactory.cs (+85 -0)
src/SharpCompress/Factories/TarFactory.cs (+197 -0)
src/SharpCompress/Factories/ZipFactory.cs (+140 -0)
src/SharpCompress/Readers/IReaderFactory.cs (+23 -0)
📝 src/SharpCompress/Readers/ReaderFactory.cs (+6 -76)
src/SharpCompress/Writers/IWriterFactory.cs (+16 -0)
📝 src/SharpCompress/Writers/WriterFactory.cs (+13 -28)

📄 Description

What's changed:

  • Created a new entry point for registering factories in a new folder called Factories.Factory (for lack of a better name)
  • I've moved the ArchiveFactories (ZipArchiveFactory, etc) to the new Factories folder
  • Added new interfaces IReaderFactory and IWriterFactory

With these new interfaces in place, I've been able to clean up some code; the idea is to eventually get rid of all the if zip else if gzip else if rar else if tar... spaghetti blocks. This will simplify adding new formats because everything will be centralized in a single factory class.

Supporting the TAR.GZ and variants has been specially tricky, I wanted to retain as much of the original logic as possible to avoid breaking something, so I had to create an internal overridable method Factory.TryOpenReader that handles the internal RewindableStream logic. Fortunately, new formats will not needs this.

From now on, adding a new archive format is about extending "Factory" class, and implement any of IArchiveFactory, IReaderFactory and IWriterFactory on it.

SevenZipFactory is an example of a factory implementing only IArchiveFactory but not IReaderFactory. To some degree, these interfaces work as decorators, so an archive format only needs to implement the interfaces it can support.

Future: there's still some spaghettis around, like getting multipart files, or creating a writeable archive... I think these could be done by adding additional decoration interfaces.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/709 **Author:** [@vpenades](https://github.com/vpenades) **Created:** 11/29/2022 **Status:** ✅ Merged **Merged:** 12/6/2022 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (6) - [`8775b65`](https://github.com/adamhathcock/sharpcompress/commit/8775b65f588f300e9830970d59e392557cadf9bb) Generalized factories to readers and writers. - [`ca3d088`](https://github.com/adamhathcock/sharpcompress/commit/ca3d0887854bae112aba74d1baa45a4c2e6c0203) generalized multipart archive interface - [`a223930`](https://github.com/adamhathcock/sharpcompress/commit/a22393075f372422caf4d3356a477c74948f63f6) Generalized archive creation - [`37c7251`](https://github.com/adamhathcock/sharpcompress/commit/37c7251ec90028819ede962cc1522db7f55a6300) added additional TAR extensions - [`17dab3d`](https://github.com/adamhathcock/sharpcompress/commit/17dab3df343b5d96524d3277e8f6b3144d090fa9) small refactor - [`891d5d3`](https://github.com/adamhathcock/sharpcompress/commit/891d5d3c35992fe88a5cc945a55032918c15e0b1) commented unsupported extensions ### 📊 Changes **20 files changed** (+990 additions, -514 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/Archives/ArchiveFactory.cs` (+53 -104) ➖ `src/SharpCompress/Archives/GZip/GZipArchiveFactory.cs` (+0 -51) 📝 `src/SharpCompress/Archives/IArchiveFactory.cs` (+7 -38) ➕ `src/SharpCompress/Archives/IMultiArchiveFactory.cs` (+40 -0) ➕ `src/SharpCompress/Archives/IWriteableArchiveFactory.cs` (+27 -0) ➖ `src/SharpCompress/Archives/Rar/RarArchiveFactory.cs` (+0 -52) ➖ `src/SharpCompress/Archives/SevenZip/SevenZipArchiveFactory.cs` (+0 -51) ➖ `src/SharpCompress/Archives/Tar/TarArchiveFactory.cs` (+0 -52) ➖ `src/SharpCompress/Archives/Zip/ZipArchiveFactory.cs` (+0 -62) ➕ `src/SharpCompress/Factories/Factory.cs` (+92 -0) ➕ `src/SharpCompress/Factories/GZipFactory.cs` (+143 -0) ➕ `src/SharpCompress/Factories/IFactory.cs` (+55 -0) ➕ `src/SharpCompress/Factories/RarFactory.cs` (+93 -0) ➕ `src/SharpCompress/Factories/SevenZipFactory.cs` (+85 -0) ➕ `src/SharpCompress/Factories/TarFactory.cs` (+197 -0) ➕ `src/SharpCompress/Factories/ZipFactory.cs` (+140 -0) ➕ `src/SharpCompress/Readers/IReaderFactory.cs` (+23 -0) 📝 `src/SharpCompress/Readers/ReaderFactory.cs` (+6 -76) ➕ `src/SharpCompress/Writers/IWriterFactory.cs` (+16 -0) 📝 `src/SharpCompress/Writers/WriterFactory.cs` (+13 -28) </details> ### 📄 Description What's changed: - Created a new entry point for registering factories in a new folder called Factories.Factory (for lack of a better name) - I've moved the ArchiveFactories (ZipArchiveFactory, etc) to the new Factories folder - Added new interfaces IReaderFactory and IWriterFactory With these new interfaces in place, I've been able to clean up some code; the idea is to eventually get rid of all the `if zip else if gzip else if rar else if tar...` spaghetti blocks. This will simplify adding new formats because everything will be centralized in a single factory class. Supporting the TAR.GZ and variants has been specially tricky, I wanted to retain as much of the original logic as possible to avoid breaking something, so I had to create an internal overridable method `Factory.TryOpenReader` that handles the internal RewindableStream logic. Fortunately, new formats will not needs this. From now on, adding a new archive format is about extending "Factory" class, and implement any of `IArchiveFactory`, `IReaderFactory` and `IWriterFactory` on it. SevenZipFactory is an example of a factory implementing only IArchiveFactory but not IReaderFactory. To some degree, these interfaces work as _decorators_, so an archive format only needs to implement the interfaces it can support. Future: there's still some spaghettis around, like getting multipart files, or creating a writeable archive... I think these could be done by adding additional decoration interfaces. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:19:22 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1177