Пример #1
0
        public override T Read <T>(Func <H5BinaryReader, T> func, [AllowNull] ref List <BTree2Record01> record01Cache)
        {
            // huge objects b-tree v2
            if (record01Cache is null)
            {
                _reader.Seek((long)_heapHeader.HugeObjectsBTree2Address, SeekOrigin.Begin);
                var hugeBtree2 = new BTree2Header <BTree2Record01>(_reader, _superblock, this.DecodeRecord01);
                record01Cache = hugeBtree2.EnumerateRecords().ToList();
            }

            var hugeRecord = record01Cache.FirstOrDefault(record => record.HugeObjectId == this.BTree2Key);

            _reader.Seek((long)hugeRecord.HugeObjectAddress, SeekOrigin.Begin);

            return(func(_reader));
        }
Пример #2
0
        public override T Read <T>(Func <H5BinaryReader, T> func, [AllowNull] ref List <BTree2Record01> record01Cache)
        {
            var address = _header.GetAddress(this);

            _reader.Seek((long)address, SeekOrigin.Begin);
            return(func(_reader));
        }
Пример #3
0
        public bool TryFindUserData <TUserData>([NotNullWhen(returnValue: true)] out TUserData userData,
                                                Func <T, T, int> compare3,
                                                FoundDelegate <T, TUserData> found)
            where TUserData : struct
        {
            userData = default;

            // H5B.c (H5B_find)

            /*
             * Perform a binary search to locate the child which contains
             * the thing for which we're searching.
             */
            (var index, var cmp) = this.LocateRecord(compare3);

            /* Check if not found */
            if (cmp != 0)
            {
                return(false);
            }

            /*
             * Follow the link to the subtree or to the data node.
             */
            var childAddress = this.ChildAddresses[(int)index];
            var key          = this.Keys[index];

            if (this.NodeLevel > 0)
            {
                _reader.Seek((long)childAddress, SeekOrigin.Begin);
                var subtree = new BTree1Node <T>(_reader, _superblock, _decodeKey);

                if (subtree.TryFindUserData(out userData, compare3, found))
                {
                    return(true);
                }
            }
            else
            {
                if (found(childAddress, key, out userData))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #4
0
        internal static H5File Open(string filePath, FileMode mode, FileAccess fileAccess, FileShare fileShare, bool deleteOnClose)
        {
            if (!BitConverter.IsLittleEndian)
            {
                throw new Exception("This library only works on little endian systems.");
            }

            var absoluteFilePath = System.IO.Path.GetFullPath(filePath);
            var reader           = new H5BinaryReader(System.IO.File.Open(absoluteFilePath, mode, fileAccess, fileShare));

            // superblock
            int stepSize  = 512;
            var signature = reader.ReadBytes(8);

            while (!H5File.ValidateSignature(signature, Superblock.FormatSignature))
            {
                reader.Seek(stepSize - 8, SeekOrigin.Current);

                if (reader.BaseStream.Position >= reader.BaseStream.Length)
                {
                    throw new Exception("The file is not a valid HDF 5 file.");
                }

                signature = reader.ReadBytes(8);
                stepSize *= 2;
            }

            var version = reader.ReadByte();

            var superblock = (Superblock)(version switch
            {
                0 => new Superblock01(reader, version),
                1 => new Superblock01(reader, version),
                2 => new Superblock23(reader, version),
                3 => new Superblock23(reader, version),
                _ => throw new NotSupportedException($"The superblock version '{version}' is not supported.")
            });
Пример #5
0
 private static GlobalHeapCollection ReadGlobalHeapCollection(H5BinaryReader reader, Superblock superblock, ulong address)
 {
     reader.Seek((long)address, SeekOrigin.Begin);
     return(new GlobalHeapCollection(reader, superblock));
 }