protected void ReadHeader(Stream input)
{
BinaryReader br = new BinaryReader(input);
if (!input.CanSeek)
{
Exception e = new ArgumentException("input stream can not seek");
Log.Error(this, e);
throw e;
}
input.Seek(0, SeekOrigin.Begin);
byte[] sigbytes = br.ReadBytes(3);
try
{
Signature = System.Text.ASCIIEncoding.ASCII.GetString(sigbytes);
Version = br.ReadByte();
Length = br.ReadUInt32();
}
catch (EndOfStreamException e)
{
Log.Error(this, e.Message);
throw e;
}
// Checking the signature
if (Signature.Equals("FWS", StringComparison.InvariantCulture))
{
Compressed = false;
}
else if (Signature.Equals("CWS", StringComparison.InvariantCulture))
{
Compressed = true;
}
else
{
Exception e = new SwfFormatException("Invalid Signature: '" + Signature + "'");
Log.Error(this, e);
throw e;
}
// Checking the version
if ((Version > VersionMaximum) || (Version < VersionMinimum))
{
Exception e = new SwfFormatException("Invalid / unknown version " + Version.ToString());
Log.Error(this, e);
throw e;
}
if (Compressed && (Version < 6))
{
Log.Warn(this, "Compression is indicated, but version is " + Version.ToString() + " (must at least be 6)");
}
}