Exemple #1
0
        private static Entry Read(RepositoryReader reader, string hash, string path)
        {
            using (var stream = File.OpenRead(path).DeflateForZlibData())
            {
                var(type, length) = ReadHeader(stream);
                switch (type)
                {
                case "commit":
                    return(CommitReader.Read(reader, hash, stream));

                case "tree":
                    return(TreeReader.Read(reader, hash, stream, length));

                case "blob":
                    return(new Blob(reader, hash, () =>
                    {
                        var s = File.OpenRead(path).DeflateForZlibData();
                        ReadHeader(s);
                        return s;
                    }));

                default:
                    throw new NotImplementedException();
                }
            }
        }
Exemple #2
0
        private static Entry ReadEntryStream(RepositoryReader reader, string hash, Stream stream, Stream entryStream, long offset, ObjectType type, long length, Func <Stream> streamProvider)
        {
            switch (type)
            {
            case ObjectType.Commit:
                return(CommitReader.Read(reader, hash, entryStream));

            case ObjectType.Tree:
                return(TreeReader.Read(reader, hash, entryStream, length));

            case ObjectType.Blob:
                return(BlobReader.Read(reader, hash, entryStream, streamProvider));

            case ObjectType.OfsDelta:
                var(undeltifiedData, undeltifiedLength, baseType) = OfsDeltaReader.Read(
                    stream, offset, length,
                    (off, len, pool) => ReadEntryData(reader, hash, stream, off, isNestedDelta: true),
                    isNestedDelta: false);
                using (var undeltifiedStream = new MemoryStream(undeltifiedData))
                {
                    return(ReadEntryStream(reader, hash, stream, undeltifiedStream, 0L, baseType, undeltifiedLength, streamProvider));
                }

            default:
                throw new NotImplementedException();
            }
        }