dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.37k stars 4.75k forks source link

ZipArchive Contructor with file. #48278

Closed EskeRahn closed 3 years ago

EskeRahn commented 3 years ago

Background and Motivation

Opening a ZipArchive with a stream and a file today looks oddly different

I would suggest to add a constructor using a filename

Similar to the existing stream constructor

ZipArchive za2 = new System.IO.Compression.ZipArchive  (stream  , zipArchiveMode, keepOpen, encoding);

With the same function as the current syntax

ZipArchive za3 =     System.IO.Compression.ZipFile.Open(FileName, ZipArchiveMode,           encoding);

I would like to propose this overlay:

Proposed API

                     System.IO.Compression.ZipArchive  (FileName, zipArchiveMode,           encoding);

Usage Examples

ZipArchive za1 = new System.IO.Compression.ZipArchive  (FileName, zipArchiveMode,           encoding);

Alternative Designs

Of course the old Open method syntax should be kept for compatibility, and could even be supplemented with a stream variant.

Risks

It would make no functional difference, but would give a more 'clean' interface, similar to how e.g. StreamReader are accepting either a name or a stream.

Remarks

Suggested label: area-System.IO.Compression

adamsitnik commented 3 years ago

Is there any scenario where Open method lacks something and introducing the new ctor would allow for that?

EskeRahn commented 3 years ago

Is there any scenario where Open method lacks something and introducing the new ctor would allow for that?

No, AFAIK, it is purely a cosmetic issue, of having the code/interface look cleaner.

adamsitnik commented 3 years ago

it is purely a cosmetic issue

I am sorry but we don't add new APIs to address cosmetic issues. One reason is code size (every new API increases the code size and we do care about keeping it as small as possible), another is the ease of learning (the more APIs the harder it is to learn all of them and choose which one to use). Thank you!