123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System;
- using System.IO;
- using System.Threading.Tasks;
- using GenHTTP.Api.Content.IO;
- using GenHTTP.Api.Protocol;
- namespace PRSServer
- {
- public class ByteArrayResource : IResource
- {
- public ByteArrayResource(byte[] content, string? name, FlexibleContentType? contentType, DateTime? modified)
- {
- Content = content;
- Checksum = (ulong)content.GetHashCode();
- Name = name;
- ContentType = contentType ?? FlexibleContentType.Get(GenHTTP.Api.Protocol.ContentType.TextPlain);
- Modified = modified;
- }
- public byte[] Content { get; }
- private ulong Checksum { get; }
- public string? Name { get; }
- public DateTime? Modified { get; }
- public FlexibleContentType? ContentType { get; }
- public ulong? Length => (ulong)Content.Length;
- public ValueTask<Stream> GetContentAsync()
- {
- return new ValueTask<Stream>(new MemoryStream(Content, false));
- }
- public ValueTask<ulong> CalculateChecksumAsync()
- {
- return new ValueTask<ulong>(Checksum);
- }
- public ValueTask WriteAsync(Stream target, uint bufferSize)
- {
- return target.WriteAsync(Content.AsMemory());
- }
- }
- }
|