mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
[PR #709] [MERGED] Generalized factories to readers and writers. #1177
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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:
master← Head:master📝 Commits (6)
8775b65Generalized factories to readers and writers.ca3d088generalized multipart archive interfacea223930Generalized archive creation37c7251added additional TAR extensions17dab3dsmall refactor891d5d3commented 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:
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.TryOpenReaderthat 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,IReaderFactoryandIWriterFactoryon 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.