mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-26 16:20:06 +00:00
Allow direct data source access
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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!))
|
||||
|
||||
@@ -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!))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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!))
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user