@@ -35,6 +35,7 @@ namespace Microsoft.Azure.Commands.DataLakeStore.Models
35
35
public class DataLakeStoreFileSystemClient
36
36
{
37
37
private const decimal MaximumBytesPerDownloadRequest = 32 * 1024 * 1024 ; //32MB
38
+ private const decimal MaximumBytesPerAppendRequest = 20 * 1024 * 1024 ; //20MB
38
39
39
40
/// <summary>
40
41
/// The lock object
@@ -421,9 +422,27 @@ public void ConcatenateFiles(string destinationPath, string accountName, string[
421
422
deleteDirectory ) ;
422
423
}
423
424
424
- public void CreateFile ( string filePath , string accountName , Stream contents = null , bool overwrite = false )
425
+ public void CreateFile ( string filePath , string accountName , MemoryStream contents = null , bool overwrite = false )
425
426
{
426
- _client . FileSystem . Create ( accountName , filePath , contents , overwrite : overwrite ) ;
427
+ if ( contents . Length <= MaximumBytesPerAppendRequest )
428
+ {
429
+ // use content-length header for request
430
+ _client . FileSystem . Create ( accountName , filePath , contents , overwrite : overwrite ) ;
431
+ }
432
+ else
433
+ {
434
+ // use transfer-encoding: chunked header for request
435
+ var customHeaders = new Dictionary < string , List < string > > ( ) ;
436
+ customHeaders . Add ( "Transfer-Encoding" , new List < string > { "Chunked" } ) ;
437
+ _client . FileSystem . CreateWithHttpMessagesAsync (
438
+ accountName ,
439
+ filePath ,
440
+ contents ,
441
+ overwrite : overwrite ,
442
+ customHeaders : customHeaders ) . GetAwaiter ( ) . GetResult ( ) ;
443
+ }
444
+
445
+
427
446
}
428
447
429
448
public bool CreateDirectory ( string dirPath , string accountName )
@@ -432,9 +451,24 @@ public bool CreateDirectory(string dirPath, string accountName)
432
451
return boolean != null && boolean . Value ;
433
452
}
434
453
435
- public void AppendToFile ( string filePath , string accountName , Stream contents )
454
+ public void AppendToFile ( string filePath , string accountName , MemoryStream contents )
436
455
{
437
- _client . FileSystem . Append ( accountName , filePath , contents ) ;
456
+ if ( contents . Length <= MaximumBytesPerAppendRequest )
457
+ {
458
+ // use content-length header for request
459
+ _client . FileSystem . Append ( accountName , filePath , contents ) ;
460
+ }
461
+ else
462
+ {
463
+ // use transfer-encoding: chunked header for request
464
+ var customHeaders = new Dictionary < string , List < string > > ( ) ;
465
+ customHeaders . Add ( "Transfer-Encoding" , new List < string > { "Chunked" } ) ;
466
+ _client . FileSystem . AppendWithHttpMessagesAsync (
467
+ accountName ,
468
+ filePath ,
469
+ contents ,
470
+ customHeaders : customHeaders ) . GetAwaiter ( ) . GetResult ( ) ;
471
+ }
438
472
}
439
473
440
474
public void CopyFile ( string destinationPath , string accountName , string sourcePath ,
0 commit comments