Exemple #1
0
        private void LoadCache(long vcn)
        {
            long cuStart = CompressionStart(vcn);

            if (_cacheBufferVcn != cuStart)
            {
                if (_rawStream.AreAllClustersStored(cuStart, _attr.CompressionUnitSize))
                {
                    // Uncompressed data - read straight into cache buffer
                    _rawStream.ReadClusters(cuStart, _attr.CompressionUnitSize, _cacheBuffer, 0);
                }
                else if (_rawStream.IsClusterStored(cuStart))
                {
                    // Compressed data - read via IO buffer
                    _rawStream.ReadClusters(cuStart, _attr.CompressionUnitSize, _ioBuffer, 0);

                    int expected =
                        (int)
                        Math.Min(_attr.Length - vcn * _bytesPerCluster, _attr.CompressionUnitSize * _bytesPerCluster);

                    int decomp = _context.Options.Compressor.Decompress(_ioBuffer, 0, _ioBuffer.Length, _cacheBuffer, 0);
                    if (decomp < expected)
                    {
                        throw new IOException("Decompression returned too little data");
                    }
                }
                else
                {
                    // Sparse, wipe cache buffer directly
                    Array.Clear(_cacheBuffer, 0, _cacheBuffer.Length);
                }

                _cacheBufferVcn = cuStart;
            }
        }
Exemple #2
0
 public override void ReadClusters(long startVcn, int count, byte[] buffer, int offset)
 {
     _rawStream.ReadClusters(startVcn, count, buffer, offset);
 }