Пример #1
0
        private static void AssertAlgorithm(ICompressionAlgorithm algorithm, string text)
        {
            Assert.AreEqual(text,
                            Encoding.UTF8.GetString(algorithm.Decompress(algorithm.Compress(Encoding.UTF8.GetBytes(text)))));

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(text)))
                using (var compressed = algorithm.Compress(stream))
                    using (var decompressed = algorithm.Decompress(compressed))
                        using (var decompressedStream = new MemoryStream())
                        {
                            decompressed.CopyTo(decompressedStream);

                            Assert.AreEqual(text, Encoding.UTF8.GetString(decompressedStream.ToArray()));
                        }
        }
Пример #2
0
        private void ReadIntervalScores(PhylopInterval interval)
        {
            if (interval == null)
            {
                return;
            }

            var filePosition = interval.FilePosition;

            //going to the file location that contains this interval.
            if (filePosition != -1)
            {
                _reader.BaseStream.Position = filePosition;
            }
            else
            {
                return;
            }

            var length           = _reader.ReadInt32();
            var compressedScores = _reader.ReadBytes(length);

            int requiredBufferSize = _qlz.GetDecompressedLength(compressedScores, length);

            if (requiredBufferSize > _scoreBytes.Length)
            {
                _scoreBytes = new byte[requiredBufferSize];
            }

            var uncompressedLength = _qlz.Decompress(compressedScores, length, _scoreBytes, _scoreBytes.Length);

            BytesToScores(uncompressedLength, _scoreBytes, _scores);

            _scoreCount = uncompressedLength / 2;
        }
Пример #3
0
        public Message Decompress(ICompressionAlgorithm packer)
        {
            var result = packer.Decompress(Content);

            Size = 0;
            AddBytes(result);
            return(this);
        }
Пример #4
0
        public void Read(ExtendedBinaryReader reader)
        {
            _compressedLength = reader.ReadOptInt32();
            _firstPosition    = reader.ReadOptInt32();
            //_lastPosition = reader.ReadOptInt32();
            _count = reader.ReadOptInt32();
            reader.Read(_compressedBlock, 0, _compressedLength);

            _uncompressedLength = _compressionAlgorithm.Decompress(_compressedBlock, _compressedLength,
                                                                   _uncompressedBlock, _uncompressedBlock.Length);
        }
Пример #5
0
        public static Stream Decompress(this ICompressionAlgorithm algorithm, Stream stream)
        {
            Guard.AgainstNull(algorithm, nameof(algorithm));
            Guard.AgainstNull(stream, nameof(stream));

            using (var ms = new MemoryStream())
            {
                stream.CopyTo(ms);

                return(new MemoryStream(algorithm.Decompress(ms.ToArray())));
            }
        }
Пример #6
0
        private int ReadCompressedBlock(Stream stream)
        {
            var numBytesRead = stream.Read(_compressedBlock, 0, _header.NumCompressedBytes);

            if (numBytesRead != _header.NumCompressedBytes)
            {
                throw new IOException($"Expected {_header.NumCompressedBytes} bytes from the block, but received only {numBytesRead} bytes.");
            }

            int numUncompressedBytes = _compressionAlgorithm.Decompress(_compressedBlock, _header.NumCompressedBytes, _uncompressedBlock, Size);

            if (numUncompressedBytes != _header.NumUncompressedBytes)
            {
                throw new CompressionException($"Expected {_header.NumUncompressedBytes} bytes after decompression, but found only {numUncompressedBytes} bytes.");
            }

            return(numBytesRead);
        }
Пример #7
0
        private async Task <bool> ArchiveExtraction(ICompressionAlgorithm compressionAlgorithm, string fileType)
        {
            var archive = await _workingDir.GetFileAsync(ArchiveName + fileType);

            Assert.IsNotNull(archive);

            var outputFolder = await _workingDir.CreateFolderAsync("simpleZipUiTempOutput");

            Assert.IsNotNull(outputFolder);

            // extract archive
            Assert.IsTrue(await compressionAlgorithm.Decompress(archive, outputFolder));

            var files = await outputFolder.GetFilesAsync();

            Assert.IsNotNull(files);

            if (files.Count == 1)
            {
                foreach (var file in files)
                {
                    using (var streamReader = new StreamReader(await file.OpenStreamForReadAsync()))
                    {
                        var line = streamReader.ReadLine();
                        Assert.IsNotNull(line);

                        if (!line.Equals(FileText))
                        {
                            Assert.Fail("Files do not match.");
                        }
                    }
                }
            }
            else
            {
                Assert.Fail("Archive not properly created.");
            }

            await outputFolder.DeleteAsync(); // clean up when done

            return(true);
        }
Пример #8
0
 public IMemoryOwner <byte> Decompress(ReadOnlyMemory <byte> input) =>
 _compressionAlgorithm.Decompress(input);
        public IMemoryOwner <byte> Decompress(ReadOnlyMemory <byte> input, IRequestSpan parentSpan)
        {
            using var _ = parentSpan.DecompressionSpan();

            return(_compressionAlgorithm.Decompress(input));
        }