예제 #1
0
        private TModel Seek(long location)
        {
            var 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);
        }
예제 #2
0
        public Reader(string path)
        {
            var file = new FileInfo(path);

            _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);

            var ifile   = ModelUtility.GetIndexFile(path);
            var isize   = Marshal.SizeOf(typeof(Element));
            var ibuffer = new byte[isize];

            using (var istream = ifile.Open(FileMode.Open, FileAccess.Read, FileShare.Read)) {
                while (istream.Read(ibuffer, 0, isize) != 0)
                {
                    var element = ModelUtility.PtrToStructure <Element>(ref ibuffer);

                    _index.Add(element.Id, element.Position);
                }
            }
        }