private void Load() { IStreamProvider fStreamProvider = this.StreamProvider; using (Stream fLoadingStream = fStreamProvider.GetReadonlyStream()) { //We Must start at the beginning fLoadingStream.Seek(0L, SeekOrigin.Begin); long fStreamLength = fLoadingStream.Length; long fiStart = 0; FormatSignatureAndVersionInfo fFormatSignatureAndVersionInfo = null; while (fiStart < fStreamLength) { if (FormatSignatureAndVersionInfo.TryRead( fLoadingStream, out fFormatSignatureAndVersionInfo)) { //TODO: Verify Checksum for Version 2 + 3 Here // before we decide to break or not break; } // Look for correct HDF5 start a 512, 1024, 2048, etc // See https://support.hdfgroup.org/HDF5/doc/H5.format.html#Superblock fiStart = fiStart == 0 ? 512 : fiStart * 2; } if (ReferenceEquals(null, fFormatSignatureAndVersionInfo)) { throw new Exception("This does not appear to be an HDF5 file / stream"); } this.mrFileData.Register( fFormatSignatureAndVersionInfo); } }
internal protected Hdf5Reader GetReader() => new Hdf5Reader( mrStreamProvider.GetReadonlyStream(), mrSuperBlock);
private ISuperBlock ParseV0orV1(SuperBlockObj aContainer, bool aIsV1) { using (Stream fStream = mrStreamProvider.GetReadonlyStream()) { fStream.Seek( (long)(ulong)aContainer.LocationAddress + FormatSignatureAndVersionInfo.Length, SeekOrigin.Begin); const byte fcHeaderBytes = 15; byte[] fHeadbuffer = new byte[fcHeaderBytes]; if (fcHeaderBytes != fStream.Read(fHeadbuffer, 0, fcHeaderBytes)) { throw new EndOfStreamException("Could not read Superblock"); } aContainer.FreeSpaceStorageVersion = fHeadbuffer[0]; aContainer.RootGroupSymbolTableVersion = fHeadbuffer[1]; if (fHeadbuffer[2] != 0) { throw new InvalidDataException("Reserved byte expected to be zero"); } aContainer.SharedHeaderMessageFormatVersion = fHeadbuffer[3]; aContainer.SizeOfOffsets = fHeadbuffer[4]; aContainer.SizeOfLengths = fHeadbuffer[5]; if (fHeadbuffer[6] != 0) { throw new InvalidDataException("Reserved byte expected to be zero"); } aContainer.GroupLeafNodeK = (ushort)(fHeadbuffer[7] | (fHeadbuffer[8] << 8)); aContainer.GroupInternalNodeK = (ushort)(fHeadbuffer[9] | (fHeadbuffer[10] << 8)); if (aIsV1) { const int fcV1FeildBytes = 4; byte[] fV1Buffer = new byte[fcV1FeildBytes]; if (fcV1FeildBytes != fStream.Read(fV1Buffer, 0, fcV1FeildBytes)) { throw new EndOfStreamException("Could not read Superblock"); } aContainer.IndexedStorageInternalNodeK = (ushort)(fV1Buffer[0] + (fV1Buffer[1] << 8)); if (!(fV1Buffer[2] == 0 || fV1Buffer[3] == 0)) { throw new InvalidDataException("Reserved bytes expected to be zero"); } } aContainer.BaseAddress = aContainer.LocationAddress; using (Hdf5Reader fReader = new Hdf5Reader(fStream, aContainer, false)) { Offset fBaseAddress = fReader.ReadOffset(), fFreeSpaceAddress = fReader.ReadOffset(), fEndOfFileAddress = fReader.ReadOffset(), fDirverInformationBlockAddress = fReader.ReadOffset(); SymbolTableEntry fRootGroupEntry = SymbolTableEntry.Read(fReader); if (fBaseAddress.IsNull()) { throw new InvalidDataException("No base adddress Specified"); } aContainer.BaseAddress = fBaseAddress; aContainer.FileFreespaceInfoAddress = fFreeSpaceAddress; if (fEndOfFileAddress.IsNull()) { throw new InvalidDataException("No End Of file Adddress Specified"); } aContainer.EndOfFileAddress = fEndOfFileAddress; aContainer.DriverInformationBlockAddress = fDirverInformationBlockAddress; aContainer.RootGroupSymbolTableEntry = fRootGroupEntry; aContainer.RootGroupAddress = fRootGroupEntry.ObjectHeaderAddress; } } return(aContainer); }