@@ -20,14 +20,18 @@ using (var archive = RarArchive.OpenArchive("file.rar"))
2020using (var archive = SevenZipArchive .OpenArchive (" file.7z" ))
2121using (var archive = GZipArchive .OpenArchive (" file.gz" ))
2222
23- // With options
24- var options = new ReaderOptions
23+ // With fluent options (preferred)
24+ var options = ReaderOptions .ForEncryptedArchive (" password" )
25+ .WithArchiveEncoding (new ArchiveEncoding { Default = Encoding .GetEncoding (932 ) });
26+ using (var archive = ZipArchive .OpenArchive (" encrypted.zip" , options ))
27+
28+ // Alternative: object initializer
29+ var options2 = new ReaderOptions
2530{
2631 Password = " password" ,
2732 LeaveStreamOpen = true ,
2833 ArchiveEncoding = new ArchiveEncoding { Default = Encoding .GetEncoding (932 ) }
2934};
30- using (var archive = ZipArchive .OpenArchive (" encrypted.zip" , options ))
3135```
3236
3337### Creating Archives
@@ -44,16 +48,21 @@ using (var archive = ZipArchive.CreateArchive())
4448using (var archive = TarArchive .CreateArchive ())
4549using (var archive = GZipArchive .CreateArchive ())
4650
47- // With options
48- var options = new WriterOptions (CompressionType .Deflate )
49- {
50- CompressionLevel = 9 ,
51- LeaveStreamOpen = false
52- };
51+ // With fluent options (preferred)
52+ var options = WriterOptions .ForZip ()
53+ .WithCompressionLevel (9 )
54+ .WithLeaveStreamOpen (false );
5355using (var archive = ZipArchive .CreateArchive ())
5456{
5557 archive .SaveTo (" output.zip" , options );
5658}
59+
60+ // Alternative: constructor with object initializer
61+ var options2 = new WriterOptions (CompressionType .Deflate )
62+ {
63+ CompressionLevel = 9 ,
64+ LeaveStreamOpen = false
65+ };
5766```
5867
5968---
@@ -72,16 +81,11 @@ using (var archive = ZipArchive.OpenArchive("file.zip"))
7281 var entry = archive .Entries .FirstOrDefault (e => e .Key == " file.txt" );
7382
7483 // Extract all
75- archive .WriteToDirectory (@" C:\output" , new ExtractionOptions
76- {
77- ExtractFullPath = true ,
78- Overwrite = true
79- });
84+ archive .WriteToDirectory (@" C:\output" );
8085
8186 // Extract single entry
8287 var entry = archive .Entries .First ();
8388 entry .WriteToFile (@" C:\output\file.txt" );
84- entry .WriteToFile (@" C:\output\file.txt" , new ExtractionOptions { Overwrite = true });
8589
8690 // Get entry stream
8791 using (var stream = entry .OpenEntryStream ())
@@ -95,7 +99,6 @@ using (var asyncArchive = await ZipArchive.OpenAsyncArchive("file.zip"))
9599{
96100 await asyncArchive .WriteToDirectoryAsync (
97101 @" C:\output" ,
98- new ExtractionOptions { ExtractFullPath = true , Overwrite = true },
99102 cancellationToken : cancellationToken
100103 );
101104}
@@ -187,7 +190,6 @@ using (var reader = await ReaderFactory.OpenAsyncReader(stream))
187190 // Async extraction of all entries
188191 await reader .WriteAllToDirectoryAsync (
189192 @" C:\output" ,
190- new ExtractionOptions { ExtractFullPath = true , Overwrite = true },
191193 cancellationToken
192194 );
193195}
@@ -229,43 +231,91 @@ using (var writer = WriterFactory.OpenWriter(stream, ArchiveType.Zip, Compressio
229231
230232### ReaderOptions
231233
234+ Use factory presets and fluent helpers for common configurations:
235+
232236``` csharp
233- var options = new ReaderOptions
234- {
235- Password = " password" , // For encrypted archives
236- LeaveStreamOpen = true , // Don't close wrapped stream
237- ArchiveEncoding = new ArchiveEncoding // Custom character encoding
238- {
239- Default = Encoding .GetEncoding (932 )
240- }
241- };
237+ // External stream with password and custom encoding
238+ var options = ReaderOptions .ForExternalStream ()
239+ .WithPassword (" password" )
240+ .WithArchiveEncoding (new ArchiveEncoding { Default = Encoding .GetEncoding (932 ) });
241+
242242using (var archive = ZipArchive .OpenArchive (" file.zip" , options ))
243243{
244244 // ...
245245 }
246+
247+ // Common presets
248+ var safeOptions = ReaderOptions .SafeExtract ; // No overwrite
249+ var flatOptions = ReaderOptions .FlatExtract ; // No directory structure
250+
251+ // Factory defaults:
252+ // - file path / FileInfo overloads use LeaveStreamOpen = false
253+ // - stream overloads use LeaveStreamOpen = true
254+ ```
255+
256+ Alternative: traditional object initializer:
257+
258+ ``` csharp
259+ var options = new ReaderOptions
260+ {
261+ Password = " password" ,
262+ LeaveStreamOpen = true ,
263+ ArchiveEncoding = new ArchiveEncoding { Default = Encoding .GetEncoding (932 ) }
264+ };
246265```
247266
248267### WriterOptions
249268
269+ Factory methods provide a clean, discoverable way to create writer options:
270+
271+ ``` csharp
272+ // Factory methods for common archive types
273+ var zipOptions = WriterOptions .ForZip () // ZIP with Deflate
274+ .WithCompressionLevel (9 ) // 0-9 for Deflate
275+ .WithLeaveStreamOpen (false ); // Close stream when done
276+
277+ var tarOptions = WriterOptions .ForTar (CompressionType .GZip ) // TAR with GZip
278+ .WithLeaveStreamOpen (false );
279+
280+ var gzipOptions = WriterOptions .ForGZip () // GZip file
281+ .WithCompressionLevel (6 );
282+
283+ archive .SaveTo (" output.zip" , zipOptions );
284+ ```
285+
286+ Alternative: traditional constructor with object initializer:
287+
250288``` csharp
251289var options = new WriterOptions (CompressionType .Deflate )
252290{
253- CompressionLevel = 9 , // 0-9 for Deflate
254- LeaveStreamOpen = true , // Don't close stream
291+ CompressionLevel = 9 ,
292+ LeaveStreamOpen = true ,
255293};
256294archive .SaveTo (" output.zip" , options );
257295```
258296
259- ### ExtractionOptions
297+ ### Extraction behavior
260298
261299``` csharp
262- var options = new ExtractionOptions
300+ var options = new ReaderOptions
263301{
264302 ExtractFullPath = true , // Recreate directory structure
265303 Overwrite = true , // Overwrite existing files
266304 PreserveFileTime = true // Keep original timestamps
267305 };
268- archive .WriteToDirectory (@" C:\output" , options );
306+
307+ using (var archive = ZipArchive .OpenArchive (" file.zip" , options ))
308+ {
309+ archive .WriteToDirectory (@" C:\output" );
310+ }
311+ ```
312+
313+ ### Options matrix
314+
315+ ``` text
316+ ReaderOptions: open-time behavior (password, encoding, stream ownership, extraction defaults)
317+ WriterOptions: write-time behavior (compression type/level, encoding, stream ownership)
318+ ZipWriterEntryOptions: per-entry ZIP overrides (compression, level, timestamps, comments, zip64)
269319```
270320
271321---
@@ -317,13 +367,9 @@ ArchiveType.ZStandard
317367try
318368{
319369 using (var archive = ZipArchive .Open (" archive.zip" ,
320- new ReaderOptions { Password = " password" } ))
370+ ReaderOptions . ForEncryptedArchive ( " password" ) ))
321371 {
322- archive .WriteToDirectory (@" C:\output" , new ExtractionOptions
323- {
324- ExtractFullPath = true ,
325- Overwrite = true
326- });
372+ archive .WriteToDirectory (@" C:\output" );
327373 }
328374}
329375catch (PasswordRequiredException )
@@ -348,7 +394,7 @@ var progress = new Progress<ProgressReport>(report =>
348394 Console .WriteLine ($" Extracting {report .EntryPath }: {report .PercentComplete }%" );
349395});
350396
351- var options = new ReaderOptions { Progress = progress } ;
397+ var options = ReaderOptions . ForOwnedFile (). WithProgress ( progress ) ;
352398using (var archive = ZipArchive .OpenArchive (" archive.zip" , options ))
353399{
354400 archive .WriteToDirectory (@" C:\output" );
367413 {
368414 await archive .WriteToDirectoryAsync (
369415 @" C:\output" ,
370- new ExtractionOptions { ExtractFullPath = true , Overwrite = true },
371416 cancellationToken : cts .Token
372417 );
373418 }
0 commit comments