예제 #1
0
        private Compression(CompressionMethod method, int?level = null)
        {
            _value = method.ToString();

            if (level.HasValue)
            {
                _value += string.Format("/{0}", level);
            }
        }
예제 #2
0
        internal static string ToExtensionString(this CompressionMethod method, params string[] parameters)
        {
            if (method == CompressionMethod.None)
            {
                return(string.Empty);
            }

            var m = $"permessage-{method.ToString().ToLower()}";

            return(parameters == null || parameters.Length == 0 ? m : $"{m}; {string.Join("; ", parameters)}");
        }
        public CompressedHttpContent(HttpContent content, CompressionMethod compressionMethod)
        {
            _originalContent   = content ?? throw new ArgumentNullException(nameof(content));
            _compressionMethod = compressionMethod;

            foreach (KeyValuePair <string, IEnumerable <string> > header in _originalContent.Headers)
            {
                Headers.TryAddWithoutValidation(header.Key, header.Value);
            }

            Headers.ContentEncoding.Add(_compressionMethod.ToString().ToLowerInvariant());
        }
예제 #4
0
        internal static string ToExtensionString(this CompressionMethod method, params string[] parameters)
        {
            if (method == CompressionMethod.None)
            {
                return(string.Empty);
            }
            string text = $"permessage-{method.ToString().ToLower()}";

            if (parameters == null || parameters.Length == 0)
            {
                return(text);
            }
            return(string.Format("{0}; {1}", text, parameters.ToString("; ")));
        }
예제 #5
0
        internal static string ToExtensionString(
            this CompressionMethod method, params string[] parameters
            )
        {
            if (method == CompressionMethod.None)
            {
                return(string.Empty);
            }

            var name = $"permessage-{method.ToString().ToLower()}";

            return(parameters != null && parameters.Length > 0
                ? $"{name}; {parameters.ToString("; ")}"
                : name);
        }
        public CompressedContent(HttpContent httpContent, CompressionMethod compressedMethod)
        {
            if (httpContent == null)
            {
                throw new ArgumentNullException(nameof(httpContent));
            }

            _originalContent   = httpContent;
            _compressionMethod = compressedMethod;

            foreach (KeyValuePair <string, IEnumerable <string> > item in _originalContent.Headers)
            {
                Headers.TryAddWithoutValidation(item.Key, item.Value);
            }
            Headers.ContentEncoding.Add(_compressionMethod.ToString());
        }
예제 #7
0
파일: Ext.cs 프로젝트: stubuntu/emby
        internal static string ToExtensionString(
            this CompressionMethod method, params string[] parameters)
        {
            if (method == CompressionMethod.None)
            {
                return(String.Empty);
            }

            var m = String.Format("permessage-{0}", method.ToString().ToLower());

            if (parameters == null || parameters.Length == 0)
            {
                return(m);
            }

            return(String.Format("{0}; {1}", m, parameters.ToString("; ")));
        }
예제 #8
0
        public CompressedContent(HttpContent content, CompressionMethod compressionMethod)
        {
            if (compressionMethod == CompressionMethod.None)
            {
                throw new ArgumentException("Invalid CompressionMethod", nameof(compressionMethod));
            }

            _originalContent   = content ?? throw new ArgumentNullException(nameof(content));
            _compressionMethod = compressionMethod;

            foreach (var header in _originalContent.Headers)
            {
                Headers.TryAddWithoutValidation(header.Key, header.Value);
            }

            Headers.ContentEncoding.Add(_compressionMethod.ToString().ToLowerInvariant());
        }
예제 #9
0
        private static void CreatePackageResource(string file = "")
        {
            if (string.IsNullOrEmpty(file))
            {
                file = CommandLineActions.DestinationPath;
                CommandLineLogger.LogDebug($"Using destination path: {file}");
            }

            PackageVersion packageVersion = CommandLineActions.PackageVersion;
            Dictionary <string, object> compressionOptions = CommandLineArguments.GetCompressionOptions(Path.GetExtension(file)?.ToLower() == ".lsv" ? "zlib" : Args.CompressionMethod, packageVersion);

            CompressionMethod compressionMethod = (CompressionMethod)compressionOptions["Compression"];
            bool compressionSpeed = (bool)compressionOptions["FastCompression"];

            CommandLineLogger.LogDebug($"Using compression method: {compressionMethod.ToString()}");
            CommandLineLogger.LogDebug($"Using fast compression: {compressionSpeed}");

            Packager packager = new Packager();

            packager.CreatePackage(file, CommandLineActions.SourcePath, packageVersion, compressionMethod, compressionSpeed);

            CommandLineLogger.LogInfo("Package created successfully.");
        }
