Ejemplo n.º 1
0
        protected override void Read(CustomConcurentQueue inputBlocks, string inputFilePath)
        {
            int blockIndex = 0;

            using (FileStream _compressedFile = new FileStream(inputFilePath, FileMode.Open))
            {
                while (_compressedFile.Position < _compressedFile.Length)
                {
                    if (inputBlocks.Count > _safeElementsCounts)
                    {
                        continue;
                    }

                    byte[] lengthBuffer = new byte[8];
                    _compressedFile.Read(lengthBuffer, 0, lengthBuffer.Length);
                    int    blockLength    = BitConverter.ToInt32(lengthBuffer, 4);
                    byte[] compressedData = new byte[blockLength];
                    lengthBuffer.CopyTo(compressedData, 0);

                    _compressedFile.Read(compressedData, 8, blockLength - 8);

                    inputBlocks.Add(blockIndex, compressedData);
                    blockIndex++;
                }
            }

            _isReadFinished = true;
        }
Ejemplo n.º 2
0
        protected override void Read(CustomConcurentQueue inputBlocks, string inputFilePath)
        {
            using (FileStream _fileForCompressing = new FileStream(inputFilePath, FileMode.Open))
            {
                int    bytesRead;
                byte[] lastBuffer;
                int    blockIndex = 0;

                while (_fileForCompressing.Position < _fileForCompressing.Length)
                {
                    if (inputBlocks.Count > _safeElementsCounts)
                    {
                        continue;
                    }

                    if (_fileForCompressing.Length - _fileForCompressing.Position <= _blockSize)
                    {
                        bytesRead = (int)(_fileForCompressing.Length - _fileForCompressing.Position);
                    }
                    else
                    {
                        bytesRead = _blockSize;
                    }

                    lastBuffer = new byte[bytesRead];
                    _fileForCompressing.Read(lastBuffer, 0, bytesRead);
                    inputBlocks.Add(blockIndex, lastBuffer);
                    blockIndex++;
                }
            }

            _isReadFinished = true;
        }
Ejemplo n.º 3
0
        protected override void ProcessBlock(CustomConcurentQueue outputBlocks, KeyValuePair <int, byte[]> block)
        {
            using (MemoryStream _memoryStream = new MemoryStream())
            {
                using (GZipStream cs = new GZipStream(_memoryStream, CompressionMode.Compress))
                {
                    cs.Write(block.Value, 0, block.Value.Length);
                }

                byte[] compressedData = _memoryStream.ToArray();
                outputBlocks.Add(block.Key, compressedData);
            }
        }
Ejemplo n.º 4
0
        protected override void ProcessBlock(CustomConcurentQueue outputBlocks, KeyValuePair <int, byte[]> block)
        {
            using (MemoryStream ms = new MemoryStream(block.Value))
            {
                using (GZipStream _gz = new GZipStream(ms, CompressionMode.Decompress))
                {
                    // The last 4 bytes of the gz file contains the length
                    byte[] originalLengthByteArray = new byte[4];
                    Array.Copy(block.Value, block.Value.Length - 4, originalLengthByteArray, 0, 4);
                    int length = BitConverter.ToInt32(originalLengthByteArray, 0);

                    byte[] outByte = new byte[length];
                    _gz.Read(outByte, 0, outByte.Length);
                    byte[] decompressedData = outByte.ToArray();

                    outputBlocks.Add(block.Key, decompressedData);
                }
            }
        }