Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 59efb56

Browse files
committed
Merge pull request #2532 from justinvp/http_bytearraycontent
Cleanup ByteArrayContent
2 parents 52c7af6 + 4874e78 commit 59efb56

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/System.Net.Http/src/System/Net/Http/ByteArrayContent.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System.Diagnostics;
5-
using System.Diagnostics.Contracts;
65
using System.IO;
76
using System.Threading.Tasks;
87

98
namespace System.Net.Http
109
{
1110
public class ByteArrayContent : HttpContent
1211
{
13-
private byte[] _content;
14-
private int _offset;
15-
private int _count;
12+
private readonly byte[] _content;
13+
private readonly int _offset;
14+
private readonly int _count;
1615

1716
public ByteArrayContent(byte[] content)
1817
{
@@ -60,9 +59,7 @@ protected internal override bool TryComputeLength(out long length)
6059

6160
protected override Task<Stream> CreateContentReadStreamAsync()
6261
{
63-
TaskCompletionSource<Stream> tcs = new TaskCompletionSource<Stream>();
64-
tcs.TrySetResult(new MemoryStream(_content, _offset, _count, false));
65-
return tcs.Task;
62+
return Task.FromResult<Stream>(new MemoryStream(_content, _offset, _count, writable: false));
6663
}
6764
}
6865
}

0 commit comments

Comments
 (0)