コード例 #1
0
        public ExternalFileListStream(ExternalFileListMessage externalFileList, H5DatasetAccess datasetAccess)
        {
            var offset = 0L;

            _slotStreams = externalFileList
                           .SlotDefinitions
                           .Select(slot =>
            {
                var stream = new SlotStream(externalFileList.Heap, slot, offset, datasetAccess);
                offset    += stream.Length;
                return(stream);
            })
                           .ToArray();

            if (_slotStreams.Any())
            {
                this.Length =
                    _slotStreams.Last().Offset +
                    _slotStreams.Last().Length;
            }
            else
            {
                throw new Exception("There must at least a single file be defined in the external file list.");
            }
        }
コード例 #2
0
        private void ReadExternalFileList(Span <byte> buffer, ExternalFileListMessage externalFileList, H5DatasetAccess datasetAccess)
        {
            var bufferOffset  = 0;
            var remainingSize = buffer.Length;

            foreach (var slotDefinition in externalFileList.SlotDefinitions)
            {
                var length   = Math.Min(remainingSize, (int)slotDefinition.Size);
                var heap     = externalFileList.Heap;
                var name     = heap.GetObjectName(slotDefinition.NameHeapOffset);
                var filePath = H5Utils.ConstructExternalFilePath(name, datasetAccess);

                if (!File.Exists(filePath))
                {
                    throw new Exception($"External file '{filePath}' does not exist.");
                }

                try
                {
                    using var fileStream = File.OpenRead(filePath);
                    fileStream.Seek((long)slotDefinition.Offset, SeekOrigin.Begin);

                    var actualLength  = Math.Min(length, fileStream.Length);
                    var currentBuffer = buffer.Slice(bufferOffset, (int)actualLength);

                    fileStream.Read(currentBuffer);
                }
                catch
                {
                    throw new Exception($"Unable to open external file '{filePath}'.");
                }

                bufferOffset  += length;
                remainingSize -= length;
            }
        }