import nimgit2 import types, free, objects proc lookupBlob* (repo: GitRepository, id: GitObjectId): GitBlob = let error = git_blob_lookup(addr result, repo, id) if error != 0: free(result) raise newException(CatchableError, "Blob lookup failed: " & $error.getResultCode) proc copy* (blob: GitBlob): GitBlob = let error = git_blob_dup(addr result, blob) if error != 0: free(result) raise newException(CatchableError, "Cannot copy GitBlob: " & $error.getResultCode) proc type* (obj: GitBlob): GitObjectKind = cast[GitObject](obj).type proc owner* (blob: GitBlob): GitRepository = git_blob_owner(blob) proc id* (blob: GitBlob): GitObjectId = git_blob_id(blob) proc shortId* (blob: GitBlob): string = cast[GitObject](blob).shortId() proc size* (blob: GitBlob): int = cast[int](git_blob_rawsize(blob)) proc content* (blob: GitBlob): string = result = newString(blob.size) copyMem(result.cstring, git_blob_rawcontent(blob), blob.size) proc isBinary* (blob: GitBlob): bool = cast[bool](git_blob_is_binary(blob))