-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathSendFilesWrapper.cs
More file actions
64 lines (53 loc) · 1.76 KB
/
SendFilesWrapper.cs
File metadata and controls
64 lines (53 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System.IO;
using System.IO.Pipelines;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
namespace Microsoft.VisualStudio.Web.BrowserLink
{
internal class SendFilesWrapper : IHttpResponseBodyFeature
{
private readonly HttpResponse _response;
private readonly IHttpResponseBodyFeature _wrapped;
internal SendFilesWrapper(IHttpResponseBodyFeature wrapped, HttpResponse response)
{
_wrapped = wrapped;
_response = response;
}
public Stream Stream => _wrapped?.Stream;
public PipeWriter Writer => _wrapped?.Writer;
public async Task CompleteAsync()
{
if (_wrapped != null)
{
await _wrapped.CompleteAsync();
}
}
public void DisableBuffering()
{
_wrapped?.DisableBuffering();
}
public async Task SendFileAsync(string path, long offset, long? count, CancellationToken cancellationToken = default)
{
// TODO: Send mapping data to VS
if (_wrapped != null)
{
await _wrapped.SendFileAsync(path, offset, count, cancellationToken);
return;
}
using (Stream readStream = File.OpenRead(path))
{
readStream.Seek(offset, SeekOrigin.Begin);
await readStream.CopyToAsync(_response.Body, 4096, cancellationToken);
}
}
public async Task StartAsync(CancellationToken cancellationToken = default)
{
if (_wrapped != null)
{
await _wrapped.StartAsync(cancellationToken);
}
}
}
}