-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathIResource.cs
More file actions
72 lines (60 loc) · 2.23 KB
/
IResource.cs
File metadata and controls
72 lines (60 loc) · 2.23 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
65
66
67
68
69
70
71
72
using System.Buffers;
using GenHTTP.Api.Protocol;
namespace GenHTTP.Api.Content.IO;
/// <summary>
/// Allows content providers to access a resource without the need
/// to know the actual way of access (such as database, web, or
/// file system).
/// </summary>
/// <remarks>
/// As resources may change (e.g. if a user changes the file that
/// is provided as a resource), content providers must not
/// cache the results of a method call.
/// </remarks>
public interface IResource
{
/// <summary>
/// The name of this resource, if known.
/// </summary>
string? Name { get; }
/// <summary>
/// The point in time, when the resource was last modified, if known.
/// </summary>
DateTime? Modified { get; }
/// <summary>
/// The content type of this resource, if known.
/// </summary>
FlexibleContentType? ContentType { get; }
/// <summary>
/// The number of bytes provided by this resource.
/// </summary>
/// <remarks>
/// This field will not be used to control the HTTP flow, but
/// just as meta information (e.g. to be rendered by the
/// directory listing handler). For optimized data transfer,
/// the stream provided by this resource should be seekable
/// and return a sane length.
/// </remarks>
ulong? Length { get; }
/// <summary>
/// Calculates the checksum of the resource.
/// </summary>
/// <returns>The checksum of the resource</returns>
ValueTask<ulong> CalculateChecksumAsync();
/// <summary>
/// Returns the read-only stream of the resource to be accessed.
/// </summary>
/// <returns>The resource to be accessed</returns>
ValueTask<Stream> GetContentAsync();
/// <summary>
/// Writes the content of the resource to the given stream.
/// </summary>
/// <param name="target">The stream to write to</param>
/// <param name="bufferSize">The buffer size to be used for the operation</param>
async ValueTask WriteAsync(Stream target, uint bufferSize)
{
await using var content = await GetContentAsync();
await content.CopyToAsync(target, (int)bufferSize);
}
void Write(IBufferWriter<byte> writer);
}