示例#1
0
        public static LfxPointer Create(Stream stream)
        {
            stream = new StreamCounter(stream);
            var hash  = LfxHash.Compute(stream);
            var count = stream.Position;

            return(Create(hash, count));
        }
示例#2
0
 public static LfxHash ComputeHash(this byte[] bytes, int count) => LfxHash.Compute(bytes, count);
示例#3
0
 public static LfxHash ComputeHash(this byte[] bytes) => LfxHash.Compute(bytes);
示例#4
0
 public static LfxHash ComputeHash(this Stream stream) => LfxHash.Compute(stream);
示例#5
0
 public static LfxHash ComputeHash(this string value) => LfxHash.Compute(value);
示例#6
0
        public static LfxPointer Create(string path, LfxHash?hash = null)
        {
            LfxPointer pointer;

            var length = new FileInfo(path).Length;

            if (hash == null)
            {
                hash = LfxHash.Compute(path);
            }
            pointer = Create(hash.Value, length);

            var config = LfxConfig.Load(path);

            // simple
            if (config.Type == LfxPointerType.Simple)
            {
                return(pointer);
            }

            var url     = config.Url;
            var relPath = config.ConfigFile.Path.MakeRelativePath(path);

            if (config.HasPattern)
            {
                // change base of relPath to config file containing pattern
                relPath = config.Pattern.ConfigFile.Path.MakeRelativePath(path);
                url     = Regex.Replace(
                    input: relPath,
                    pattern: config.Pattern,
                    replacement: config.Url
                    );
            }

            // curl
            if (config.Type == LfxPointerType.Curl)
            {
                return(pointer.AddUrl(url.ToUrl()));
            }

            // default hint is relPath
            var hint = relPath;

            if (config.HasHint)
            {
                // hardcoded hint (very rare)
                hint = config.Hint.Value;
                if (config.HasPattern)
                {
                    // substituted hint (nuget case)
                    hint = Regex.Replace(
                        input: relPath,
                        pattern: config.Pattern,
                        replacement: config.Hint
                        );
                }
            }

            // archive
            if (config.Type == LfxPointerType.Archive)
            {
                return(pointer.AddArchive(url.ToUrl(), hint));
            }

            // self extracting archive
            return(pointer.AddSelfExtractingArchive(url.ToUrl(), hint, config.Args));
        }