@@ -28,8 +28,7 @@ public GetObjectArgs()
2828 OffsetLengthSet = false ;
2929 }
3030
31- internal Action < Stream > CallBack { get ; private set ; }
32- internal Func < Stream , CancellationToken , Task > FuncCallBack { get ; private set ; }
31+ internal Func < Stream , CancellationToken , Task > CallBack { get ; private set ; }
3332 internal long ObjectOffset { get ; private set ; }
3433 internal long ObjectLength { get ; private set ; }
3534 internal string FileName { get ; private set ; }
@@ -38,7 +37,7 @@ public GetObjectArgs()
3837 internal override void Validate ( )
3938 {
4039 base . Validate ( ) ;
41- if ( CallBack is null && FuncCallBack is null && string . IsNullOrEmpty ( FileName ) )
40+ if ( CallBack is null && string . IsNullOrEmpty ( FileName ) )
4241 throw new MinioException ( "Atleast one of " + nameof ( CallBack ) + ", CallBack method or " + nameof ( FileName ) +
4342 " file path to save need to be set for GetObject operation." ) ;
4443
@@ -76,8 +75,7 @@ internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuild
7675 {
7776 if ( ! string . IsNullOrEmpty ( VersionId ) ) requestMessageBuilder . AddQueryParameter ( "versionId" , $ "{ VersionId } ") ;
7877
79- if ( CallBack is not null ) requestMessageBuilder . ResponseWriter = CallBack ;
80- else requestMessageBuilder . FunctionResponseWriter = FuncCallBack ;
78+ requestMessageBuilder . ResponseWriter = CallBack ;
8179
8280 if ( Headers . TryGetValue ( S3ZipExtractKey , out var value ) )
8381 requestMessageBuilder . AddQueryParameter ( S3ZipExtractKey , value ) ;
@@ -87,13 +85,31 @@ internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuild
8785
8886 public GetObjectArgs WithCallbackStream ( Action < Stream > cb )
8987 {
90- CallBack = cb ;
88+ CallBack = ( stream , cancellationToken ) =>
89+ {
90+ var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
91+
92+ if ( cancellationToken . IsCancellationRequested )
93+ taskCompletionSource . SetCanceled ( ) ;
94+ else
95+ try
96+ {
97+ cb ( stream ) ;
98+ taskCompletionSource . SetResult ( true ) ;
99+ }
100+ catch ( Exception ex )
101+ {
102+ taskCompletionSource . SetException ( ex ) ;
103+ }
104+
105+ return taskCompletionSource . Task ;
106+ } ;
91107 return this ;
92108 }
93109
94110 public GetObjectArgs WithCallbackStream ( Func < Stream , CancellationToken , Task > cb )
95111 {
96- FuncCallBack = cb ;
112+ CallBack = cb ;
97113 return this ;
98114 }
99115
0 commit comments