Method: Rugged::Blob.to_buffer

Defined in:
ext/rugged/rugged_blob.c

.to_buffer(*args) ⇒ Object


496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'ext/rugged/rugged_blob.c', line 496

static VALUE rb_git_blob_to_buffer(int argc, VALUE *argv, VALUE self)
{
	VALUE rb_repo, rb_sha1, rb_max_bytes;
	VALUE rb_ret;

	git_repository *repo = NULL;
	git_blob *blob = NULL;

	size_t size;
	const char *content;

	rb_scan_args(argc, argv, "21", &rb_repo, &rb_sha1, &rb_max_bytes);

	rugged_check_repo(rb_repo);
	Data_Get_Struct(rb_repo, git_repository, repo);

	blob = (git_blob *)rugged_object_get(repo, rb_sha1, GIT_OBJ_BLOB);

	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;
	}

	rb_ret = rb_ary_new();

	rb_ary_push(rb_ret, rb_str_new(content, size));
	rb_ary_push(rb_ret, INT2FIX(git_blob_rawsize(blob)));

	git_object_free((git_object*)blob);

	/* TODO: LOC */

	return rb_ret;
}