@@ -193,23 +193,7 @@ internal async Task UnknownDownloadInternal()
193193 // length is 0 bytes.
194194 if ( initialResult == default || initialLength == 0 )
195195 {
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 ) ;
213197 return ;
214198 }
215199
@@ -272,7 +256,11 @@ await DownloadStreamingInternal(range: httpRange).ConfigureAwait(false))
272256 internal async Task LengthKnownDownloadInternal ( )
273257 {
274258 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 )
276264 {
277265 // To prevent requesting a range that is invalid when
278266 // we already know the length we can just make one get blob request.
@@ -309,6 +297,7 @@ await CompleteFileDownload().ConfigureAwait(false))
309297
310298 // Get list of ranges of the blob
311299 IList < HttpRange > ranges = GetRangesList ( 0 , totalLength , rangeSize ) ;
300+
312301 // Create Download Chunk event handler to manage when the ranges finish downloading
313302 _downloadChunkHandler = GetDownloadChunkHandler (
314303 currentTranferred : 0 ,
@@ -503,5 +492,26 @@ internal async Task DisposeHandlers()
503492 await _downloadChunkHandler . DisposeAsync ( ) . ConfigureAwait ( false ) ;
504493 }
505494 }
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+ }
506516 }
507517}
0 commit comments