Esempio n. 1
0
 private static ReadOnlyMemory <byte> Decompress(BasicDeliverEventArgs args)
 {
     return(args.BasicProperties.ContentEncoding switch
     {
         DeflateStreamHelper.ContentEncoding => DeflateStreamHelper.Decompress(args.Body),
         GzipStreamHelper.ContentEncoding => GzipStreamHelper.Decompress(args.Body),
         _ => args.Body
     });
        private static byte[] Decompress(BasicDeliverEventArgs args)
        {
            var data = args.Body.ToArray();

            return(args.BasicProperties.ContentEncoding switch
            {
                DeflateStreamHelper.ContentEncoding => DeflateStreamHelper.Decompress(data),
                GzipStreamHelper.ContentEncoding => GzipStreamHelper.Decompress(data),
                _ => data
            });
Esempio n. 3
0
        private (string?encoding, ReadOnlyMemory <byte> data) CompressData(ReadOnlyMemory <byte> source,
                                                                           CompressType type)
        {
            _logger.LogTrace("compress type : {type}", type);
            if (type == CompressType.None)
            {
                return("utf8", source);
            }

            switch (type)
            {
            case CompressType.GZip:
                return(GzipStreamHelper.ContentEncoding, GzipStreamHelper.Compress(source));

            case CompressType.Deflate:
                return(DeflateStreamHelper.ContentEncoding, DeflateStreamHelper.Compress(source));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Esempio n. 4
0
        private (string?encoding, byte[] data) CompressData(byte[] source, CompressType type)
        {
            _logger.LogTrace("compress type : {type}", type);
            if (type == CompressType.None)
            {
                return("utf8", source);
            }

            using var input = new MemoryStream();
            input.Write(source, 0, source.Length);
            input.Seek(0, SeekOrigin.Begin);
            switch (type)
            {
            case CompressType.GZip:
                return(GzipStreamHelper.ContentEncoding, GzipStreamHelper.Compress(input));

            case CompressType.Deflate:
                return(DeflateStreamHelper.ContentEncoding, DeflateStreamHelper.Compress(input));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }