Add shell deserializers for gzip and tar

This commit is contained in:
Matt Nadareski
2025-08-28 07:52:43 -04:00
parent 4b8dc12c98
commit 5dda3e2c81
4 changed files with 73 additions and 23 deletions

View File

@@ -0,0 +1,17 @@
using System.IO;
using SabreTools.Models.GZIP;
namespace SabreTools.Serialization.Deserializers
{
public class GZip : BaseBinaryDeserializer<Archive>
{
/// <inheritdoc/>
protected override bool SkipCompression => true;
/// <inheritdoc/>
public override Archive? Deserialize(Stream? data)
{
throw new System.NotImplementedException();
}
}
}

View File

@@ -0,0 +1,19 @@
using System.IO;
using SabreTools.Models.TAR;
namespace SabreTools.Serialization.Deserializers
{
public class TapeArchive : BaseBinaryDeserializer<Archive>
{
/// <inheritdoc/>
protected override bool SkipCompression => true;
/// <inheritdoc/>
public override Archive? Deserialize(Stream? data)
{
throw new System.NotImplementedException();
}
}
}

View File

@@ -1,16 +1,12 @@
using System;
using System.IO;
using SabreTools.IO.Compression.Deflate;
using SabreTools.Models.GZIP;
using SabreTools.Serialization.Interfaces;
namespace SabreTools.Serialization.Wrappers
{
/// <summary>
/// This is a shell wrapper; one that does not contain
/// any actual parsing. It is used as a placeholder for
/// types that typically do not have models.
/// </summary>
public class GZip : WrapperBase, IExtractable
public class GZip : WrapperBase<Archive>, IExtractable
{
#region Descriptive Properties
@@ -22,15 +18,15 @@ namespace SabreTools.Serialization.Wrappers
#region Constructors
/// <inheritdoc/>
public GZip(byte[]? data, int offset)
: base(data, offset)
public GZip(Archive? model, byte[]? data, int offset)
: base(model, data, offset)
{
// All logic is handled by the base class
}
/// <inheritdoc/>
public GZip(Stream? data)
: base(data)
public GZip(Archive? model, Stream? data)
: base(model, data)
{
// All logic is handled by the base class
}
@@ -67,7 +63,18 @@ namespace SabreTools.Serialization.Wrappers
if (data == null || !data.CanRead)
return null;
return new GZip(data);
try
{
var model = Deserializers.GZip.DeserializeStream(data);
if (model == null)
return null;
return new GZip(model, data);
}
catch
{
return null;
}
}
#endregion

View File

@@ -1,4 +1,5 @@
using System.IO;
using SabreTools.Models.TAR;
using SabreTools.Serialization.Interfaces;
#if NET462_OR_GREATER || NETCOREAPP
using SharpCompress.Archives;
@@ -7,12 +8,7 @@ using SharpCompress.Archives.Tar;
namespace SabreTools.Serialization.Wrappers
{
/// <summary>
/// This is a shell wrapper; one that does not contain
/// any actual parsing. It is used as a placeholder for
/// types that typically do not have models.
/// </summary>
public class TapeArchive : WrapperBase, IExtractable
public class TapeArchive : WrapperBase<Archive>, IExtractable
{
#region Descriptive Properties
@@ -23,16 +19,16 @@ namespace SabreTools.Serialization.Wrappers
#region Constructors
//// <inheritdoc/>
public TapeArchive(byte[]? data, int offset)
: base(data, offset)
/// <inheritdoc/>
public TapeArchive(Archive? model, byte[]? data, int offset)
: base(model, data, offset)
{
// All logic is handled by the base class
}
/// <inheritdoc/>
public TapeArchive(Stream? data)
: base(data)
public TapeArchive(Archive? model, Stream? data)
: base(model, data)
{
// All logic is handled by the base class
}
@@ -69,7 +65,18 @@ namespace SabreTools.Serialization.Wrappers
if (data == null || !data.CanRead)
return null;
return new TapeArchive(data);
try
{
var model = Deserializers.TapeArchive.DeserializeStream(data);
if (model == null)
return null;
return new TapeArchive(model, data);
}
catch
{
return null;
}
}
#endregion