wabbajack/Wabbajack.Common/NativeFileStreamFactory.cs

44 lines
1020 B
C#
Raw Normal View History

2021-09-27 12:42:46 +00:00
using System;
using System.IO;
using System.Threading.Tasks;
2021-09-27 12:42:46 +00:00
using Wabbajack.DTOs.Streams;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
namespace Wabbajack.Common
{
public class NativeFileStreamFactory : IStreamFactory
{
protected AbsolutePath _file;
2021-09-27 12:42:46 +00:00
private DateTime? _lastModifiedCache;
2020-09-08 22:15:33 +00:00
public NativeFileStreamFactory(AbsolutePath file, IPath path)
{
_file = file;
Name = path;
}
2021-09-27 12:42:46 +00:00
public NativeFileStreamFactory(AbsolutePath file)
{
_file = file;
2020-09-08 22:15:33 +00:00
Name = file;
}
2021-09-27 12:42:46 +00:00
public ValueTask<Stream> GetStream()
{
2021-09-27 12:42:46 +00:00
return new ValueTask<Stream>(_file.Open(FileMode.Open, FileAccess.Read, FileShare.Read));
}
public DateTime LastModifiedUtc
{
get
{
2021-09-27 12:42:46 +00:00
_lastModifiedCache ??= _file.LastModifiedUtc();
return _lastModifiedCache.Value;
}
}
2020-09-08 22:15:33 +00:00
public IPath Name { get; }
}
2021-09-27 12:42:46 +00:00
}