Esempio n. 1
0
 // flushes the data in the BGZF block
 protected void FlushBlock()
 {
     if (_compressQueue != null)
     {
         // Save the block to the queue to be processed on multiple threads.
         CompressedData compressedData = new CompressedData();
         _writeQueue.Add(compressedData);
         _compressQueue.Add(new Data((byte[])UncompressedBlock.Clone(), BlockOffset, compressedData));
         BlockOffset = 0;
     }
     else
     {
         // flush all of the remaining blocks
         while (BlockOffset > 0)
         {
             BlockAddress += FlushSingleBlock();
         }
     }
 }
Esempio n. 2
0
        // writes data to the BGZF block
        protected int Write(byte[] data, uint dataLength)
        {
            // initialize
            const int blockLength     = MaxBlockSize;
            int       numBytesWritten = 0;
            int       inputIndex      = 0;

            // copy the data to the buffer
            while (numBytesWritten < dataLength)
            {
                int copyLength = Math.Min(blockLength - BlockOffset, (int)dataLength - numBytesWritten);

                Buffer.BlockCopy(data, inputIndex, UncompressedBlock, BlockOffset, copyLength);

                BlockOffset     += copyLength;
                inputIndex      += copyLength;
                numBytesWritten += copyLength;

                if (BlockOffset == blockLength)
                {
                    if (_compressQueue != null)
                    {
                        // Save the block to the queue to be processed on multiple threads.
                        CompressedData compressedData = new CompressedData();
                        _writeQueue.Add(compressedData);
                        _compressQueue.Add(new Data((byte[])UncompressedBlock.Clone(), blockLength, compressedData));
                        BlockOffset = 0;
                    }
                    else
                    {
                        FlushBlock();
                    }
                }
            }

            return(numBytesWritten);
        }