Esempio n. 1
0
        public async Task <string> GetObjectAsync(string oid, ObjectType expectedType = ObjectType.Blob)
        {
            string[] split = oid.Split(2);
            string   obj   = await FileExtensions.ReadFileAsync($"{Dir}/objects/{split[0]}/{split[1]}", Encoding);

            var po = new ParsedObject(obj);

            if (po.Type != expectedType)
            {
                throw new ArgumentException($"Expected type {expectedType} but found {po.Type}");
            }
            return(po.Content);
        }
Esempio n. 2
0
        public async Task <string> HashAsync(string path, ObjectType type = ObjectType.Blob)
        {
            string content = await FileExtensions.ReadFileAsync(path, Encoding).ConfigureAwait(false);

            string filtered = Filter(content);
            string obj      = _objectFactory.Create(type, filtered).Value;

            string oid = Hash(Encoding.GetBytes(obj));

            string[] split = oid.Split(2);

            await FileExtensions.WriteFileAsync($"{Dir}/objects/{split[0]}/{split[1]}", obj);

            return(oid);
        }