public async Task CompressedAppendToNonEmptyStreamAndDecompress()
        {
            var sourceStr1 = "TEST this is TEST";
            var sourceStr2 = "THIS IS another TEST";

            var utils = new CompressionUtils();

            using (var source1 = GetStreamWithContents(sourceStr1))
                using (var source2 = GetStreamWithContents(sourceStr2))
                    using (var target = new MemoryStream())
                    {
                        var chunk1Position = 0;
                        await utils.CopyWithCompression(source1, target);

                        var chunk2Position = target.Position;
                        await utils.CopyWithCompression(source2, target);

                        var decompressedBytes1 = (await utils.ReadWithDecompression(target, chunk1Position)).ToArray();
                        var decompressedStr1   = Encoding.GetString(decompressedBytes1);
                        var decompressedBytes2 = (await utils.ReadWithDecompression(target, chunk2Position)).ToArray();
                        var decompressedStr2   = Encoding.GetString(decompressedBytes2);

                        sourceStr1.Should().Be(decompressedStr1);
                        sourceStr2.Should().Be(decompressedStr2);
                    }
        }
        public async Task CompressedAppendToEmptyStreamAndDecompress()
        {
            var sourceStr = "TEST this is TEST";

            var utils = new CompressionUtils();

            using (var source = GetStreamWithContents(sourceStr))
                using (var target = new MemoryStream())
                {
                    await utils.CopyWithCompression(source, target);

                    var bytes           = (await utils.ReadWithDecompression(target, 0)).ToArray();
                    var decompressedStr = Encoding.GetString(bytes);

                    sourceStr.Should().BeEquivalentTo(decompressedStr);
                }
        }
Exemplo n.º 3
0
        private async Task <DataFileCommitInfo> Commit()
        {
            var compression = new CompressionUtils();
            var commitInfo  = new DataFileCommitInfo();

            while (_nonPersistedQ.Count >= _batchSize)
            {
                var batchStartPos = _file.Position;
                var nextBatch     = ReadNextBatchFromQueue();

                using (var ms = new MemoryStream())
                {
                    await DocumentSerializer.SerializeBatch(nextBatch, ms).ConfigureAwait(false);

                    await compression.CopyWithCompression(ms, _file).ConfigureAwait(false);

                    await _file.FlushAsync().ConfigureAwait(false);
                }

                commitInfo.RecordCommittedBatch(batchStartPos, nextBatch);
            }

            return(commitInfo);
        }