private Stream EnsureStream() { if (_stream is null) { var name = _heap.GetObjectName(_slot.NameHeapOffset); var filePath = H5Utils.ConstructExternalFilePath(name, _datasetAccess); if (!File.Exists(filePath)) { throw new Exception($"External file '{filePath}' does not exist."); } _stream = File.OpenRead(filePath); _stream.Seek((long)_slot.Offset, SeekOrigin.Begin); } return(_stream); }
public H5NamedReference GetTarget(H5LinkAccess linkAccess) { // this file if (string.IsNullOrWhiteSpace(this.ObjectPath)) { try { var reference = this.Parent.InternalGet(this.Value, linkAccess); reference.Name = this.Name; return(reference); } catch (Exception ex) { return(new H5NamedReference(this.Name, Superblock.UndefinedAddress) { Exception = ex }); } } // external file else { try { var absoluteFilePath = H5Utils.ConstructExternalFilePath(this.Parent.File, this.Value, linkAccess); var objectPath = this.ObjectPath; var externalFile = H5Cache.GetH5File(this.Parent.Context.Superblock, absoluteFilePath); return(externalFile.InternalGet(objectPath, linkAccess)); } catch (Exception ex) { return(new H5NamedReference(this.Name, Superblock.UndefinedAddress) { Exception = ex }); } } }
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; } }