Exemple #1
0
        public void InvertsStream(Mode mode, int bufferSize, string expected)
        {
            // Arrange
            Func <byte[], IEnumerable <byte> > map;

            switch (mode)
            {
            case Mode.Reduce:
                map = bytes => bytes.Where((b, i) => i % 4 == 0);
                break;

            case Mode.Expand:
                map = bytes => bytes.Concat(new[] { UnderscoreByte });
                break;

            case Mode.Replace:
                map = bytes => bytes.Select(b => UnderscoreByte);
                break;

            case Mode.Identity:
                map = bytes => bytes;
                break;

            default:
                throw new NotSupportedException($"The mode '{mode}' is not supported.");
            }

            var source      = new MemoryStream(Encoding.ASCII.GetBytes("These are the source bytes!"));
            var inverted    = new InvertedStream(source, buffer => new MapStream(buffer, map));
            var destination = new MemoryStream();

            // Act
            using (inverted)
            {
                inverted.CopyTo(destination, bufferSize);
            }

            // Assert
            var actual = Encoding.ASCII.GetString(destination.ToArray());

            actual.Should().Be(expected);
        }
Exemple #2
0
 public async Task SetAsync(string key, Stream stream, CancellationToken cancellationToken)
 {
     var compressionStream = new InvertedStream(stream, b => new GZipStream(b, _compressionLevel));
     await _innerStore.SetAsync(key, compressionStream, cancellationToken).ConfigureAwait(false);
 }