protected override Stream DoGetFileStream(string path)
{
var file = FindFileInfo(path);
if (file == null)
{
throw new InvalidOperationException("File not found in archive: " + path);
}
Stream stream = new FileStream(ArchivePath, FileMode.Open, FileAccess.Read);
stream.Position = file.DataOffset;
long length = file.Size;
if (flags.HasFlag(ArchiveFlags.FileNameBeforeData))
{
// Consume (skip) filename before data
var singleByteBuffer = new byte[1];
stream.Read(singleByteBuffer, 0, 1);
var stringLength = singleByteBuffer[0];
stream.Seek(stringLength, SeekOrigin.Current);
// Adjust length according to consumed data
length -= stringLength + 1;
}
if (file.IsCompressed)
{
// Read original size
var originalSizeBuffer = new byte[4];
stream.Read(originalSizeBuffer, 0, 4);
uint originalSize = BitConverter.ToUInt32(originalSizeBuffer, 0);
// Deflate stream
return new CustomDeflateStream(stream, originalSize);
}
else
{
return new ArchiveSubstream(stream, length);
}
}