예제 #10
0
 public Method(CompressionMethod method) : this()
 {
     Value = method.ToString();
 }
예제 #11
0
 internal static string ToExtensionString(this CompressionMethod method)
 {
     return((method == CompressionMethod.None) ? string.Empty : string.Format("permessage-{0}", method.ToString().ToLower()));
 }
예제 #12
0
 public Method(CompressionMethod method) : this()
 {
     Value = method.ToString();
 }
예제 #13
0
 private static string createDeprecatedCompressionExtension(CompressionMethod method)
 {
     return method != CompressionMethod.NONE
      ? String.Format("permessage-compress; method={0}", method.ToString().ToLower())
      : String.Empty;
 }
예제 #14
0
 private Compression(CompressionMethod method, CompressionLevel level)
 {
     _value = method.ToString() + "/" + level.ToString();
 }
예제 #15
0
        public static CompressionModule FromKnownCompressionMethod(CompressionMethod method)
        {
            switch (method)
            {
            case CompressionMethod.None: return(new Modules.Store.StoreCompressionModule());

            case CompressionMethod.Bzip2: return(new Modules.Bzip2.Bzip2CompressionModule());

            case CompressionMethod.Deflate: return(new Modules.Deflate.DeflateCompressionModule());

            case CompressionMethod.Gzip: return(new Modules.Gzip.GzipCompressionModule());

            case CompressionMethod.LZSS: return(new Modules.LZSS.LZSSCompressionModule());

            case CompressionMethod.LZRW1: return(new Modules.LZRW1.LZRW1CompressionModule());

            case CompressionMethod.LZX: return(new Modules.LZX.LZXCompressionModule());

            case CompressionMethod.XMemLZX: return(new Modules.XMemLZX.XMemLZXCompressionModule());

            case CompressionMethod.Zlib: return(new Modules.Zlib.ZlibCompressionModule());
            }
            throw new ArgumentException("Could not identify compression module for method " + method.ToString());
        }
예제 #16
0
 internal static string ToExtensionString(this CompressionMethod method)
 {
     return(method != CompressionMethod.None ? $"permessage-{method.ToString().ToLower()}" : string.Empty);
 }
        public void SetMethod(CompressionMethod method)
        {
            if (!Enum.IsDefined(typeof(CompressionMethod), method))
            {
                throw new InvalidEnumArgumentException();
            }
            switch (this.KnownFormat)
            {
                case KnownSevenZipFormat.Xz:
                    if (method != CompressionMethod.LZMA2)
                    {
                        throw new NotSupportedException();
                    }
                    return;

                case KnownSevenZipFormat.Zip:
                    switch (method)
                    {
                        case CompressionMethod.Copy:
                        case CompressionMethod.LZMA:
                        case CompressionMethod.PPMd:
                        case CompressionMethod.BZip2:
                        case CompressionMethod.Deflate:
                        case CompressionMethod.Deflate64:
                            this.Properties["m"] = method.ToString();
                            return;
                    }
                    break;

                case KnownSevenZipFormat.Tar:
                    if (method != CompressionMethod.Copy)
                    {
                        throw new NotSupportedException();
                    }
                    return;

                case KnownSevenZipFormat.SevenZip:
                    switch (method)
                    {
                        case CompressionMethod.Copy:
                        case CompressionMethod.LZMA:
                        case CompressionMethod.LZMA2:
                        case CompressionMethod.PPMd:
                        case CompressionMethod.BZip2:
                            this.Properties["0"] = method.ToString();
                            return;
                    }
                    throw new NotSupportedException();

                case KnownSevenZipFormat.BZip2:
                    if (method != CompressionMethod.BZip2)
                    {
                        throw new NotSupportedException();
                    }
                    return;

                case KnownSevenZipFormat.GZip:
                    if (method != CompressionMethod.Deflate)
                    {
                        throw new NotSupportedException();
                    }
                    return;

                default:
                    throw new NotSupportedException();
            }
            throw new NotSupportedException();
        }