tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
LimitedStreamResult.cs
Go to the documentation of this file.
1using System;
2using System.IO;
3using System.Net.Mime;
4using System.Threading;
5using System.Threading.Tasks;
6
7using Microsoft.AspNetCore.Mvc;
8using Microsoft.AspNetCore.Mvc.Infrastructure;
9using Microsoft.Extensions.DependencyInjection;
10
12
14{
19 {
23 readonly Stream stream;
24
30 : base(MediaTypeNames.Application.Octet)
31 {
32 this.stream = stream ?? throw new ArgumentNullException(nameof(stream));
33 }
34
36 public ValueTask DisposeAsync() => stream.DisposeAsync();
37
39 public override Task ExecuteResultAsync(ActionContext context)
40 {
41 ArgumentNullException.ThrowIfNull(context);
42
43 var executor = context
44 .HttpContext
45 .RequestServices
46 .GetRequiredService<IActionResultExecutor<LimitedStreamResult>>();
47 return executor.ExecuteAsync(context, this);
48 }
49
51 public ValueTask<Stream> GetResult(CancellationToken cancellationToken) => ValueTask.FromResult(stream);
52 }
53}
Very similar to FileStreamResult except it's IActionResultExecutor<TResult> contains a fix for https:...
LimitedStreamResult(Stream stream)
Initializes a new instance of the LimitedStreamResult class.
ValueTask< Stream > GetResult(CancellationToken cancellationToken)
Gets the provided Stream. May be called multiple times, though cancelling any may cause all calls to ...
Interface for asynchronously consuming Streams of files.