Blob


1 /*
2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #include <sys/stat.h>
18 #include <sys/queue.h>
20 #include <errno.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sha1.h>
25 #include <zlib.h>
26 #include <ctype.h>
27 #include <limits.h>
29 #include "got_error.h"
30 #include "got_object.h"
31 #include "got_repository.h"
33 #include "got_lib_sha1.h"
34 #include "got_lib_delta.h"
35 #include "got_lib_pack.h"
36 #include "got_lib_zbuf.h"
37 #include "got_lib_object.h"
39 #ifndef MIN
40 #define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
41 #endif
43 #ifndef nitems
44 #define nitems(_a) (sizeof(_a) / sizeof((_a)[0]))
45 #endif
47 #define GOT_OBJ_TAG_COMMIT "commit"
48 #define GOT_OBJ_TAG_TREE "tree"
49 #define GOT_OBJ_TAG_BLOB "blob"
51 #define GOT_COMMIT_TAG_TREE "tree "
52 #define GOT_COMMIT_TAG_PARENT "parent "
53 #define GOT_COMMIT_TAG_AUTHOR "author "
54 #define GOT_COMMIT_TAG_COMMITTER "committer "
56 const struct got_error *
57 got_object_id_str(char **outbuf, struct got_object_id *id)
58 {
59 static const size_t len = SHA1_DIGEST_STRING_LENGTH;
61 *outbuf = calloc(1, len);
62 if (*outbuf == NULL)
63 return got_error_from_errno();
65 if (got_sha1_digest_to_str(id->sha1, *outbuf, len) == NULL) {
66 free(*outbuf);
67 *outbuf = NULL;
68 return got_error(GOT_ERR_BAD_OBJ_ID_STR);
69 }
71 return NULL;
72 }
74 int
75 got_object_id_cmp(struct got_object_id *id1, struct got_object_id *id2)
76 {
77 return memcmp(id1->sha1, id2->sha1, SHA1_DIGEST_LENGTH);
78 }
80 struct got_object_id *
81 got_object_id_dup(struct got_object_id *id1)
82 {
83 struct got_object_id *id2;
85 id2 = malloc(sizeof(*id2));
86 if (id2 == NULL)
87 return NULL;
88 memcpy(id2, id1, sizeof(*id2));
89 return id2;
90 }
92 struct got_object_id *
93 got_object_get_id(struct got_object *obj)
94 {
95 return got_object_id_dup(&obj->id);
96 }
98 int
99 got_object_get_type(struct got_object *obj)
101 switch (obj->type) {
102 case GOT_OBJ_TYPE_COMMIT:
103 case GOT_OBJ_TYPE_TREE:
104 case GOT_OBJ_TYPE_BLOB:
105 case GOT_OBJ_TYPE_TAG:
106 return obj->type;
107 default:
108 abort();
109 break;
112 /* not reached */
113 return 0;
116 static const struct got_error *
117 parse_object_header(struct got_object **obj, char *buf, size_t len)
119 const char *obj_tags[] = {
120 GOT_OBJ_TAG_COMMIT,
121 GOT_OBJ_TAG_TREE,
122 GOT_OBJ_TAG_BLOB
123 };
124 const int obj_types[] = {
125 GOT_OBJ_TYPE_COMMIT,
126 GOT_OBJ_TYPE_TREE,
127 GOT_OBJ_TYPE_BLOB,
128 };
129 int type = 0;
130 size_t size = 0, hdrlen = 0;
131 int i;
132 char *p = strchr(buf, '\0');
134 if (p == NULL)
135 return got_error(GOT_ERR_BAD_OBJ_HDR);
137 hdrlen = strlen(buf) + 1 /* '\0' */;
139 for (i = 0; i < nitems(obj_tags); i++) {
140 const char *tag = obj_tags[i];
141 size_t tlen = strlen(tag);
142 const char *errstr;
144 if (strncmp(buf, tag, tlen) != 0)
145 continue;
147 type = obj_types[i];
148 if (len <= tlen)
149 return got_error(GOT_ERR_BAD_OBJ_HDR);
150 size = strtonum(buf + tlen, 0, LONG_MAX, &errstr);
151 if (errstr != NULL)
152 return got_error(GOT_ERR_BAD_OBJ_HDR);
153 break;
156 if (type == 0)
157 return got_error(GOT_ERR_BAD_OBJ_HDR);
159 *obj = calloc(1, sizeof(**obj));
160 if (*obj == NULL)
161 return got_error_from_errno();
162 (*obj)->type = type;
163 (*obj)->hdrlen = hdrlen;
164 (*obj)->size = size;
165 return NULL;
168 static const struct got_error *
169 read_object_header(struct got_object **obj, struct got_repository *repo,
170 FILE *f)
172 const struct got_error *err;
173 struct got_zstream_buf zb;
174 char *buf;
175 const size_t zbsize = 64;
176 size_t outlen, totlen;
177 int i;
179 buf = calloc(zbsize, sizeof(char));
180 if (buf == NULL)
181 return got_error_from_errno();
183 err = got_inflate_init(&zb, NULL, zbsize);
184 if (err)
185 return err;
187 i = 0;
188 totlen = 0;
189 do {
190 err = got_inflate_read(&zb, f, &outlen);
191 if (err)
192 goto done;
193 if (strchr(zb.outbuf, '\0') == NULL) {
194 buf = recallocarray(buf, 1 + i, 2 + i, zbsize);
195 if (buf == NULL) {
196 err = got_error_from_errno();
197 goto done;
200 memcpy(buf + totlen, zb.outbuf, outlen);
201 totlen += outlen;
202 i++;
203 } while (strchr(zb.outbuf, '\0') == NULL);
205 err = parse_object_header(obj, buf, totlen);
206 done:
207 got_inflate_end(&zb);
208 return err;
211 static const struct got_error *
212 object_path(char **path, struct got_object_id *id, struct got_repository *repo)
214 const struct got_error *err = NULL;
215 char *hex;
216 char *path_objects = got_repo_get_path_objects(repo);
218 if (path_objects == NULL)
219 return got_error_from_errno();
221 err = got_object_id_str(&hex, id);
222 if (err)
223 return err;
225 if (asprintf(path, "%s/%.2x/%s", path_objects,
226 id->sha1[0], hex + 2) == -1)
227 err = got_error_from_errno();
229 free(hex);
230 free(path_objects);
231 return err;
234 static const struct got_error *
235 open_loose_object(FILE **f, struct got_object *obj, struct got_repository *repo)
237 const struct got_error *err = NULL;
238 char *path;
240 err = object_path(&path, &obj->id, repo);
241 if (err)
242 return err;
243 *f = fopen(path, "rb");
244 if (*f == NULL) {
245 err = got_error_from_errno();
246 goto done;
248 done:
249 free(path);
250 return err;
253 const struct got_error *
254 got_object_open(struct got_object **obj, struct got_repository *repo,
255 struct got_object_id *id)
257 const struct got_error *err = NULL;
258 char *path;
259 FILE *f;
261 err = object_path(&path, id, repo);
262 if (err)
263 return err;
265 f = fopen(path, "rb");
266 if (f == NULL) {
267 if (errno != ENOENT) {
268 err = got_error_from_errno();
269 goto done;
271 err = got_packfile_open_object(obj, id, repo);
272 if (err)
273 goto done;
274 if (*obj == NULL)
275 err = got_error(GOT_ERR_NO_OBJ);
276 } else {
277 err = read_object_header(obj, repo, f);
278 if (err)
279 goto done;
280 memcpy((*obj)->id.sha1, id->sha1, SHA1_DIGEST_LENGTH);
282 done:
283 free(path);
284 if (f)
285 fclose(f);
286 return err;
290 const struct got_error *
291 got_object_open_by_id_str(struct got_object **obj, struct got_repository *repo,
292 const char *id_str)
294 struct got_object_id id;
296 if (!got_parse_sha1_digest(id.sha1, id_str))
297 return got_error(GOT_ERR_BAD_OBJ_ID_STR);
299 return got_object_open(obj, repo, &id);
302 void
303 got_object_close(struct got_object *obj)
305 if (obj->flags & GOT_OBJ_FLAG_DELTIFIED) {
306 struct got_delta *delta;
307 while (!SIMPLEQ_EMPTY(&obj->deltas.entries)) {
308 delta = SIMPLEQ_FIRST(&obj->deltas.entries);
309 SIMPLEQ_REMOVE_HEAD(&obj->deltas.entries, entry);
310 got_delta_close(delta);
313 if (obj->flags & GOT_OBJ_FLAG_PACKED)
314 free(obj->path_packfile);
315 free(obj);
318 static const struct got_error *
319 parse_commit_object(struct got_commit_object **commit, char *buf, size_t len)
321 const struct got_error *err = NULL;
322 char *s = buf;
323 size_t tlen;
324 ssize_t remain = (ssize_t)len;
326 *commit = calloc(1, sizeof(**commit));
327 if (*commit == NULL)
328 return got_error_from_errno();
329 (*commit)->tree_id = calloc(1, sizeof(*(*commit)->tree_id));
330 if ((*commit)->tree_id == NULL) {
331 err = got_error_from_errno();
332 free(*commit);
333 *commit = NULL;
334 return err;
337 SIMPLEQ_INIT(&(*commit)->parent_ids);
339 tlen = strlen(GOT_COMMIT_TAG_TREE);
340 if (strncmp(s, GOT_COMMIT_TAG_TREE, tlen) == 0) {
341 remain -= tlen;
342 if (remain < SHA1_DIGEST_STRING_LENGTH) {
343 err = got_error(GOT_ERR_BAD_OBJ_DATA);
344 goto done;
346 s += tlen;
347 if (!got_parse_sha1_digest((*commit)->tree_id->sha1, s)) {
348 err = got_error(GOT_ERR_BAD_OBJ_DATA);
349 goto done;
351 remain -= SHA1_DIGEST_STRING_LENGTH;
352 s += SHA1_DIGEST_STRING_LENGTH;
353 } else {
354 err = got_error(GOT_ERR_BAD_OBJ_DATA);
355 goto done;
358 tlen = strlen(GOT_COMMIT_TAG_PARENT);
359 while (strncmp(s, GOT_COMMIT_TAG_PARENT, tlen) == 0) {
360 struct got_parent_id *pid;
362 remain -= tlen;
363 if (remain < SHA1_DIGEST_STRING_LENGTH) {
364 err = got_error(GOT_ERR_BAD_OBJ_DATA);
365 goto done;
368 pid = calloc(1, sizeof(*pid));
369 if (pid == NULL) {
370 err = got_error_from_errno();
371 goto done;
373 pid->id = calloc(1, sizeof(*pid->id));
374 if (pid->id == NULL) {
375 err = got_error_from_errno();
376 free(pid);
377 goto done;
379 s += tlen;
380 if (!got_parse_sha1_digest(pid->id->sha1, s)) {
381 err = got_error(GOT_ERR_BAD_OBJ_DATA);
382 free(pid->id);
383 free(pid);
384 goto done;
386 SIMPLEQ_INSERT_TAIL(&(*commit)->parent_ids, pid, entry);
387 (*commit)->nparents++;
389 remain -= SHA1_DIGEST_STRING_LENGTH;
390 s += SHA1_DIGEST_STRING_LENGTH;
393 tlen = strlen(GOT_COMMIT_TAG_AUTHOR);
394 if (strncmp(s, GOT_COMMIT_TAG_AUTHOR, tlen) == 0) {
395 char *p;
397 remain -= tlen;
398 if (remain <= 0) {
399 err = got_error(GOT_ERR_BAD_OBJ_DATA);
400 goto done;
402 s += tlen;
403 p = strchr(s, '\n');
404 if (p == NULL) {
405 err = got_error(GOT_ERR_BAD_OBJ_DATA);
406 goto done;
408 *p = '\0';
409 (*commit)->author = strdup(s);
410 if ((*commit)->author == NULL) {
411 err = got_error_from_errno();
412 goto done;
414 s += strlen((*commit)->author) + 1;
415 remain -= strlen((*commit)->author) + 1;
418 tlen = strlen(GOT_COMMIT_TAG_COMMITTER);
419 if (strncmp(s, GOT_COMMIT_TAG_COMMITTER, tlen) == 0) {
420 char *p;
422 remain -= tlen;
423 if (remain <= 0) {
424 err = got_error(GOT_ERR_BAD_OBJ_DATA);
425 goto done;
427 s += tlen;
428 p = strchr(s, '\n');
429 if (p == NULL) {
430 err = got_error(GOT_ERR_BAD_OBJ_DATA);
431 goto done;
433 *p = '\0';
434 (*commit)->committer = strdup(s);
435 if ((*commit)->committer == NULL) {
436 err = got_error_from_errno();
437 goto done;
439 s += strlen((*commit)->committer) + 1;
440 remain -= strlen((*commit)->committer) + 1;
443 (*commit)->logmsg = strndup(s, remain);
444 if ((*commit)->logmsg == NULL) {
445 err = got_error_from_errno();
446 goto done;
448 done:
449 if (err) {
450 got_object_commit_close(*commit);
451 *commit = NULL;
453 return err;
456 static void
457 tree_entry_close(struct got_tree_entry *te)
459 free(te->id);
460 free(te->name);
461 free(te);
464 static const struct got_error *
465 parse_tree_entry(struct got_tree_entry **te, size_t *elen, char *buf,
466 size_t maxlen)
468 char *p = buf, *space;
469 const struct got_error *err = NULL;
471 *te = calloc(1, sizeof(**te));
472 if (*te == NULL)
473 return got_error_from_errno();
475 (*te)->id = calloc(1, sizeof(*(*te)->id));
476 if ((*te)->id == NULL) {
477 err = got_error_from_errno();
478 free(*te);
479 *te = NULL;
480 return err;
483 *elen = strlen(buf) + 1;
484 if (*elen > maxlen) {
485 free(*te);
486 *te = NULL;
487 return got_error(GOT_ERR_BAD_OBJ_DATA);
490 space = strchr(buf, ' ');
491 if (space == NULL) {
492 err = got_error(GOT_ERR_BAD_OBJ_DATA);
493 free(*te);
494 *te = NULL;
495 return err;
497 while (*p != ' ') {
498 if (*p < '0' && *p > '7') {
499 err = got_error(GOT_ERR_BAD_OBJ_DATA);
500 goto done;
502 (*te)->mode <<= 3;
503 (*te)->mode |= *p - '0';
504 p++;
507 (*te)->name = strdup(space + 1);
508 if (*elen > maxlen || maxlen - *elen < SHA1_DIGEST_LENGTH) {
509 err = got_error(GOT_ERR_BAD_OBJ_DATA);
510 goto done;
512 buf += strlen(buf) + 1;
513 memcpy((*te)->id->sha1, buf, SHA1_DIGEST_LENGTH);
514 *elen += SHA1_DIGEST_LENGTH;
515 done:
516 if (err) {
517 tree_entry_close(*te);
518 *te = NULL;
520 return err;
523 static const struct got_error *
524 parse_tree_object(struct got_tree_object **tree, struct got_repository *repo,
525 uint8_t *buf, size_t len)
527 const struct got_error *err;
528 size_t remain = len;
530 *tree = calloc(1, sizeof(**tree));
531 if (*tree == NULL)
532 return got_error_from_errno();
534 SIMPLEQ_INIT(&(*tree)->entries);
536 while (remain > 0) {
537 struct got_tree_entry *te;
538 size_t elen;
540 err = parse_tree_entry(&te, &elen, buf, remain);
541 if (err)
542 return err;
543 (*tree)->nentries++;
544 SIMPLEQ_INSERT_TAIL(&(*tree)->entries, te, entry);
545 buf += elen;
546 remain -= elen;
549 if (remain != 0) {
550 got_object_tree_close(*tree);
551 return got_error(GOT_ERR_BAD_OBJ_DATA);
554 return NULL;
557 static const struct got_error *
558 read_to_mem(uint8_t **outbuf, size_t *outlen, FILE *f)
560 const struct got_error *err = NULL;
561 static const size_t blocksize = 512;
562 size_t n, total, remain;
563 uint8_t *buf;
565 *outbuf = NULL;
566 *outlen = 0;
568 buf = calloc(1, blocksize);
569 if (buf == NULL)
570 return got_error_from_errno();
572 remain = blocksize;
573 total = 0;
574 while (1) {
575 if (remain == 0) {
576 uint8_t *newbuf;
577 newbuf = reallocarray(buf, 1, total + blocksize);
578 if (newbuf == NULL) {
579 err = got_error_from_errno();
580 goto done;
582 buf = newbuf;
583 remain += blocksize;
585 n = fread(buf + total, 1, remain, f);
586 if (n == 0) {
587 if (ferror(f)) {
588 err = got_ferror(f, GOT_ERR_IO);
589 goto done;
591 break; /* EOF */
593 remain -= n;
594 total += n;
595 };
597 done:
598 if (err == NULL) {
599 *outbuf = buf;
600 *outlen = total;
601 } else
602 free(buf);
603 return err;
606 static const struct got_error *
607 read_commit_object(struct got_commit_object **commit,
608 struct got_repository *repo, struct got_object *obj, FILE *f)
610 const struct got_error *err = NULL;
611 size_t len;
612 uint8_t *p;
614 if (obj->flags & GOT_OBJ_FLAG_PACKED)
615 err = read_to_mem(&p, &len, f);
616 else
617 err = got_inflate_to_mem(&p, &len, f);
618 if (err)
619 return err;
621 if (len < obj->hdrlen + obj->size) {
622 err = got_error(GOT_ERR_BAD_OBJ_DATA);
623 goto done;
626 /* Skip object header. */
627 len -= obj->hdrlen;
628 err = parse_commit_object(commit, p + obj->hdrlen, len);
629 free(p);
630 done:
631 return err;
634 const struct got_error *
635 got_object_commit_open(struct got_commit_object **commit,
636 struct got_repository *repo, struct got_object *obj)
638 const struct got_error *err = NULL;
640 if (obj->type != GOT_OBJ_TYPE_COMMIT)
641 return got_error(GOT_ERR_OBJ_TYPE);
643 if (obj->flags & GOT_OBJ_FLAG_PACKED) {
644 uint8_t *buf;
645 size_t len;
646 err = got_packfile_extract_object_to_mem(&buf, &len, obj, repo);
647 if (err)
648 return err;
649 obj->size = len;
650 err = parse_commit_object(commit, buf, len);
651 free(buf);
652 } else {
653 FILE *f;
654 err = open_loose_object(&f, obj, repo);
655 if (err)
656 return err;
657 err = read_commit_object(commit, repo, obj, f);
658 fclose(f);
660 return err;
663 void
664 got_object_commit_close(struct got_commit_object *commit)
666 struct got_parent_id *pid;
668 while (!SIMPLEQ_EMPTY(&commit->parent_ids)) {
669 pid = SIMPLEQ_FIRST(&commit->parent_ids);
670 SIMPLEQ_REMOVE_HEAD(&commit->parent_ids, entry);
671 free(pid->id);
672 free(pid);
675 free(commit->tree_id);
676 free(commit->author);
677 free(commit->committer);
678 free(commit->logmsg);
679 free(commit);
682 static const struct got_error *
683 read_tree_object(struct got_tree_object **tree,
684 struct got_repository *repo, struct got_object *obj, FILE *f)
686 const struct got_error *err = NULL;
687 size_t len;
688 uint8_t *p;
690 if (obj->flags & GOT_OBJ_FLAG_PACKED)
691 err = read_to_mem(&p, &len, f);
692 else
693 err = got_inflate_to_mem(&p, &len, f);
694 if (err)
695 return err;
697 if (len < obj->hdrlen + obj->size) {
698 err = got_error(GOT_ERR_BAD_OBJ_DATA);
699 goto done;
702 /* Skip object header. */
703 len -= obj->hdrlen;
704 err = parse_tree_object(tree, repo, p + obj->hdrlen, len);
705 free(p);
706 done:
707 return err;
710 const struct got_error *
711 got_object_tree_open(struct got_tree_object **tree,
712 struct got_repository *repo, struct got_object *obj)
714 const struct got_error *err = NULL;
716 if (obj->type != GOT_OBJ_TYPE_TREE)
717 return got_error(GOT_ERR_OBJ_TYPE);
719 if (obj->flags & GOT_OBJ_FLAG_PACKED) {
720 uint8_t *buf;
721 size_t len;
722 err = got_packfile_extract_object_to_mem(&buf, &len, obj, repo);
723 if (err)
724 return err;
725 obj->size = len;
726 err = parse_tree_object(tree, repo, buf, len);
727 free(buf);
728 } else {
729 FILE *f;
730 err = open_loose_object(&f, obj, repo);
731 if (err)
732 return err;
733 err = read_tree_object(tree, repo, obj, f);
734 fclose(f);
736 return err;
739 void
740 got_object_tree_close(struct got_tree_object *tree)
742 struct got_tree_entry *te;
744 while (!SIMPLEQ_EMPTY(&tree->entries)) {
745 te = SIMPLEQ_FIRST(&tree->entries);
746 SIMPLEQ_REMOVE_HEAD(&tree->entries, entry);
747 tree_entry_close(te);
750 free(tree);
753 const struct got_error *
754 got_object_blob_open(struct got_blob_object **blob,
755 struct got_repository *repo, struct got_object *obj, size_t blocksize)
757 const struct got_error *err = NULL;
759 if (obj->type != GOT_OBJ_TYPE_BLOB)
760 return got_error(GOT_ERR_OBJ_TYPE);
762 if (blocksize < obj->hdrlen)
763 return got_error(GOT_ERR_NO_SPACE);
765 *blob = calloc(1, sizeof(**blob));
766 if (*blob == NULL)
767 return got_error_from_errno();
769 if (obj->flags & GOT_OBJ_FLAG_PACKED) {
770 (*blob)->read_buf = calloc(1, blocksize);
771 if ((*blob)->read_buf == NULL) {
772 err = got_error_from_errno();
773 free(*blob);
774 *blob = NULL;
775 return err;
777 err = got_packfile_extract_object(&((*blob)->f), obj, repo);
778 if (err) {
779 free((*blob)->read_buf);
780 free(*blob);
781 *blob = NULL;
782 return err;
784 } else {
785 err = open_loose_object(&((*blob)->f), obj, repo);
786 if (err) {
787 free(*blob);
788 *blob = NULL;
789 return err;
792 err = got_inflate_init(&(*blob)->zb, NULL, blocksize);
793 if (err != NULL) {
794 fclose((*blob)->f);
795 free(*blob);
796 *blob = NULL;
797 return err;
800 (*blob)->read_buf = (*blob)->zb.outbuf;
801 (*blob)->flags |= GOT_BLOB_F_COMPRESSED;
804 (*blob)->hdrlen = obj->hdrlen;
805 (*blob)->blocksize = blocksize;
806 memcpy(&(*blob)->id.sha1, obj->id.sha1, SHA1_DIGEST_LENGTH);
808 return err;
811 void
812 got_object_blob_close(struct got_blob_object *blob)
814 if (blob->flags & GOT_BLOB_F_COMPRESSED)
815 got_inflate_end(&blob->zb);
816 else
817 free(blob->read_buf);
818 fclose(blob->f);
819 free(blob);
822 char *
823 got_object_blob_id_str(struct got_blob_object *blob, char *buf, size_t size)
825 return got_sha1_digest_to_str(blob->id.sha1, buf, size);
828 size_t
829 got_object_blob_get_hdrlen(struct got_blob_object *blob)
831 return blob->hdrlen;
834 const uint8_t *
835 got_object_blob_get_read_buf(struct got_blob_object *blob)
837 return blob->read_buf;
840 const struct got_error *
841 got_object_blob_read_block(size_t *outlenp, struct got_blob_object *blob)
843 size_t n;
845 if (blob->flags & GOT_BLOB_F_COMPRESSED)
846 return got_inflate_read(&blob->zb, blob->f, outlenp);
848 n = fread(blob->read_buf, 1, blob->blocksize, blob->f);
849 if (n == 0 && ferror(blob->f))
850 return got_ferror(blob->f, GOT_ERR_IO);
851 *outlenp = n;
852 return NULL;