public IEnumerable<DataRecord> ReadAll(long startOffset, int maxRecordCount) { if (startOffset < 0) throw new ArgumentOutOfRangeException("startOffset"); if (maxRecordCount < 0) throw new ArgumentOutOfRangeException("maxRecordCount"); var endOffset = GetEndOffset(); if (startOffset >= endOffset) yield break; if (!File.Exists(Path.Combine(_path, "stream.dat"))) throw new InvalidOperationException("File stream.chk found but stream.dat file does not exist"); using (_dataStream = new FileStream(Path.Combine(_path, "stream.dat"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (_dataBits = new BitReader(_dataStream)) { _dataStream.Seek(startOffset, SeekOrigin.Begin); int count = 0; while (_dataStream.Position < endOffset && count <= maxRecordCount) { var key = _dataBits.ReadString(); var length = _dataBits.Reader7BitInt(); if (_dataStream.Position + length > _dataStream.Length) throw new InvalidOperationException("Data length is out of range."); var data = _dataBits.ReadBytes(length); yield return new DataRecord(key, data, _dataStream.Position); if (count == maxRecordCount) break; count++; } } } }