예제 #1
0
        private void CompressAndWriteClusters(long focusVcn, int count, byte[] buffer, int offset)
        {
            BlockCompressor compressor = _context.Options.Compressor;

            compressor.BlockSize = _bytesPerCluster;

            int compressedLength = _ioBuffer.Length;
            var result           = compressor.Compress(buffer, offset, _attr.CompressionUnitSize * _bytesPerCluster, _ioBuffer, 0, ref compressedLength);

            if (result == CompressionResult.AllZeros)
            {
                _rawStream.ReleaseClusters(focusVcn, count);
            }
            else if (result == CompressionResult.Compressed && (_attr.CompressionUnitSize * _bytesPerCluster) - compressedLength > _bytesPerCluster)
            {
                int compClusters = Utilities.Ceil(compressedLength, _bytesPerCluster);
                _rawStream.AllocateClusters(focusVcn, compClusters);
                _rawStream.WriteClusters(focusVcn, compClusters, _ioBuffer, 0);
                _rawStream.ReleaseClusters(focusVcn + compClusters, _attr.CompressionUnitSize - compClusters);
            }
            else
            {
                _rawStream.AllocateClusters(focusVcn, _attr.CompressionUnitSize);
                _rawStream.WriteClusters(focusVcn, _attr.CompressionUnitSize, buffer, offset);
            }
        }
예제 #2
0
 public override void WriteClusters(long startVcn, int count, byte[] buffer, int offset)
 {
     _rawStream.AllocateClusters(startVcn, count);
     _rawStream.WriteClusters(startVcn, count, buffer, offset);
 }