Commit Diff


commit - c136f699978dbcb5baddbbbb3b8ffe593b8b2ff4
commit + 0d569390539da8c000749a958bde945d57274f50
blob - 19f043e1c43b4b21c3b19d764f34a7575df5b7a7
blob + 34c1b6df1b13b23dea3ca12f6a6cdaf82e3106f4
--- include/got_object.h
+++ include/got_object.h
@@ -291,6 +291,13 @@ const struct got_error *got_object_blob_read_block(siz
 void got_object_blob_rewind(struct got_blob_object *);
 
 /*
+ * Heuristic to check whether the blob contains binary data.  Rewinds
+ * the blob's data stream back after the header.
+ */
+const struct got_error *got_object_blob_is_binary(int *,
+    struct got_blob_object *);
+
+/*
  * Read the entire content of a blob and write it to the specified file.
  * Flush and rewind the file as well. Indicate the amount of bytes
  * written in the size_t output argument, and the number of lines in the
blob - 7bc7eb3dcdcec57157f35f8b6c676e1979ba2b76
blob + 4d1c1cdecf129d5464dd74b1c503a6164e6939b5
--- lib/object.c
+++ lib/object.c
@@ -402,6 +402,29 @@ got_object_blob_read_block(size_t *outlenp, struct got
 }
 
 const struct got_error *
+got_object_blob_is_binary(int *binary, struct got_blob_object *blob)
+{
+	const struct got_error *err;
+	size_t hdrlen, len;
+
+	*binary = 0;
+	hdrlen = got_object_blob_get_hdrlen(blob);
+
+	if (fseeko(blob->f, hdrlen, SEEK_SET) == -1)
+		return got_error_from_errno("fseeko");
+
+	err = got_object_blob_read_block(&len, blob);
+	if (err)
+		return err;
+
+	*binary = memchr(blob->read_buf, '\0', len) != NULL;
+
+	if (fseeko(blob->f, hdrlen, SEEK_SET) == -1)
+		return got_error_from_errno("fseeko");
+	return NULL;
+}
+
+const struct got_error *
 got_object_blob_dump_to_file(off_t *filesize, int *nlines,
     off_t **line_offsets, FILE *outfile, struct got_blob_object *blob)
 {