Skip to content

Commit 2561427

Browse files
author
Igor Evdokimov
committed
- cosmetic
1 parent a8a9c8c commit 2561427

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

Botticelli.Server.FrontNew/Utils/ProgressStreamContent.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,24 @@
22

33
namespace Botticelli.Server.FrontNew.Utils;
44

5-
public class ProgressStreamContent : StreamContent
5+
public class ProgressStreamContent(Stream content, Action<long, long> progress) : StreamContent(content)
66
{
7-
private readonly Action<long, long> _progress;
8-
9-
public ProgressStreamContent(Stream content, Action<long, long> progress) : base(content)
10-
{
11-
_progress = progress;
12-
}
13-
14-
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
7+
private const int BufferSize = 8192;
8+
9+
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext? context)
1510
{
1611
var totalBytes = Headers.ContentLength ?? -1;
17-
var buffer = new byte[8192];
12+
var buffer = new byte[BufferSize];
1813
long totalRead = 0;
1914
int bytesRead;
2015

2116
var contentStream = await ReadAsStreamAsync();
2217
contentStream.Seek(0, SeekOrigin.Begin);
23-
while ((bytesRead = await contentStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
18+
while ((bytesRead = await contentStream.ReadAsync(buffer)) > 0)
2419
{
25-
await stream.WriteAsync(buffer, 0, bytesRead);
20+
await stream.WriteAsync(buffer.AsMemory(0, bytesRead));
2621
totalRead += bytesRead;
27-
_progress?.Invoke(totalRead, totalBytes);
22+
progress?.Invoke(totalRead, totalBytes);
2823
}
2924
}
3025
}

0 commit comments

Comments
 (0)