Skip to content

Commit f599ba1

Browse files
authored
Merge pull request #4204 from begoldsm/preview
ADLS: Bug Fix to support create and append for any size
2 parents 2eea764 + d435892 commit f599ba1

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

src/ResourceManager/DataLakeStore/Commands.DataLakeStore/Models/DataLakeStoreFileSystemClient.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace Microsoft.Azure.Commands.DataLakeStore.Models
3535
public class DataLakeStoreFileSystemClient
3636
{
3737
private const decimal MaximumBytesPerDownloadRequest = 32 * 1024 * 1024; //32MB
38+
private const decimal MaximumBytesPerAppendRequest = 20 * 1024 * 1024; //20MB
3839

3940
/// <summary>
4041
/// The lock object
@@ -421,9 +422,27 @@ public void ConcatenateFiles(string destinationPath, string accountName, string[
421422
deleteDirectory);
422423
}
423424

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)
425426
{
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+
427446
}
428447

429448
public bool CreateDirectory(string dirPath, string accountName)
@@ -432,9 +451,24 @@ public bool CreateDirectory(string dirPath, string accountName)
432451
return boolean != null && boolean.Value;
433452
}
434453

435-
public void AppendToFile(string filePath, string accountName, Stream contents)
454+
public void AppendToFile(string filePath, string accountName, MemoryStream contents)
436455
{
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+
}
438472
}
439473

440474
public void CopyFile(string destinationPath, string accountName, string sourcePath,

0 commit comments

Comments
 (0)