static int copy_source(zip_t *za, zip_source_t *src) { zip_uint8_t buf[BUFSIZE]; zip_int64_t n; int ret; if (zip_source_open(src) < 0) { _zip_error_set_from_source(&za->error, src); return -1; } ret = 0; while ((n=zip_source_read(src, buf, sizeof(buf))) > 0) { if (_zip_write(za, buf, (zip_uint64_t)n) < 0) { ret = -1; break; } } if (n < 0) { _zip_error_set_from_source(&za->error, src); ret = -1; } zip_source_close(src); return ret; }
int _zip_string_write(zip_t *za, const zip_string_t *s) { if (s == NULL) return 0; return _zip_write(za, s->raw, s->length); }
int _zip_ef_write(zip_t *za, const zip_extra_field_t *ef, zip_flags_t flags) { zip_uint8_t b[4]; zip_buffer_t *buffer = _zip_buffer_new(b, sizeof(b)); if (buffer == NULL) { return -1; } for (; ef; ef=ef->next) { if (ef->flags & flags & ZIP_EF_BOTH) { _zip_buffer_set_offset(buffer, 0); _zip_buffer_put_16(buffer, ef->id); _zip_buffer_put_16(buffer, ef->size); if (!_zip_buffer_ok(buffer)) { zip_error_set(&za->error, ZIP_ER_INTERNAL, 0); _zip_buffer_free(buffer); return -1; } if (_zip_write(za, b, 4) < 0) { _zip_buffer_free(buffer); return -1; } if (ef->size > 0) { if (_zip_write(za, ef->data, ef->size) < 0) { _zip_buffer_free(buffer); return -1; } } } } _zip_buffer_free(buffer); return 0; }
static int copy_data(zip_t *za, zip_uint64_t len) { zip_uint8_t buf[BUFSIZE]; size_t n; while (len > 0) { n = len > sizeof(buf) ? sizeof(buf) : len; if (_zip_read(za->src, buf, n, &za->error) < 0) { return -1; } if (_zip_write(za, buf, n) < 0) { return -1; } len -= n; } return 0; }