public bool TryGet(LfxHash hash, out LfxBlob blob) { // try local store blob = default(LfxBlob); if (m_store.TryGet(hash, out blob)) { return(true); } // no parent, no hope if (m_parentCache == null) { return(false); } // try parent store LfxBlob parentBlob; if (!m_parentCache.TryGet(hash, out parentBlob)) { return(false); } // promote to local store blob = m_store.Add(parentBlob); return(true); }
public static LfxPointer Create(Stream stream) { stream = new StreamCounter(stream); var hash = LfxHash.Compute(stream); var count = stream.Position; return(Create(hash, count)); }
private string GetPath(LfxHash hash) { return(Path.Combine( m_dir, hash.ToString().Substring(0, 2), hash.ToString().Substring(2, 2), hash )); }
public static LfxPointer Create(LfxHash hash, long count) { var pointer = new LfxPointer(); pointer.Add(VersionKey, Version1Uri.ToString()); pointer.Add(SizeKey, $"{count}"); pointer.Add(OidKey, $"{OidHashMethodSha256}:{hash}"); return(pointer); }
public bool TryGet(LfxHash hash, out LfxBlob blob) { blob = default(LfxBlob); var path = GetPath(hash); if (!File.Exists(path)) { return(false); } blob = new LfxBlob(this, hash, path); return(true); }
private LfxBlob Add(Stream stream, LfxHash hash) { // insert var path = GetPath(hash); if (!File.Exists(path)) { IODirectory.CreateDirectory(Path.GetDirectoryName(path)); using (var targetStream = File.OpenWrite(path)) stream.CopyTo(targetStream); } return(new LfxBlob(this, hash, path)); }
internal LfxBlob(LfxBlobStore store, LfxHash hash, string path) { m_store = store; m_hash = hash; m_file = path; }
public bool Promote(LfxHash hash) { LfxBlob blob; return(TryGet(hash, out blob)); }
public bool Equals(LfxHash other) => m_value != null && m_value == other.m_value;
public static LfxHash ComputeHash(this byte[] bytes, int count) => LfxHash.Compute(bytes, count);
public static LfxHash ComputeHash(this byte[] bytes) => LfxHash.Compute(bytes);
public static LfxHash ComputeHash(this Stream stream) => LfxHash.Compute(stream);
public static LfxHash ComputeHash(this string value) => LfxHash.Compute(value);
public bool Contains(LfxHash hash) { LfxBlob blob; return(TryGet(hash, out blob)); }
public IEnumerator <LfxBlob> GetEnumerator() { return(Files .Select(o => new LfxBlob(this, LfxHash.Parse(Path.GetFileName(o)), o)) .GetEnumerator()); }
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)); }