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_sha1_priv.h"
34 #include "got_delta_priv.h"
35 #include "got_pack_priv.h"
36 #include "got_zb_priv.h"
37 #include "got_object_priv.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(GOT_ERR_NO_MEM);
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 int
81 got_object_get_type(struct got_object *obj)
82 {
83 switch (obj->type) {
84 case GOT_OBJ_TYPE_COMMIT:
85 case GOT_OBJ_TYPE_TREE:
86 case GOT_OBJ_TYPE_BLOB:
87 case GOT_OBJ_TYPE_TAG:
88 return obj->type;
89 default:
90 abort();
91 break;
92 }
94 /* not reached */
95 return 0;
96 }
98 static const struct got_error *
99 parse_object_header(struct got_object **obj, char *buf, size_t len)
101 const char *obj_tags[] = {
102 GOT_OBJ_TAG_COMMIT,
103 GOT_OBJ_TAG_TREE,
104 GOT_OBJ_TAG_BLOB
105 };
106 const int obj_types[] = {
107 GOT_OBJ_TYPE_COMMIT,
108 GOT_OBJ_TYPE_TREE,
109 GOT_OBJ_TYPE_BLOB,
110 };
111 int type = 0;
112 size_t size = 0, hdrlen = 0;
113 int i;
114 char *p = strchr(buf, '\0');
116 if (p == NULL)
117 return got_error(GOT_ERR_BAD_OBJ_HDR);
119 hdrlen = strlen(buf) + 1 /* '\0' */;
121 for (i = 0; i < nitems(obj_tags); i++) {
122 const char *tag = obj_tags[i];
123 size_t tlen = strlen(tag);
124 const char *errstr;
126 if (strncmp(buf, tag, tlen) != 0)
127 continue;
129 type = obj_types[i];
130 if (len <= tlen)
131 return got_error(GOT_ERR_BAD_OBJ_HDR);
132 size = strtonum(buf + tlen, 0, LONG_MAX, &errstr);
133 if (errstr != NULL)
134 return got_error(GOT_ERR_BAD_OBJ_HDR);
135 break;
138 if (type == 0)
139 return got_error(GOT_ERR_BAD_OBJ_HDR);
141 *obj = calloc(1, sizeof(**obj));
142 if (*obj == NULL)
143 return got_error(GOT_ERR_NO_MEM);
144 (*obj)->type = type;
145 (*obj)->hdrlen = hdrlen;
146 (*obj)->size = size;
147 return NULL;
150 static const struct got_error *
151 read_object_header(struct got_object **obj, struct got_repository *repo,
152 FILE *f)
154 const struct got_error *err;
155 struct got_zstream_buf zb;
156 char *buf;
157 size_t len;
158 const size_t zbsize = 64;
159 size_t outlen, totlen;
160 int i, ret;
162 buf = calloc(zbsize, sizeof(char));
163 if (buf == NULL)
164 return got_error(GOT_ERR_NO_MEM);
166 err = got_inflate_init(&zb, zbsize);
167 if (err)
168 return err;
170 i = 0;
171 totlen = 0;
172 do {
173 err = got_inflate_read(&zb, f, &outlen);
174 if (err)
175 goto done;
176 if (strchr(zb.outbuf, '\0') == NULL) {
177 buf = recallocarray(buf, 1 + i, 2 + i, zbsize);
178 if (buf == NULL) {
179 err = got_error(GOT_ERR_NO_MEM);
180 goto done;
183 memcpy(buf + totlen, zb.outbuf, outlen);
184 totlen += outlen;
185 i++;
186 } while (strchr(zb.outbuf, '\0') == NULL);
188 err = parse_object_header(obj, buf, totlen);
189 done:
190 got_inflate_end(&zb);
191 return err;
194 static const struct got_error *
195 object_path(char **path, struct got_object_id *id, struct got_repository *repo)
197 const struct got_error *err = NULL;
198 char *hex;
199 char *path_objects = got_repo_get_path_objects(repo);
201 if (path_objects == NULL)
202 return got_error(GOT_ERR_NO_MEM);
204 err = got_object_id_str(&hex, id);
205 if (err)
206 return err;
208 if (asprintf(path, "%s/%.2x/%s", path_objects,
209 id->sha1[0], hex + 2) == -1)
210 err = got_error(GOT_ERR_NO_MEM);
212 free(hex);
213 free(path_objects);
214 return err;
217 static const struct got_error *
218 open_loose_object(FILE **f, struct got_object *obj, struct got_repository *repo)
220 const struct got_error *err = NULL;
221 char *path;
223 err = object_path(&path, &obj->id, repo);
224 if (err)
225 return err;
226 *f = fopen(path, "rb");
227 if (*f == NULL) {
228 err = got_error_from_errno();
229 goto done;
231 done:
232 free(path);
233 return err;
236 const struct got_error *
237 got_object_open(struct got_object **obj, struct got_repository *repo,
238 struct got_object_id *id)
240 const struct got_error *err = NULL;
241 char *path;
242 FILE *f;
244 err = object_path(&path, id, repo);
245 if (err)
246 return err;
248 f = fopen(path, "rb");
249 if (f == NULL) {
250 if (errno != ENOENT) {
251 err = got_error_from_errno();
252 goto done;
254 err = got_packfile_open_object(obj, id, repo);
255 if (err)
256 goto done;
257 if (*obj == NULL)
258 err = got_error(GOT_ERR_NO_OBJ);
259 } else {
260 err = read_object_header(obj, repo, f);
261 if (err)
262 goto done;
263 memcpy((*obj)->id.sha1, id->sha1, SHA1_DIGEST_LENGTH);
265 done:
266 free(path);
267 if (err && f)
268 fclose(f);
269 return err;
273 const struct got_error *
274 got_object_open_by_id_str(struct got_object **obj, struct got_repository *repo,
275 const char *id_str)
277 struct got_object_id id;
279 if (!got_parse_sha1_digest(id.sha1, id_str))
280 return got_error(GOT_ERR_BAD_OBJ_ID_STR);
282 return got_object_open(obj, repo, &id);
285 void
286 got_object_close(struct got_object *obj)
288 if (obj->flags & GOT_OBJ_FLAG_DELTIFIED) {
289 struct got_delta *delta;
290 while (!SIMPLEQ_EMPTY(&obj->deltas.entries)) {
291 delta = SIMPLEQ_FIRST(&obj->deltas.entries);
292 SIMPLEQ_REMOVE_HEAD(&obj->deltas.entries, entry);
293 got_delta_close(delta);
296 if (obj->flags & GOT_OBJ_FLAG_PACKED)
297 free(obj->path_packfile);
298 free(obj);
301 static int
302 commit_object_valid(struct got_commit_object *commit)
304 int i;
305 int n;
307 if (commit == NULL)
308 return 0;
310 n = 0;
311 for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
312 if (commit->tree_id->sha1[i] == 0)
313 n++;
315 if (n == SHA1_DIGEST_LENGTH)
316 return 0;
318 return 1;
321 static const struct got_error *
322 parse_commit_object(struct got_commit_object **commit, char *buf, size_t len)
324 const struct got_error *err = NULL;
325 char *s = buf;
326 size_t tlen;
327 ssize_t remain = (ssize_t)len;
329 *commit = calloc(1, sizeof(**commit));
330 if (*commit == NULL)
331 return got_error(GOT_ERR_NO_MEM);
332 (*commit)->tree_id = calloc(1, sizeof(*(*commit)->tree_id));
333 if ((*commit)->tree_id == NULL) {
334 free(*commit);
335 *commit = NULL;
336 return got_error(GOT_ERR_NO_MEM);
339 SIMPLEQ_INIT(&(*commit)->parent_ids);
341 tlen = strlen(GOT_COMMIT_TAG_TREE);
342 if (strncmp(s, GOT_COMMIT_TAG_TREE, tlen) == 0) {
343 remain -= tlen;
344 if (remain < SHA1_DIGEST_STRING_LENGTH) {
345 err = got_error(GOT_ERR_BAD_OBJ_DATA);
346 goto done;
348 s += tlen;
349 if (!got_parse_sha1_digest((*commit)->tree_id->sha1, s)) {
350 err = got_error(GOT_ERR_BAD_OBJ_DATA);
351 goto done;
353 remain -= SHA1_DIGEST_STRING_LENGTH;
354 s += SHA1_DIGEST_STRING_LENGTH;
355 } else {
356 err = got_error(GOT_ERR_BAD_OBJ_DATA);
357 goto done;
360 tlen = strlen(GOT_COMMIT_TAG_PARENT);
361 while (strncmp(s, GOT_COMMIT_TAG_PARENT, tlen) == 0) {
362 struct got_parent_id *pid;
364 remain -= tlen;
365 if (remain < SHA1_DIGEST_STRING_LENGTH) {
366 err = got_error(GOT_ERR_BAD_OBJ_DATA);
367 goto done;
370 pid = calloc(1, sizeof(*pid));
371 if (pid == NULL) {
372 err = got_error(GOT_ERR_NO_MEM);
373 goto done;
375 pid->id = calloc(1, sizeof(*pid->id));
376 if (pid->id == NULL) {
377 free(pid);
378 err = got_error(GOT_ERR_NO_MEM);
379 goto done;
381 s += tlen;
382 if (!got_parse_sha1_digest(pid->id->sha1, s)) {
383 err = got_error(GOT_ERR_BAD_OBJ_DATA);
384 free(pid->id);
385 free(pid);
386 goto done;
388 SIMPLEQ_INSERT_TAIL(&(*commit)->parent_ids, pid, entry);
389 (*commit)->nparents++;
391 remain -= SHA1_DIGEST_STRING_LENGTH;
392 s += SHA1_DIGEST_STRING_LENGTH;
395 tlen = strlen(GOT_COMMIT_TAG_AUTHOR);
396 if (strncmp(s, GOT_COMMIT_TAG_AUTHOR, tlen) == 0) {
397 char *p;
399 remain -= tlen;
400 if (remain <= 0) {
401 err = got_error(GOT_ERR_BAD_OBJ_DATA);
402 goto done;
404 s += tlen;
405 p = strchr(s, '\n');
406 if (p == NULL) {
407 err = got_error(GOT_ERR_BAD_OBJ_DATA);
408 goto done;
410 *p = '\0';
411 (*commit)->author = strdup(s);
412 if ((*commit)->author == NULL) {
413 err = got_error(GOT_ERR_NO_MEM);
414 goto done;
416 s += strlen((*commit)->author) + 1;
417 remain -= strlen((*commit)->author) + 1;
420 tlen = strlen(GOT_COMMIT_TAG_COMMITTER);
421 if (strncmp(s, GOT_COMMIT_TAG_COMMITTER, tlen) == 0) {
422 char *p;
424 remain -= tlen;
425 if (remain <= 0) {
426 err = got_error(GOT_ERR_BAD_OBJ_DATA);
427 goto done;
429 s += tlen;
430 p = strchr(s, '\n');
431 if (p == NULL) {
432 err = got_error(GOT_ERR_BAD_OBJ_DATA);
433 goto done;
435 *p = '\0';
436 (*commit)->committer = strdup(s);
437 if ((*commit)->committer == NULL) {
438 err = got_error(GOT_ERR_NO_MEM);
439 goto done;
441 s += strlen((*commit)->committer) + 1;
442 remain -= strlen((*commit)->committer) + 1;
445 (*commit)->logmsg = strndup(s, remain);
446 if ((*commit)->logmsg == NULL) {
447 err = got_error(GOT_ERR_NO_MEM);
448 goto done;
450 done:
451 if (err) {
452 got_object_commit_close(*commit);
453 *commit = NULL;
455 return err;
458 static void
459 tree_entry_close(struct got_tree_entry *te)
461 free(te->id);
462 free(te->name);
463 free(te);
466 static const struct got_error *
467 parse_tree_entry(struct got_tree_entry **te, size_t *elen, char *buf,
468 size_t maxlen)
470 char *p = buf, *space;
471 const struct got_error *err = NULL;
472 char hex[SHA1_DIGEST_STRING_LENGTH];
474 *te = calloc(1, sizeof(**te));
475 if (*te == NULL)
476 return got_error(GOT_ERR_NO_MEM);
478 (*te)->id = calloc(1, sizeof(*(*te)->id));
479 if ((*te)->id == NULL) {
480 free(*te);
481 *te = NULL;
482 return got_error(GOT_ERR_NO_MEM);
485 *elen = strlen(buf) + 1;
486 if (*elen > maxlen) {
487 free(*te);
488 *te = NULL;
489 return got_error(GOT_ERR_BAD_OBJ_DATA);
492 space = strchr(buf, ' ');
493 if (space == NULL) {
494 free(*te);
495 *te = NULL;
496 return got_error(GOT_ERR_BAD_OBJ_DATA);
498 while (*p != ' ') {
499 if (*p < '0' && *p > '7') {
500 err = got_error(GOT_ERR_BAD_OBJ_DATA);
501 goto done;
503 (*te)->mode <<= 3;
504 (*te)->mode |= *p - '0';
505 p++;
508 (*te)->name = strdup(space + 1);
509 if (*elen > maxlen || maxlen - *elen < SHA1_DIGEST_LENGTH) {
510 err = got_error(GOT_ERR_BAD_OBJ_DATA);
511 goto done;
513 buf += strlen(buf) + 1;
514 memcpy((*te)->id->sha1, buf, SHA1_DIGEST_LENGTH);
515 *elen += SHA1_DIGEST_LENGTH;
516 done:
517 if (err) {
518 tree_entry_close(*te);
519 *te = NULL;
521 return err;
524 static const struct got_error *
525 parse_tree_object(struct got_tree_object **tree, struct got_repository *repo,
526 char *buf, size_t len)
528 const struct got_error *err;
529 size_t remain = len;
530 int nentries;
532 *tree = calloc(1, sizeof(**tree));
533 if (*tree == NULL)
534 return got_error(GOT_ERR_NO_MEM);
536 SIMPLEQ_INIT(&(*tree)->entries);
538 while (remain > 0) {
539 struct got_tree_entry *te;
540 size_t elen;
542 err = parse_tree_entry(&te, &elen, buf, remain);
543 if (err)
544 return err;
545 (*tree)->nentries++;
546 SIMPLEQ_INSERT_TAIL(&(*tree)->entries, te, entry);
547 buf += elen;
548 remain -= elen;
551 if (remain != 0) {
552 got_object_tree_close(*tree);
553 return got_error(GOT_ERR_BAD_OBJ_DATA);
556 return NULL;
559 static const struct got_error *
560 read_to_mem(uint8_t **outbuf, size_t *outlen, FILE *f)
562 const struct got_error *err = NULL;
563 static const size_t blocksize = 512;
564 size_t n, total, remain;
565 uint8_t *buf;
567 *outbuf = NULL;
568 *outlen = 0;
570 buf = calloc(1, blocksize);
571 if (buf == NULL)
572 return got_error(GOT_ERR_NO_MEM);
574 remain = blocksize;
575 total = 0;
576 while (1) {
577 if (remain == 0) {
578 uint8_t *newbuf;
579 newbuf = reallocarray(buf, 1, total + blocksize);
580 if (newbuf == NULL) {
581 err = got_error(GOT_ERR_NO_MEM);
582 goto done;
584 buf = newbuf;
585 remain += blocksize;
587 n = fread(buf + total, 1, remain, f);
588 if (n == 0) {
589 if (ferror(f)) {
590 err = got_ferror(f, GOT_ERR_IO);
591 goto done;
593 break; /* EOF */
595 remain -= n;
596 total += n;
597 };
599 done:
600 if (err == NULL) {
601 *outbuf = buf;
602 *outlen = total;
603 } else
604 free(buf);
605 return err;
608 static const struct got_error *
609 read_commit_object(struct got_commit_object **commit,
610 struct got_repository *repo, struct got_object *obj, FILE *f)
612 const struct got_error *err = NULL;
613 size_t len;
614 uint8_t *p;
615 int i, ret;
617 if (obj->flags & GOT_OBJ_FLAG_PACKED)
618 err = read_to_mem(&p, &len, f);
619 else
620 err = got_inflate_to_mem(&p, &len, f);
621 if (err)
622 return err;
624 if (len < obj->hdrlen + obj->size) {
625 err = got_error(GOT_ERR_BAD_OBJ_DATA);
626 goto done;
629 /* Skip object header. */
630 len -= obj->hdrlen;
631 err = parse_commit_object(commit, p + obj->hdrlen, len);
632 free(p);
633 done:
634 return err;
637 const struct got_error *
638 got_object_commit_open(struct got_commit_object **commit,
639 struct got_repository *repo, struct got_object *obj)
641 const struct got_error *err = NULL;
642 FILE *f;
644 if (obj->type != GOT_OBJ_TYPE_COMMIT)
645 return got_error(GOT_ERR_OBJ_TYPE);
647 if (obj->flags & GOT_OBJ_FLAG_PACKED)
648 err = got_packfile_extract_object(&f, obj, repo);
649 else
650 err = open_loose_object(&f, obj, repo);
651 if (err)
652 return err;
654 err = read_commit_object(commit, repo, obj, f);
655 fclose(f);
656 return err;
659 void
660 got_object_commit_close(struct got_commit_object *commit)
662 struct got_parent_id *pid;
664 while (!SIMPLEQ_EMPTY(&commit->parent_ids)) {
665 pid = SIMPLEQ_FIRST(&commit->parent_ids);
666 SIMPLEQ_REMOVE_HEAD(&commit->parent_ids, entry);
667 free(pid->id);
668 free(pid);
671 free(commit->tree_id);
672 free(commit->author);
673 free(commit->committer);
674 free(commit->logmsg);
675 free(commit);
678 static const struct got_error *
679 read_tree_object(struct got_tree_object **tree,
680 struct got_repository *repo, struct got_object *obj, FILE *f)
682 const struct got_error *err = NULL;
683 size_t len;
684 uint8_t *p;
685 int i, ret;
687 if (obj->flags & GOT_OBJ_FLAG_PACKED)
688 err = read_to_mem(&p, &len, f);
689 else
690 err = got_inflate_to_mem(&p, &len, f);
691 if (err)
692 return err;
694 if (len < obj->hdrlen + obj->size) {
695 err = got_error(GOT_ERR_BAD_OBJ_DATA);
696 goto done;
699 /* Skip object header. */
700 len -= obj->hdrlen;
701 err = parse_tree_object(tree, repo, p + obj->hdrlen, len);
702 free(p);
703 done:
704 return err;
707 const struct got_error *
708 got_object_tree_open(struct got_tree_object **tree,
709 struct got_repository *repo, struct got_object *obj)
711 const struct got_error *err = NULL;
712 FILE *f;
714 if (obj->type != GOT_OBJ_TYPE_TREE)
715 return got_error(GOT_ERR_OBJ_TYPE);
717 if (obj->flags & GOT_OBJ_FLAG_PACKED)
718 err = got_packfile_extract_object(&f, obj, repo);
719 else
720 err = open_loose_object(&f, obj, repo);
721 if (err)
722 return err;
724 err = read_tree_object(tree, repo, obj, f);
725 fclose(f);
726 return err;
729 void
730 got_object_tree_close(struct got_tree_object *tree)
732 struct got_tree_entry *te;
734 while (!SIMPLEQ_EMPTY(&tree->entries)) {
735 te = SIMPLEQ_FIRST(&tree->entries);
736 SIMPLEQ_REMOVE_HEAD(&tree->entries, entry);
737 tree_entry_close(te);
740 free(tree);
743 const struct got_error *
744 got_object_blob_open(struct got_blob_object **blob,
745 struct got_repository *repo, struct got_object *obj, size_t blocksize)
747 const struct got_error *err = NULL;
749 if (obj->type != GOT_OBJ_TYPE_BLOB)
750 return got_error(GOT_ERR_OBJ_TYPE);
752 if (blocksize < obj->hdrlen)
753 return got_error(GOT_ERR_NO_SPACE);
755 *blob = calloc(1, sizeof(**blob));
756 if (*blob == NULL)
757 return got_error(GOT_ERR_NO_MEM);
759 if (obj->flags & GOT_OBJ_FLAG_PACKED) {
760 (*blob)->read_buf = calloc(1, blocksize);
761 if ((*blob)->read_buf == NULL)
762 return got_error(GOT_ERR_NO_MEM);
763 err = got_packfile_extract_object(&((*blob)->f), obj, repo);
764 if (err)
765 return err;
766 } else {
767 err = open_loose_object(&((*blob)->f), obj, repo);
768 if (err) {
769 free(*blob);
770 return err;
773 err = got_inflate_init(&(*blob)->zb, blocksize);
774 if (err != NULL) {
775 fclose((*blob)->f);
776 free(*blob);
777 return err;
780 (*blob)->read_buf = (*blob)->zb.outbuf;
781 (*blob)->flags |= GOT_BLOB_F_COMPRESSED;
784 (*blob)->hdrlen = obj->hdrlen;
785 (*blob)->blocksize = blocksize;
786 memcpy(&(*blob)->id.sha1, obj->id.sha1, SHA1_DIGEST_LENGTH);
788 return err;
791 void
792 got_object_blob_close(struct got_blob_object *blob)
794 if (blob->flags & GOT_BLOB_F_COMPRESSED)
795 got_inflate_end(&blob->zb);
796 else
797 free(blob->read_buf);
798 fclose(blob->f);
799 free(blob);
802 char *
803 got_object_blob_id_str(struct got_blob_object *blob, char *buf, size_t size)
805 return got_sha1_digest_to_str(blob->id.sha1, buf, size);
808 size_t
809 got_object_blob_get_hdrlen(struct got_blob_object *blob)
811 return blob->hdrlen;
814 const uint8_t *
815 got_object_blob_get_read_buf(struct got_blob_object *blob)
817 return blob->read_buf;
820 const struct got_error *
821 got_object_blob_read_block(size_t *outlenp, struct got_blob_object *blob)
823 size_t n;
825 if (blob->flags & GOT_BLOB_F_COMPRESSED)
826 return got_inflate_read(&blob->zb, blob->f, outlenp);
828 n = fread(blob->read_buf, 1, blob->blocksize, blob->f);
829 if (n == 0 && ferror(blob->f))
830 return got_ferror(blob->f, GOT_ERR_IO);
831 *outlenp = n;
832 return NULL;