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 GetContentAsync() { return new ValueTask(new MemoryStream(Content, false)); } public ValueTask CalculateChecksumAsync() { return new ValueTask(Checksum); } public ValueTask WriteAsync(Stream target, uint bufferSize) { return target.WriteAsync(Content.AsMemory()); } } }