Files
SabreTools.Serialization/Files/Hashfile.Serializer.cs

25 lines
776 B
C#
Raw Permalink Normal View History

using SabreTools.Serialization.Interfaces;
2023-09-09 00:02:56 -04:00
namespace SabreTools.Serialization.Files
{
public partial class Hashfile : IFileSerializer<Models.Hashfile.Hashfile>
{
/// <inheritdoc/>
2023-09-11 01:23:29 -04:00
public bool Serialize(Models.Hashfile.Hashfile? obj, string? path) => Serialize(obj, path, Hash.CRC);
/// <inheritdoc/>
public bool Serialize(Models.Hashfile.Hashfile? obj, string? path, Hash hash)
2023-09-09 00:02:56 -04:00
{
2023-11-21 20:59:20 -05:00
if (string.IsNullOrEmpty(path))
2023-09-10 17:32:03 -04:00
return false;
2023-11-21 21:10:43 -05:00
using var stream = new Streams.Hashfile().Serialize(obj, hash);
if (stream == null)
return false;
2023-09-09 00:02:56 -04:00
2023-11-21 21:10:43 -05:00
using var fs = System.IO.File.OpenWrite(path);
stream.CopyTo(fs);
return true;
2023-09-09 00:02:56 -04:00
}
}
}