Esempio n. 1
0
        private void NextBlock()
        {
            long position = _context.RawStream.Position;

            uint writeLen = _context.WriteDataBlock(_currentBlock, 0, _currentOffset);
            FragmentRecord blockRecord = new FragmentRecord()
            {
                StartBlock = position,
                CompressedSize = (int)writeLen
            };

            _fragmentBlocks.Add(blockRecord);
        }
Esempio n. 2
0
        private int ReadFrag(int pos, byte[] buffer, int offset, int count)
        {
            int fragRecordsPerBlock = 8192 / FragmentRecord.RecordSize;
            int fragTable = (int)_inode.FragmentKey / fragRecordsPerBlock;
            int recordOffset = (int)(_inode.FragmentKey % fragRecordsPerBlock) * FragmentRecord.RecordSize;

            byte[] fragRecordData = new byte[FragmentRecord.RecordSize];

            _context.FragmentTableReaders[fragTable].SetPosition(0, recordOffset);
            _context.FragmentTableReaders[fragTable].Read(fragRecordData, 0, fragRecordData.Length);

            FragmentRecord fragRecord = new FragmentRecord();
            fragRecord.ReadFrom(fragRecordData, 0);

            Block frag = _context.ReadBlock(fragRecord.StartBlock, fragRecord.CompressedSize);

            // Attempt to read data beyond end of fragment
            if (pos > frag.Available)
            {
                return 0;
            }

            int toCopy = (int)Math.Min(frag.Available - (_inode.FragmentOffset + pos), count);
            Array.Copy(frag.Data, _inode.FragmentOffset + pos, buffer, offset, toCopy);
            return toCopy;
        }