예제 #1
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);
            }
        }
예제 #2
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);
            }
        }