Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Added the ability to upload files larger than 4MB #2180

Merged
merged 6 commits into from
Mar 23, 2018

Conversation

KrzysztofCwalina
Copy link
Member

}
index += length;
bytesLeft -= length;
if (bytesLeft == 0) break;
Copy link
Member

@ahsonkhan ahsonkhan Mar 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why not use this as the while loop condition, especially since we do this check at the end of the loop anyway?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

{
FilePath = filePath;
FileContent = fileContent;
if (offset < 0) throw new ArgumentOutOfRangeException(nameof(offset));
Copy link
Member

@ahsonkhan ahsonkhan Mar 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add checks for offset greater than _length?

Copy link
Member Author

@KrzysztofCwalina KrzysztofCwalina Mar 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offset can be greater, equal, or less than length. It cannot be greater than fileContent.Length - _length. I will add the check.

writer.WriteHeader("x-ms-date", Time, 'R');
// TODO (pri 3): this allocation should be eliminated
writer.WriteHeader("x-ms-range", $"bytes=0-{size - 1}");

var start = arguments._offset;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use of var

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix

Copy link
Member

@ahsonkhan ahsonkhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, looks good! Can't wait to try it :)

{
Memory<byte> buffer = writer.GetMemory();
if(buffer.Length > bytesToWrite)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: formatting, add space

@@ -131,14 +138,21 @@ class Writer : StorageRequestWriter<PutRangeRequest>
public override Http.Method Verb => Http.Method.Put;

protected override async Task WriteBody(PipeWriter writer, PutRangeRequest arguments)
=> await writer.WriteAsync(arguments.FileContent);
{
var stream = arguments._fileContent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use of var

{
FilePath = filePath;
FileContent = fileContent;
if (offset < 0 || offset > fileContent.Length - length) throw new ArgumentOutOfRangeException(nameof(offset));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. What about the case when length > fileContent.Length?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AORE will be thrown. fileContent.Length - length will be negative and will be < offset (which has to be positive at the time of this check)

@@ -212,7 +212,7 @@ static void TransferStorageFileToDirectory(ReadOnlySpan<char> storageFile, ReadO
}
index += length;
bytesLeft -= length;
if (bytesLeft == 0) break;
Debug.Assert(bytesLeft >= 0);
Copy link
Member

@ahsonkhan ahsonkhan Mar 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this Debug.Assert is necessary, given the loop condition is already stronger. Maybe a better option would be to add a Debug.Assert after the loop exits, if we know that bytesLeft should never be negative and if that signals a coding bug:
Debug.Assert(bytesLeft == 0);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assert ensures bytesLeft is no negative

@KrzysztofCwalina KrzysztofCwalina merged commit 600dbcb into dotnet:master Mar 23, 2018
@KrzysztofCwalina KrzysztofCwalina deleted the AzCopy branch March 30, 2018 01:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants