コード例 #1
0
            public void Should_not_left_some_buffers_in_stream_when_compressed_blocks_has_length_in_headers_and_blocks_smaller_than_buffer_limit()
            {
                var compressed       = TestData.ShortFileContent.CompessWithDecompressionHelp(DecompressionHelpMode.BlockLengthInMimetypeSection);
                var stream           = Enumerable.Range(0, 5).SelectMany(_ => compressed).ToArray().AsStream();
                var splitter         = new MimeTypeLengthGzipSplitter(compressed.Length * 2, log);
                var rewindableStream = new RewindableReadonlyStream(stream);

                splitter.SplitToIndependentBlocks(rewindableStream).Enumerate();

                rewindableStream.ReturnedBuffer.Should().HaveCount(0);
            }
コード例 #2
0
            public void Should_split_into_blocks_when_compressed_blocks_has_length_in_headers_and_blocks_smaller_than_buffer_limit()
            {
                var compressed       = TestData.ShortFileContent.CompessWithDecompressionHelp(DecompressionHelpMode.BlockLengthInMimetypeSection);
                var stream           = Enumerable.Range(0, 5).SelectMany(_ => compressed).ToArray().AsStream();
                var splitter         = new MimeTypeLengthGzipSplitter(compressed.Length * 2, log);
                var rewindableStream = new RewindableReadonlyStream(stream);

                var blocks = splitter.SplitToIndependentBlocks(rewindableStream).ToArray();

                blocks.Should().HaveCount(6);
                blocks.Take(5).Should().OnlyContain(x => x.HasBlock);
                blocks[5].Status.Should().Be(GzipSplittingStatus.StreamIsEnd);
            }
コード例 #3
0
            public void Should_return_a_block_when_it_compressed_with_length_in_header_and_smaller_than_buffer_limit()
            {
                var compressed       = TestData.ShortFileContent.CompessWithDecompressionHelp(DecompressionHelpMode.BlockLengthInMimetypeSection);
                var stream           = compressed.ToArray().AsStream();
                var splitter         = new MimeTypeLengthGzipSplitter(compressed.Length * 2, log);
                var rewindableStream = new RewindableReadonlyStream(stream);

                var blocks = splitter.SplitToIndependentBlocks(rewindableStream).ToArray();

                blocks.Should().HaveCount(2);
                blocks[0].HasBlock.Should().BeTrue();
                blocks[1].Status.Should().Be(GzipSplittingStatus.StreamIsEnd);
            }
コード例 #4
0
            public void Should_split_into_correctly_decomressable_independent_blocks()
            {
                var expectedBlockStrings = Enumerable.Range(0, 5)
                                           .Select(x => x + " " + TestData.ShortFileContent.Shuffle())
                                           .ToArray();

                var stream           = expectedBlockStrings.SelectMany(x => x.CompessWithDecompressionHelp(DecompressionHelpMode.BlockLengthInMimetypeSection)).ToArray().AsStream();
                var splitter         = new MimeTypeLengthGzipSplitter(int.MaxValue, log);
                var rewindableStream = new RewindableReadonlyStream(stream);

                var blocks = splitter.SplitToIndependentBlocks(rewindableStream).ToArray();

                blocks.Should().HaveCount(6);
                blocks.Take(5).Should().OnlyContain(x => x.HasBlock);
                blocks[5].Status.Should().Be(GzipSplittingStatus.StreamIsEnd);
                var actualBlocksStrings = blocks.Take(5).Select(x => x.Block.Decompress().AsString()).ToArray();

                actualBlocksStrings.Should().BeEquivalentTo(expectedBlockStrings);
            }
コード例 #5
0
            public void Should_not_to_split_stream_and_return_used_bytes_when_first_block_have_invalid_length(BrokenLengthCases theCase)
            {
                var wrongLengthInHeader = TestData.ShortFileContent.CompessWithDecompressionHelp(DecompressionHelpMode.BlockLengthInMimetypeSection);
                var expectedReadedBytes = SetLengthToHeader(wrongLengthInHeader, theCase);
                var withLengthInHeader  = TestData.ShortFileContent.CompessWithDecompressionHelp(DecompressionHelpMode.BlockLengthInMimetypeSection);

                var bytes = Enumerable.Range(0, 5)
                            .Select(_ => withLengthInHeader)
                            .Prepend(wrongLengthInHeader)
                            .SelectMany(x => x)
                            .ToArray();
                var stream           = bytes.AsStream();
                var splitter         = new MimeTypeLengthGzipSplitter(int.MaxValue, log);
                var rewindableStream = new RewindableReadonlyStream(stream);

                var blocks = splitter.SplitToIndependentBlocks(rewindableStream).ToArray();

                blocks.Should().HaveCount(1);
                blocks[0].Status.Should().Be(GzipSplittingStatus.CantReadBlock);
                rewindableStream.ReturnedBuffer.Should().HaveCount(expectedReadedBytes);
                rewindableStream.ReturnedBuffer.Should().BeEquivalentTo(bytes.Take(expectedReadedBytes).ToArray());
            }