@@ -17,7 +17,14 @@ public static class IArchiveEntryExtensions
1717 /// </summary>
1818 /// <param name="streamToWriteTo">The stream to write the entry content to.</param>
1919 /// <param name="progress">Optional progress reporter for tracking extraction progress.</param>
20- public void WriteTo ( Stream streamToWriteTo , IProgress < ProgressReport > ? progress = null )
20+ public void WriteTo ( Stream streamToWriteTo , IProgress < ProgressReport > ? progress = null ) =>
21+ archiveEntry . WriteTo ( streamToWriteTo , null , progress ) ;
22+
23+ private void WriteTo (
24+ Stream streamToWriteTo ,
25+ int ? bufferSize ,
26+ IProgress < ProgressReport > ? progress = null
27+ )
2128 {
2229 if ( archiveEntry . IsDirectory )
2330 {
@@ -26,7 +33,7 @@ public void WriteTo(Stream streamToWriteTo, IProgress<ProgressReport>? progress
2633
2734 using var entryStream = archiveEntry . OpenEntryStream ( ) ;
2835 var sourceStream = WrapWithProgress ( entryStream , archiveEntry , progress ) ;
29- sourceStream . CopyTo ( streamToWriteTo , Constants . BufferSize ) ;
36+ sourceStream . CopyTo ( streamToWriteTo , bufferSize ?? Constants . BufferSize ) ;
3037 }
3138
3239 /// <summary>
@@ -40,6 +47,18 @@ public async ValueTask WriteToAsync(
4047 IProgress < ProgressReport > ? progress = null ,
4148 CancellationToken cancellationToken = default
4249 )
50+ {
51+ await archiveEntry
52+ . WriteToAsync ( streamToWriteTo , Constants . BufferSize , progress , cancellationToken )
53+ . ConfigureAwait ( false ) ;
54+ }
55+
56+ private async ValueTask WriteToAsync (
57+ Stream streamToWriteTo ,
58+ int ? bufferSize ,
59+ IProgress < ProgressReport > ? progress = null ,
60+ CancellationToken cancellationToken = default
61+ )
4362 {
4463 if ( archiveEntry . IsDirectory )
4564 {
@@ -57,7 +76,7 @@ public async ValueTask WriteToAsync(
5776#endif
5877 var sourceStream = WrapWithProgress ( entryStream , archiveEntry , progress ) ;
5978 await sourceStream
60- . CopyToAsync ( streamToWriteTo , Constants . BufferSize , cancellationToken )
79+ . CopyToAsync ( streamToWriteTo , bufferSize ?? Constants . BufferSize , cancellationToken )
6180 . ConfigureAwait ( false ) ;
6281 }
6382 }
@@ -133,16 +152,18 @@ await entry.WriteToFileAsync(path, options, ct).ConfigureAwait(false),
133152 /// <summary>
134153 /// Extract to specific file
135154 /// </summary>
136- public void WriteToFile ( string destinationFileName , ExtractionOptions ? options = null ) =>
155+ public void WriteToFile ( string destinationFileName , ExtractionOptions ? options = null )
156+ {
137157 entry . WriteEntryToFile (
138158 destinationFileName ,
139159 options ,
140160 ( x , fm ) =>
141161 {
142- using var fs = File . Open ( destinationFileName , fm ) ;
143- entry . WriteTo ( fs ) ;
162+ using var fs = File . Open ( x , fm ) ;
163+ entry . WriteTo ( fs , options ? . BufferSize ?? Constants . BufferSize ) ;
144164 }
145165 ) ;
166+ }
146167
147168 /// <summary>
148169 /// Extract to specific file asynchronously
@@ -158,8 +179,10 @@ await entry
158179 options ,
159180 async ( x , fm , ct ) =>
160181 {
161- using var fs = File . Open ( destinationFileName , fm ) ;
162- await entry . WriteToAsync ( fs , null , ct ) . ConfigureAwait ( false ) ;
182+ using var fs = File . Open ( x , fm ) ;
183+ await entry
184+ . WriteToAsync ( fs , options ? . BufferSize , null , ct )
185+ . ConfigureAwait ( false ) ;
163186 } ,
164187 cancellationToken
165188 )
0 commit comments