diff options
author | Timo Teräs <timo.teras@iki.fi> | 2021-07-16 16:31:59 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2021-07-22 15:30:08 +0300 |
commit | 7af34db6cfed5792b8acd4a4fd4da56de8381673 (patch) | |
tree | cd4823b746a03f81e976a929065d5655e0f8db80 /src/apk_io.h | |
parent | 7b58f909fac0dd309355b244af60dc7374d7ef76 (diff) | |
download | apk-tools-7af34db6cfed5792b8acd4a4fd4da56de8381673.tar.gz apk-tools-7af34db6cfed5792b8acd4a4fd4da56de8381673.tar.bz2 apk-tools-7af34db6cfed5792b8acd4a4fd4da56de8381673.tar.xz apk-tools-7af34db6cfed5792b8acd4a4fd4da56de8381673.zip |
adb: support seamless de/compression of adb files
Add compression header of adb files. Support uncompressed and
deflate compression at this time.
Diffstat (limited to 'src/apk_io.h')
-rw-r--r-- | src/apk_io.h | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/apk_io.h b/src/apk_io.h index 40a0d8c..61aee4f 100644 --- a/src/apk_io.h +++ b/src/apk_io.h @@ -93,6 +93,7 @@ struct apk_istream *apk_istream_from_fd(int fd); struct apk_istream *apk_istream_from_fd_url_if_modified(int atfd, const char *url, time_t since); static inline int apk_istream_error(struct apk_istream *is, int err) { if (!is->err) is->err = err; return err; } ssize_t apk_istream_read(struct apk_istream *is, void *ptr, size_t size); +void *apk_istream_peek(struct apk_istream *is, size_t len); void *apk_istream_get(struct apk_istream *is, size_t len); apk_blob_t apk_istream_get_max(struct apk_istream *is, size_t size); apk_blob_t apk_istream_get_delim(struct apk_istream *is, apk_blob_t token); @@ -119,19 +120,6 @@ static inline int apk_istream_close(struct apk_istream *is) return is->ops->close(is); } -#define APK_MPART_DATA 1 /* data processed so far */ -#define APK_MPART_BOUNDARY 2 /* final part of data, before boundary */ -#define APK_MPART_END 3 /* signals end of stream */ - -typedef int (*apk_multipart_cb)(void *ctx, int part, apk_blob_t data); - -struct apk_istream *apk_istream_gunzip_mpart(struct apk_istream *, - apk_multipart_cb cb, void *ctx); -static inline struct apk_istream *apk_istream_gunzip(struct apk_istream *is) -{ - return apk_istream_gunzip_mpart(is, NULL, NULL); -} - struct apk_segment_istream { struct apk_istream is; struct apk_istream *pis; @@ -152,7 +140,6 @@ struct apk_ostream { int rc; }; -struct apk_ostream *apk_ostream_gzip(struct apk_ostream *); struct apk_ostream *apk_ostream_counter(off_t *); struct apk_ostream *apk_ostream_to_fd(int fd); struct apk_ostream *apk_ostream_to_file(int atfd, const char *file, mode_t mode); @@ -199,4 +186,33 @@ gid_t apk_id_cache_resolve_gid(struct apk_id_cache *idc, apk_blob_t groupname, g apk_blob_t apk_id_cache_resolve_user(struct apk_id_cache *idc, uid_t uid); apk_blob_t apk_id_cache_resolve_group(struct apk_id_cache *idc, gid_t gid); +// Gzip support + +#define APK_MPART_DATA 1 /* data processed so far */ +#define APK_MPART_BOUNDARY 2 /* final part of data, before boundary */ +#define APK_MPART_END 3 /* signals end of stream */ + +typedef int (*apk_multipart_cb)(void *ctx, int part, apk_blob_t data); + +struct apk_istream *apk_istream_zlib(struct apk_istream *, int, + apk_multipart_cb cb, void *ctx); +static inline struct apk_istream *apk_istream_gunzip_mpart(struct apk_istream *is, + apk_multipart_cb cb, void *ctx) { + return apk_istream_zlib(is, 0, cb, ctx); +} +static inline struct apk_istream *apk_istream_gunzip(struct apk_istream *is) { + return apk_istream_zlib(is, 0, NULL, NULL); +} +static inline struct apk_istream *apk_istream_deflate(struct apk_istream *is) { + return apk_istream_zlib(is, 1, NULL, NULL); +} + +struct apk_ostream *apk_ostream_zlib(struct apk_ostream *, int); +static inline struct apk_ostream *apk_ostream_gzip(struct apk_ostream *os) { + return apk_ostream_zlib(os, 0); +} +static inline struct apk_ostream *apk_ostream_deflate(struct apk_ostream *os) { + return apk_ostream_zlib(os, 1); +} + #endif |