C#: Extended the generic Supports(Stream) method with the length of the input stream, since Overlay-LZ compresses from end to start.

This commit is contained in:
barubary 2011-04-05 16:50:17 +00:00
parent 3a6221a0c6
commit fa10d8a515
7 changed files with 18 additions and 8 deletions

View File

@ -53,7 +53,7 @@
<Compile Include="Formats\Nitro\NitroCFormat.cs" />
<Compile Include="Exceptions\NotEnoughDataException.cs" />
<Compile Include="Formats\Nitro\RLE.cs" />
<Compile Include="NewProgram.cs" />
<Compile Include="TestProgram.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

View File

@ -24,7 +24,7 @@ namespace DSDecmp.Formats
// open the file, and delegate to the decompressor-specific code.
using (FileStream fstr = new FileStream(file, FileMode.Open))
{
return this.Supports(fstr);
return this.Supports(fstr, fstr.Length);
}
}
@ -37,9 +37,10 @@ namespace DSDecmp.Formats
/// <param name="stream">The stream that may or may not contain compressed data. The
/// position of this stream may change during this call, but will be returned to its
/// original position when the method returns.</param>
/// <param name="inLength">The length of the input stream.</param>
/// <returns>False if the data can certainly not be decompressed using this decompressor.
/// True if the data may potentially be decompressed using this decompressor.</returns>
public abstract bool Supports(Stream stream);
public abstract bool Supports(Stream stream, long inLength);
/// <summary>
/// Decompresses the given file, writing the deocmpressed data to the given output file.

View File

@ -15,13 +15,13 @@ namespace DSDecmp.Formats.Nitro
public Huffman() : base(0) { }
public override bool Supports(System.IO.Stream stream)
public override bool Supports(System.IO.Stream stream, long inLength)
{
base.magicByte = (byte)BlockSize.FOURBIT;
if (base.Supports(stream))
if (base.Supports(stream, inLength))
return true;
base.magicByte = (byte)BlockSize.EIGHTBIT;
return base.Supports(stream);
return base.Supports(stream, inLength);
}
public override void Decompress(Stream instream, long inLength, Stream outstream)
@ -154,6 +154,9 @@ namespace DSDecmp.Formats.Nitro
// make sure to start over next round
currentNode = rootNode;
}
if (readBytes < inLength)
throw new TooMuchInputException(readBytes, inLength);
}
public override int Compress(Stream instream, long inLength, Stream outstream)

View File

@ -140,6 +140,9 @@ namespace DSDecmp.Formats.Nitro
}
}
if (readBytes < inLength)
throw new TooMuchInputException(readBytes, inLength);
}
public override int Compress(Stream instream, long inLength, Stream outstream)

View File

@ -212,6 +212,9 @@ namespace DSDecmp.Formats.Nitro
bufferOffset = (bufferOffset + 1) % bufferLength;
}
}
if (readBytes < inLength)
throw new TooMuchInputException(readBytes, inLength);
}
public override int Compress(Stream instream, long inLength, Stream outstream)

View File

@ -45,7 +45,7 @@ namespace DSDecmp.Formats.Nitro
return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
}
public override bool Supports(System.IO.Stream stream)
public override bool Supports(System.IO.Stream stream, long inLength)
{
long startPosition = stream.Position;
try

View File

@ -31,7 +31,7 @@ namespace DSDecmp.Formats.Nitro
byte type = (byte)instream.ReadByte();
if (type != base.magicByte)
throw new InvalidDataException("The provided stream is not a valid LZ-0x11 "
throw new InvalidDataException("The provided stream is not a valid RLE "
+ "compressed stream (invalid type 0x" + type.ToString("X") + ")");
byte[] sizeBytes = new byte[3];
instream.Read(sizeBytes, 0, 3);