public VirtualFileOpenStream([NotNull] VirtualDiskImpl disk, [NotNull] IFileBlock file) { if (file == null) throw new ArgumentNullException("file"); if (disk == null) throw new ArgumentNullException("disk"); _disk = disk; _file = file; _currentFileBlock = _file; _bytesRead = 0; // Make sure the buffer starts out initialized _moveToNextContinuationBlock(); }
/// <summary> /// Copies the data block offsets of the <see cref="_currentFileBlock"/> to the <see cref="_offsetBuffer"/>. Signals if there are potentially more continuation blocks. /// </summary> /// <returns>True if it makes sense to call the method again; false otherwise</returns> private bool _moveToNextContinuationBlock() { // It must be safe to call this method, even if it has returned false before. if (_currentFileBlock == null) return false; // Read the entire offset list into our buffer foreach (var dataBlockOffset in _currentFileBlock) _offsetBuffer.Enqueue(dataBlockOffset); // See if it makes sense to have _moveNext called again if (_currentFileBlock.ContinuationBlockOffset != null) { _currentFileBlock = _disk.BlockManager.GetFileContinuationBlock(_currentFileBlock.ContinuationBlockOffset.Value); } else { _currentFileBlock = null; } return true; }