diff --git a/base/libgit2/blob.jl b/base/libgit2/blob.jl index 0676deceddd85..6b706ecd64ff0 100644 --- a/base/libgit2/blob.jl +++ b/base/libgit2/blob.jl @@ -4,15 +4,28 @@ function Base.length(blob::GitBlob) return ccall((:git_blob_rawsize, :libgit2), Int64, (Ptr{Void},), blob.ptr) end +""" + rawcontent(blob::GitBlob) -> Vector{UInt8} + +Fetch the *raw* contents of the [`GitBlob`](@ref) `blob`. This is an +`Array` containing the contents of the blob, which may be binary or may be Unicode. +If you write to this `Array` the blob on disk will not be updated. +`rawcontent` will allow the user to load the raw binary data into +the output `Array` and will not check to ensure it is valid Unicode, so errors +may occur if the result is passed to functions which expect valid Unicode data. + +See also [`content`](@ref), which *will* throw an error if the content of the `blob` +is binary and not valid Unicode. +""" function rawcontent(blob::GitBlob) ptr = ccall((:git_blob_rawcontent, :libgit2), Ptr{UInt8}, (Ptr{Void},), blob.ptr) copy(unsafe_wrap(Array, ptr, (length(blob),), false)) end """ - content(blob::GitBlob) + content(blob::GitBlob) -> String -Fetch the contents of the `GitBlob` `blob`. If the `blob` contains +Fetch the contents of the [`GitBlob`](@ref) `blob`. If the `blob` contains binary data (which can be determined using [`isbinary`](@ref)), throw an error. Otherwise, return a `String` containing the contents of the `blob`. @@ -24,6 +37,8 @@ function content(blob::GitBlob) end """ + isbinary(blob::GitBlob) -> Bool + Use a heuristic to guess if a file is binary: searching for NULL bytes and looking for a reasonable ratio of printable to non-printable characters among the first 8000 bytes. @@ -37,7 +52,7 @@ end LibGit2.addblob!(repo::GitRepo, path::AbstractString) Reads the file at `path` and adds it to the object database of `repo` as a loose blob. -Returns the `GitHash` of the resulting blob. +Returns the [`GitHash`](@ref) of the resulting blob. # Example