Commit a19581a24bec8161b09eab50d721edc1c8f42be9

Stefan Sperling 2018-06-21T22:04:27

implement got_object_open_as_blob()

diff --git a/include/got_object.h b/include/got_object.h
index 60c0249..9268ff8 100644
--- a/include/got_object.h
+++ b/include/got_object.h
@@ -193,6 +193,9 @@ got_object_open_as_commit(struct got_commit_object **,
 const struct got_error *
 got_object_open_as_tree(struct got_tree_object **,
     struct got_repository *, struct got_object_id *);
+const struct got_error *
+got_object_open_as_blob(struct got_blob_object **,
+    struct got_repository *, struct got_object_id *, size_t);
 
 const struct got_error *
 got_object_open_by_path(struct got_object **, struct got_repository *,
diff --git a/lib/object.c b/lib/object.c
index 530f08f..3bf9f60 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -1320,6 +1320,28 @@ done:
 	return err;
 }
 
+const struct got_error *
+got_object_open_as_blob(struct got_blob_object **blob,
+    struct got_repository *repo, struct got_object_id *id,
+    size_t blocksize)
+{
+	const struct got_error *err;
+	struct got_object *obj;
+
+	err = got_object_open(&obj, repo, id);
+	if (err)
+		return err;
+	if (got_object_get_type(obj) != GOT_OBJ_TYPE_BLOB) {
+		err = got_error(GOT_ERR_OBJ_TYPE);
+		goto done;
+	}
+
+	err = got_object_blob_open(blob, repo, obj, blocksize);
+done:
+	got_object_close(obj);
+	return err;
+}
+
 void
 got_object_blob_close(struct got_blob_object *blob)
 {