Skip to content

Commit 937d94e

Browse files
committed
Add blob samples
1 parent 4d15983 commit 937d94e

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

docs/guides/101-samples/index.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,57 @@ int error = git_tag_peel(&dereferenced_target, tag);
749749
)
750750

751751

752+
<h2 id="blobs">Blobs</h2>
753+
754+
<h3 id="blobs_lookups">Lookups</h3>
755+
756+
```c
757+
git_blob *blob = NULL;
758+
int error = git_blob_lookup(&blob, repo, &oid);
759+
```
760+
761+
(
762+
[`git_blob_lookup`](http://libgit2.github.com/libgit2/#HEAD/group/blob/git_blob_lookup)
763+
)
764+
765+
<h3 id="blobs_content">Content</h3>
766+
767+
```c
768+
git_off_t rawsize = git_blob_rawsize(blob);
769+
const void *rawcontent = git_blob_rawcontent(blob);
770+
771+
git_buf filtered_content = GIT_BUF_INIT;
772+
int error = git_blob_filtered_content(
773+
&filtered_content, /* output buffer */
774+
blob, /* blob */
775+
"README.md", /* path (for attribute-based filtering) */
776+
true); /* check if binary? */
777+
```
778+
779+
(
780+
[`git_blob_rawsize`](http://libgit2.github.com/libgit2/#HEAD/group/blob/git_blob_rawsize),
781+
[`git_blob_rawcontent`](http://libgit2.github.com/libgit2/#HEAD/group/blob/git_blob_rawcontent),
782+
[`git_blob_filtered_content`](http://libgit2.github.com/libgit2/#HEAD/group/blob/git_blob_filtered_content)
783+
)
784+
785+
<h3 id="blobs_create">Create</h3>
786+
787+
```c
788+
git_oid oid = {{0}};
789+
int error = git_blob_create_fromworkdir(&oid, repo, "README.md");
790+
error = git_blob_create_fromdisk(&oid, repo, "/etc/hosts");
791+
792+
const char str[] = "# Hello there!";
793+
error = git_blob_create_frombuffer(&oid, repo, str, strlen(str));
794+
```
795+
796+
(
797+
[`git_blob_create_fromworkdir`](http://libgit2.github.com/libgit2/#HEAD/group/blob/git_blob_create_fromworkdir),
798+
[`git_blob_create_fromdisk`](http://libgit2.github.com/libgit2/#HEAD/group/blob/git_blob_create_fromdisk),
799+
[`git_blob_create_frombuffer`](http://libgit2.github.com/libgit2/#HEAD/group/blob/git_blob_create_frombuffer)
800+
)
801+
802+
752803
<h2 id="trees">Trees</h2>
753804
754805
<h3 id="trees_lookups">Lookups</h3>

0 commit comments

Comments
 (0)