@@ -42,8 +42,9 @@ public abstract partial class ZipArchive : IDisposable, IEnumerable <ZipEntry>
4242 {
4343 internal class CallbackContext : IDisposable {
4444 bool disposed ;
45- public Stream Source = null ;
46- public Stream Destination = null ;
45+ public Stream Source { get ; set ; } = null ;
46+ public Stream Destination { get ; set ; } = null ;
47+ public string DestinationFileName { get ; set ; } = null ;
4748
4849 protected virtual void Dispose ( bool disposing )
4950 {
@@ -57,6 +58,10 @@ protected virtual void Dispose (bool disposing)
5758 Destination . Dispose ( ) ;
5859 Destination = null ;
5960 }
61+ if ( ! string . IsNullOrEmpty ( DestinationFileName ) && File . Exists ( DestinationFileName ) ) {
62+ File . Delete ( DestinationFileName ) ;
63+ DestinationFileName = null ;
64+ }
6065 }
6166 disposed = true ;
6267 }
@@ -855,7 +860,8 @@ internal static unsafe Int64 stream_callback (IntPtr state, IntPtr data, UInt64
855860 context . Destination = null ;
856861 break ;
857862 case SourceCommand . RollbackWrite :
858- // err do something?
863+ destination . Dispose ( ) ;
864+ context . Destination = null ;
859865 break ;
860866
861867 case SourceCommand . Read :
@@ -869,7 +875,14 @@ internal static unsafe Int64 stream_callback (IntPtr state, IntPtr data, UInt64
869875 ArrayPool < byte > . Shared . Return ( buffer ) ;
870876 }
871877 case SourceCommand . BeginWrite :
872- context . Destination = new MemoryStream ( ) ;
878+ try {
879+ string tempFile = Path . GetTempFileName ( ) ;
880+ context . Destination = File . Open ( tempFile , FileMode . OpenOrCreate , FileAccess . ReadWrite ) ;
881+ context . DestinationFileName = tempFile ;
882+ } catch ( IOException ) {
883+ // ok use a memory stream as a backup
884+ context . Destination = new MemoryStream ( ) ;
885+ }
873886 destination = context . Destination ;
874887 destination . Position = 0 ;
875888 break ;
@@ -886,12 +899,6 @@ internal static unsafe Int64 stream_callback (IntPtr state, IntPtr data, UInt64
886899 handle . Free ( ) ;
887900 break ;
888901
889- case SourceCommand . Error :
890- break ;
891-
892- case SourceCommand . Remove :
893- break ;
894-
895902 case SourceCommand . Supports :
896903 var supports = ( Int64 ) Native . zip_source_make_command_bitmap (
897904 SourceCommand . Open ,
0 commit comments