Allow direct data source access

This commit is contained in:
Matt Nadareski
2025-08-23 21:31:13 -04:00
parent 02f9e1e935
commit e007a06dda
8 changed files with 15 additions and 20 deletions

View File

@@ -87,13 +87,13 @@ namespace SabreTools.Serialization.Wrappers
/// <inheritdoc/>
public bool Extract(string outputDirectory, bool includeDebug)
{
if (DataSource == null || !DataSource.CanRead)
if (_dataSource == null || !_dataSource.CanRead)
return false;
try
{
// Try opening the stream
using var bz2File = new BZip2InputStream(DataSource, true);
using var bz2File = new BZip2InputStream(_dataSource, true);
// Ensure directory separators are consistent
string filename = Guid.NewGuid().ToString();

View File

@@ -86,13 +86,13 @@ namespace SabreTools.Serialization.Wrappers
/// <inheritdoc/>
public bool Extract(string outputDirectory, bool includeDebug)
{
if (DataSource == null || !DataSource.CanRead)
if (_dataSource == null || !_dataSource.CanRead)
return false;
try
{
// Try opening the stream
using var gzipFile = new GZipStream(DataSource, CompressionMode.Decompress, true);
using var gzipFile = new GZipStream(_dataSource, CompressionMode.Decompress, true);
// Ensure directory separators are consistent
string filename = Guid.NewGuid().ToString();

View File

@@ -91,14 +91,14 @@ namespace SabreTools.Serialization.Wrappers
/// <inheritdoc cref="Extract(string, bool)"/>
public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebug)
{
if (DataSource == null || !DataSource.CanRead)
if (_dataSource == null || !_dataSource.CanRead)
return false;
#if NET462_OR_GREATER || NETCOREAPP
try
{
var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader };
var zipFile = ZipArchive.Open(DataSource, readerOptions);
var zipFile = ZipArchive.Open(_dataSource, readerOptions);
// Try to read the file path if no entries are found
if (zipFile.Entries.Count == 0 && !string.IsNullOrEmpty(Filename) && File.Exists(Filename!))

View File

@@ -94,14 +94,14 @@ namespace SabreTools.Serialization.Wrappers
/// <inheritdoc cref="Extract(string, bool)"/>
public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebug)
{
if (DataSource == null || !DataSource.CanRead)
if (_dataSource == null || !_dataSource.CanRead)
return false;
#if NET462_OR_GREATER || NETCOREAPP
try
{
var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader };
RarArchive rarFile = RarArchive.Open(DataSource, readerOptions);
RarArchive rarFile = RarArchive.Open(_dataSource, readerOptions);
// Try to read the file path if no entries are found
if (rarFile.Entries.Count == 0 && !string.IsNullOrEmpty(Filename) && File.Exists(Filename!))

View File

@@ -94,14 +94,14 @@ namespace SabreTools.Serialization.Wrappers
/// <inheritdoc cref="Extract(string, bool)"/>
public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebug)
{
if (DataSource == null || !DataSource.CanRead)
if (_dataSource == null || !_dataSource.CanRead)
return false;
#if NET462_OR_GREATER || NETCOREAPP
try
{
var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader };
var sevenZip = SevenZipArchive.Open(DataSource, readerOptions);
var sevenZip = SevenZipArchive.Open(_dataSource, readerOptions);
// Try to read the file path if no entries are found
if (sevenZip.Entries.Count == 0 && !string.IsNullOrEmpty(Filename) && File.Exists(Filename!))
sevenZip = SevenZipArchive.Open(Filename!, readerOptions);

View File

@@ -88,13 +88,13 @@ namespace SabreTools.Serialization.Wrappers
/// <inheritdoc/>
public bool Extract(string outputDirectory, bool includeDebug)
{
if (DataSource == null || !DataSource.CanRead)
if (_dataSource == null || !_dataSource.CanRead)
return false;
#if NET462_OR_GREATER || NETCOREAPP
try
{
var tarFile = TarArchive.Open(DataSource);
var tarFile = TarArchive.Open(_dataSource);
// Try to read the file path if no entries are found
if (tarFile.Entries.Count == 0 && !string.IsNullOrEmpty(Filename) && File.Exists(Filename!))

View File

@@ -24,11 +24,6 @@ namespace SabreTools.Serialization.Wrappers
#region Properties
/// <summary>
/// Data source as a stream
/// </summary>
public Stream? DataSource => _dataSource;
/// <inheritdoc cref="ViewStream.Filename"/>
public string? Filename => _dataSource.Filename;
@@ -42,7 +37,7 @@ namespace SabreTools.Serialization.Wrappers
/// <summary>
/// Source of the original data
/// </summary>
private readonly ViewStream _dataSource;
protected readonly ViewStream _dataSource;
#if NETCOREAPP
/// <summary>

View File

@@ -88,13 +88,13 @@ namespace SabreTools.Serialization.Wrappers
public bool Extract(string outDir, bool includeDebug)
{
#if NET462_OR_GREATER || NETCOREAPP
if (DataSource == null || !DataSource.CanRead)
if (_dataSource == null || !_dataSource.CanRead)
return false;
try
{
// Try opening the stream
using var xzFile = new XZStream(DataSource);
using var xzFile = new XZStream(_dataSource);
// Ensure directory separators are consistent
string filename = System.Guid.NewGuid().ToString();