39 lines
977 B
C#
39 lines
977 B
C#
using System.IO;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace FileExposer.Models;
|
|
|
|
public record RelativePath(string Path,
|
|
Record[] Records)
|
|
{
|
|
|
|
internal static RelativePath? Get(Stream stream)
|
|
{
|
|
RelativePath? result;
|
|
string? json = GetJson(stream);
|
|
result = string.IsNullOrEmpty(json) ? null : JsonSerializer.Deserialize<RelativePath>(json);
|
|
return result;
|
|
}
|
|
|
|
private static string? GetJson(Stream stream)
|
|
{
|
|
string? result;
|
|
if (!stream.CanRead)
|
|
result = null;
|
|
else
|
|
{
|
|
Task<string> task = new StreamReader(stream).ReadToEndAsync();
|
|
result = task.Result;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
}
|
|
|
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
|
[JsonSerializable(typeof(RelativePath))]
|
|
public partial class RelativePathSourceGenerationContext : JsonSerializerContext
|
|
{
|
|
} |