public Reader(string path) { this.path = path; FileInfo file = new FileInfo(path); if (!file.Exists) { throw new Exception("Reader passed path '" + path + "' which does not exist!"); } _size = Marshal.SizeOf(typeof(TModel)); _buffer = new byte[_size]; _stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read); _count = (int)file.Length / _size; _index = new Dictionary <int, long>(_count); FileInfo ifile = ModelUtility.GetIndexFile(path); int isize = Marshal.SizeOf(typeof(Element)); byte[] ibuffer = new byte[isize]; using (FileStream istream = ifile.Open(FileMode.Open, FileAccess.Read, FileShare.Read)) { while (istream.Read(ibuffer, 0, isize) != 0) { Element element = ModelUtility.PtrToStructure <Element>(ref ibuffer); _index.Add(element.Id, element.Position); } } }
private TModel Seek(long location) { long offset = location - _position; if (offset != 0) { _stream.Seek(offset, SeekOrigin.Current); } _position = location + _size; _stream.Read(_buffer, 0, _size); _model = ModelUtility.PtrToStructure <TModel>(ref _buffer); return(_model); }