@@ -193,23 +193,7 @@ internal async Task UnknownDownloadInternal()
193
193
// length is 0 bytes.
194
194
if ( initialResult == default || initialLength == 0 )
195
195
{
196
- // We just need to at minimum create the file
197
- bool succesfulCreation = await CopyToStreamInternal (
198
- offset : 0 ,
199
- sourceLength : 0 ,
200
- source : default ,
201
- expectedLength : 0 ) . ConfigureAwait ( false ) ;
202
- if ( succesfulCreation )
203
- {
204
- // Queue the work to end the download
205
- await QueueChunkToChannelAsync (
206
- async ( ) =>
207
- await CompleteFileDownload ( ) . ConfigureAwait ( false ) ) . ConfigureAwait ( false ) ;
208
- }
209
- else
210
- {
211
- await CheckAndUpdateCancellationStatusAsync ( ) . ConfigureAwait ( false ) ;
212
- }
196
+ await CreateZeroLengthDownload ( ) . ConfigureAwait ( false ) ;
213
197
return ;
214
198
}
215
199
@@ -272,7 +256,11 @@ await DownloadStreamingInternal(range: httpRange).ConfigureAwait(false))
272
256
internal async Task LengthKnownDownloadInternal ( )
273
257
{
274
258
long totalLength = _sourceResource . Length . Value ;
275
- if ( _initialTransferSize <= totalLength )
259
+ if ( totalLength == 0 )
260
+ {
261
+ await CreateZeroLengthDownload ( ) . ConfigureAwait ( false ) ;
262
+ }
263
+ else if ( _initialTransferSize <= totalLength )
276
264
{
277
265
// To prevent requesting a range that is invalid when
278
266
// we already know the length we can just make one get blob request.
@@ -309,6 +297,7 @@ await CompleteFileDownload().ConfigureAwait(false))
309
297
310
298
// Get list of ranges of the blob
311
299
IList < HttpRange > ranges = GetRangesList ( 0 , totalLength , rangeSize ) ;
300
+
312
301
// Create Download Chunk event handler to manage when the ranges finish downloading
313
302
_downloadChunkHandler = GetDownloadChunkHandler (
314
303
currentTranferred : 0 ,
@@ -503,5 +492,26 @@ internal async Task DisposeHandlers()
503
492
await _downloadChunkHandler . DisposeAsync ( ) . ConfigureAwait ( false ) ;
504
493
}
505
494
}
495
+
496
+ private async Task CreateZeroLengthDownload ( )
497
+ {
498
+ // We just need to at minimum create the file
499
+ bool succesfulCreation = await CopyToStreamInternal (
500
+ offset : 0 ,
501
+ sourceLength : 0 ,
502
+ source : default ,
503
+ expectedLength : 0 ) . ConfigureAwait ( false ) ;
504
+ if ( succesfulCreation )
505
+ {
506
+ // Queue the work to end the download
507
+ await QueueChunkToChannelAsync (
508
+ async ( ) =>
509
+ await CompleteFileDownload ( ) . ConfigureAwait ( false ) ) . ConfigureAwait ( false ) ;
510
+ }
511
+ else
512
+ {
513
+ await CheckAndUpdateCancellationStatusAsync ( ) . ConfigureAwait ( false ) ;
514
+ }
515
+ }
506
516
}
507
517
}
0 commit comments