On this page:
git_  blob_  create_  frombuffer
git_  blob_  create_  fromdisk
git_  blob_  create_  fromstream
git_  blob_  create_  fromstream_  commit
git_  blob_  create_  fromworkdir
git_  blob_  dup
git_  blob_  filtered_  content
git_  blob_  free
git_  blob_  id
git_  blob_  is_  binary
git_  blob_  lookup
git_  blob_  lookup_  prefix
git_  blob_  owner
git_  blob_  rawcontent
git_  blob_  rawsize
8.12

3 Blob🔗ℹ

 (require libgit2/include/blob) package: libgit2

procedure

(git_blob_create_frombuffer id    
  repo    
  buffer    
  len)  integer?
  id : oid?
  repo : repository?
  buffer : (cpointer void)
  len : integer?
Write an in-memory buffer to the ODB as a blob

procedure

(git_blob_create_fromdisk id repo path)  integer?

  id : oid?
  repo : repository?
  path : string?
Read a file from the filesystem and write its content to the Object Database as a loose blob

procedure

(git_blob_create_fromstream repo hintpath)  writestream?

  repo : repository?
  hintpath : string?
Create a stream to write a new blob into the object db

This function may need to buffer the data on disk and will in general not be the right choice if you know the size of the data to write. If you have data in memory, use git_blob_create_frombuffer(). If you do not, but know the size of the contents (and don’t want/need to perform filtering), use git_odb_open_wstream().

Don’t close this stream yourself but pass it to git_blob_create_fromstream_commit() to commit the write to the object db and get the object id.

If the hintpath parameter is filled, it will be used to determine what git filters should be applied to the object before it is written to the object database.

procedure

(git_blob_create_fromstream_commit out    
  stream)  integer?
  out : oid?
  stream : writestream?
Close the stream and write the blob to the object db

The stream will be closed and freed.

procedure

(git_blob_create_fromworkdir id    
  repo    
  relative_path)  integer?
  id : oid?
  repo : repository?
  relative_path : string?
Read a file from the working folder of a repository and write it to the Object Database as a loose blob

procedure

(git_blob_dup source)  blob?

  source : blob?
Create an in-memory copy of a blob. The copy must be explicitly free’d or it will leak.

procedure

(git_blob_filtered_content out    
  blob    
  as_path    
  check_for_binary_data)  integer?
  out : buf?
  blob : blob?
  as_path : string?
  check_for_binary_data : boolean?
Get a buffer with the filtered content of a blob.

This applies filters as if the blob was being checked out to the working directory under the specified filename. This may apply CRLF filtering or other types of changes depending on the file attributes set for the blob and the content detected in it.

The output is written into a git_buf which the caller must free when done (via git_buf_free).

If no filters need to be applied, then the out buffer will just be populated with a pointer to the raw content of the blob. In that case, be careful to not free the blob until done with the buffer or copy it into memory you own.

procedure

(git_blob_free blob)  void?

  blob : blob?
Close an open blob

This is a wrapper around git_object_free()

IMPORTANT: It is necessary to call this method when you stop using a blob. Failure to do so will cause a memory leak.

procedure

(git_blob_id blob)  oid?

  blob : blob?
Get the id of a blob.

procedure

(git_blob_is_binary blob)  boolean?

  blob : blob?
Determine if the blob content is most certainly binary or not.

The heuristic used to guess if a file is binary is taken from core git: Searching for NUL bytes and looking for a reasonable ratio of printable to non-printable characters among the first 8000 bytes.

procedure

(git_blob_lookup repo id)  blob?

  repo : repository?
  id : oid?
Lookup a blob object from a repository.

procedure

(git_blob_lookup_prefix repo id len)  blob?

  repo : repository?
  id : oid?
  len : size_t
Lookup a blob object from a repository, given a prefix of its identifier (short id).

procedure

(git_blob_owner blob)  repository?

  blob : blob?
Get the repository that contains the blob.

procedure

(git_blob_rawcontent blob)  bytes?

  blob : blob?
Get a read-only buffer with the raw content of a blob.

A pointer to the raw content of a blob is returned; this pointer is owned internally by the object and shall not be free’d. The pointer may be invalidated at a later time.

procedure

(git_blob_rawsize blob)  git_off_t?

  blob : blob?
Get the size in bytes of the contents of a blob