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

            compressor.BlockSize = _bytesPerCluster;

            int totalAllocated = 0;

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

            if (result == CompressionResult.AllZeros)
            {
                totalAllocated -= _rawStream.ReleaseClusters(focusVcn, count);
            }
            else if (result == CompressionResult.Compressed &&
                     _attr.CompressionUnitSize * _bytesPerCluster - compressedLength > _bytesPerCluster)
            {
                int compClusters = Utilities.Ceil(compressedLength, _bytesPerCluster);
                totalAllocated += _rawStream.AllocateClusters(focusVcn, compClusters);
                totalAllocated += _rawStream.WriteClusters(focusVcn, compClusters, _ioBuffer, 0);
                totalAllocated -= _rawStream.ReleaseClusters(focusVcn + compClusters,
                                                             _attr.CompressionUnitSize - compClusters);
            }
            else
            {
                totalAllocated += _rawStream.AllocateClusters(focusVcn, _attr.CompressionUnitSize);
                totalAllocated += _rawStream.WriteClusters(focusVcn, _attr.CompressionUnitSize, buffer, offset);
            }

            return(totalAllocated);
        }
예제 #2
0
        public override int WriteClusters(long startVcn, int count, byte[] buffer, int offset)
        {
            int clustersAllocated = 0;

            clustersAllocated += _rawStream.AllocateClusters(startVcn, count);
            clustersAllocated += _rawStream.WriteClusters(startVcn, count, buffer, offset);
            return(clustersAllocated);
        }