using System; using System.IO; using LibGit2Sharp.Core; namespace LibGit2Sharp { /// /// Stores the binary content of a tracked file. /// public class Blob : GitObject { private readonly ILazy lazySize; private readonly ILazy lazyIsBinary; /// /// Needed for mocking purposes. /// protected Blob() { } internal Blob(Repository repo, ObjectId id) : base(repo, id) { lazySize = GitObjectLazyGroup.Singleton(repo, id, Proxy.git_blob_rawsize); lazyIsBinary = GitObjectLazyGroup.Singleton(repo, id, Proxy.git_blob_is_binary); } /// /// Gets the size in bytes of the raw content of a blob. /// Please note that this would load entire blob content in the memory to compute the Size. /// In order to read blob size from header, Repository.ObjectMetadata.RetrieveObjectMetadata(Blob.Id).Size /// can be used. /// /// public virtual long Size { get { return lazySize.Value; } } /// /// Determine if the blob content is most certainly binary or not. /// public virtual bool IsBinary { get { return lazyIsBinary.Value; } } /// /// Gets the blob content in a . /// public virtual Stream GetContentStream() { return Proxy.git_blob_rawcontent_stream(repo.Handle, Id, Size); } /// /// Gets the blob content in a as it would be /// checked out to the working directory. /// Parameter controlling content filtering behavior /// public virtual Stream GetContentStream(FilteringOptions filteringOptions) { Ensure.ArgumentNotNull(filteringOptions, "filteringOptions"); return Proxy.git_blob_filtered_content_stream(repo.Handle, Id, filteringOptions.HintPath, false); } } }