Exemplo n.º 1
0
 public void VerifyFileHeader(FileEntities.FileHeader fileHeader, bool blockIsCompressed, long?errorOffset)
 {
     if (!blockIsCompressed && fileHeader.CompressedFileSize != fileHeader.UncompressedFileSize)
     {
         throw new FileFormatException(FileFormatException.EntityType.FileHeader, FileFormatException.Error.InvalidValue, errorOffset, "The compressed file size should match the uncompressed size when compression is disabled.");
     }
 }
 public FileEntities.FileHeader ReadFileHeader()
 {
     // // For some reason the DeflateStream used by ZlibStream will sometimes hit EOF prematurely if we read only
     // // small parts at a time. But apparently we can work around this by reading the full file header first into
     // // a buffer and proceed by reading from the buffer.
     using (var memoryReader = new BinaryReader(new MemoryStream(this.BaseReader.ReadBytes(560)))) {
         using (var memoryStructReader = new ContainerFileLoaderStructureReader(memoryReader, true)) {
             var result = new FileEntities.FileHeader()
             {
                 Path                  = memoryStructReader.ReadUTF16String(520, FileFormatException.EntityType.FileHeader),
                 DataOffset            = memoryStructReader.ReadInt64(FileFormatException.EntityType.FileHeader),
                 CompressedFileSize    = memoryStructReader.ReadInt64(FileFormatException.EntityType.FileHeader),
                 UncompressedFileSize  = memoryStructReader.ReadInt64(FileFormatException.EntityType.FileHeader),
                 ModificationTimestamp = memoryStructReader.ReadInt64(FileFormatException.EntityType.FileHeader),
             };
             memoryStructReader.ReadInt64(FileFormatException.EntityType.FileHeader); // skipped
             return(result);
         }
     }
 }