return bytes_read;
}
+/* Read all of ZM into memory, storing the data in *DATAP and its size in *NP.
+ Returns NULL if successful, otherwise an error string that the caller
+ must eventually free(). */
+char * WARN_UNUSED_RESULT
+zip_member_read_all (struct zip_reader *zr, const char *member_name,
+ void **datap, size_t *np)
+{
+ struct zip_member *zm = zip_member_open (zr, member_name);
+ if (!zm)
+ {
+ *datap = NULL;
+ *np = 0;
+ return ds_steal_cstr (zr->errs);
+ }
+
+ *datap = xmalloc (zm->ucomp_size);
+ *np = zm->ucomp_size;
+
+ uint8_t *data = *datap;
+ while (zm->bytes_unread)
+ if (zip_member_read (zm, data + (zm->ucomp_size - zm->bytes_unread),
+ zm->bytes_unread) == -1)
+ {
+ zip_member_finish (zm);
+ free (*datap);
+ *datap = NULL;
+ *np = 0;
+ return ds_steal_cstr (zr->errs);
+ }
+
+ zip_member_finish (zm);
+ return NULL;
+}
/* Read a central directory header from FILE and initializes ZE with it.
Returns true if successful, false otherwise. On error, appends error
}
static struct zip_entry *
-zip_entry_find (struct zip_reader *zr, const char *member)
+zip_entry_find (const struct zip_reader *zr, const char *member)
{
for (int i = 0; i < zr->n_entries; ++i)
{
return idx < zr->n_entries ? zr->entries[idx].name : NULL;
}
+/* Returns true if ZR contains a member named MEMBER, false otherwise. */
+bool
+zip_reader_contains_member (const struct zip_reader *zr, const char *member)
+{
+ return zip_entry_find (zr, member) != NULL;
+}
+
/* Return the member called MEMBER from the reader ZR */
struct zip_member *
zip_member_open (struct zip_reader *zr, const char *member)