Method: Rugged::Blob#content
- Defined in:
- ext/rugged/rugged_blob.c
#content(max_bytes = -1) ⇒ String
Return up to max_bytes
from the contents of a blob as bytes String
. If max_bytes
is less than 0, the full string is returned.
This string is tagged with the ASCII-8BIT encoding: the bytes are returned as-is, since Git is encoding agnostic.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'ext/rugged/rugged_blob.c', line 83
static VALUE rb_git_blob_content_GET(int argc, VALUE *argv, VALUE self)
{
git_blob *blob;
size_t size;
const char *content;
VALUE rb_max_bytes;
TypedData_Get_Struct(self, git_blob, &rugged_object_type, blob);
rb_scan_args(argc, argv, "01", &rb_max_bytes);
content = git_blob_rawcontent(blob);
size = git_blob_rawsize(blob);
if (!NIL_P(rb_max_bytes)) {
int maxbytes;
Check_Type(rb_max_bytes, T_FIXNUM);
maxbytes = FIX2INT(rb_max_bytes);
if (maxbytes >= 0 && (size_t)maxbytes < size)
size = (size_t)maxbytes;
}
/*
* since we don't really ever know the encoding of a blob
* lets default to the binary encoding (ascii-8bit)
*/
return rb_str_new(content, size);
}
|