Exemplo n.º 1
0
        internal CompoundDocument(Stream stream, FileHeader header)
        {
            this.FileStorage = stream;
            this.Reader = new BinaryReader(this.FileStorage);
            if (stream.CanWrite)
            {
                this.Writer = new BinaryWriter(this.FileStorage, Encoding.Unicode);
            }

            this.Header = header;
            this.SectorSize = (int)Math.Pow(2, Header.SectorSizeInPot);
            this.ShortSectorSize = (int)Math.Pow(2, Header.ShortSectorSizeInPot);
            this.TotalSectors = stream.Length == 0 ? 0
                : (int)(stream.Length - 512) / this.SectorSize;

            this.MasterSectorAllocation = new MasterSectorAllocation(this);
            this.SectorAllocation = new SectorAllocation(this);
            this.ShortSectorAllocation = new ShortSectorAllocation(this);
        }
 private static void WriteHeader(BinaryWriter writer, FileHeader header)
 {
     // header size is 512 bytes
     writer.Write(header.FileTypeIdentifier);
     writer.Write(header.FileIdentifier.ToByteArray());
     writer.Write(header.RevisionNumber);
     writer.Write(header.VersionNumber);
     writer.Write(header.ByteOrderMark);
     writer.Write(header.SectorSizeInPot);
     writer.Write(header.ShortSectorSizeInPot);
     writer.Write(header.UnUsed10);
     writer.Write(header.NumberOfSATSectors);
     writer.Write(header.FirstSectorIDofDirectoryStream);
     writer.Write(header.UnUsed4);
     writer.Write(header.MinimumStreamSize);
     writer.Write(header.FirstSectorIDofShortSectorAllocationTable);
     writer.Write(header.NumberOfShortSectors);
     writer.Write(header.FirstSectorIDofMasterSectorAllocationTable);
     writer.Write(header.NumberOfMasterSectors);
     WriteArrayOfInt32(writer, header.MasterSectorAllocationTable);
 }
Exemplo n.º 3
0
 private static FileHeader ReadHeader(BinaryReader reader)
 {
     FileHeader header = new FileHeader();
     header.FileTypeIdentifier = reader.ReadBytes(8);
     header.FileIdentifier = new Guid(reader.ReadBytes(16));
     header.RevisionNumber = reader.ReadUInt16();
     header.VersionNumber = reader.ReadUInt16();
     header.ByteOrderMark = reader.ReadBytes(2);
     header.SectorSizeInPot = reader.ReadUInt16();
     header.ShortSectorSizeInPot = reader.ReadUInt16();
     header.UnUsed10 = reader.ReadBytes(10);
     header.NumberOfSATSectors = reader.ReadInt32();
     header.FirstSectorIDofDirectoryStream = reader.ReadInt32();
     header.UnUsed4 = reader.ReadBytes(4);
     header.MinimumStreamSize = reader.ReadInt32();
     header.FirstSectorIDofShortSectorAllocationTable = reader.ReadInt32();
     header.NumberOfShortSectors = reader.ReadInt32();
     header.FirstSectorIDofMasterSectorAllocationTable = reader.ReadInt32();
     header.NumberOfMasterSectors = reader.ReadInt32();
     header.MasterSectorAllocationTable = ReadArrayOfInt32(reader, 109);
     return header;
 }