Nathan Moinvaziri | aa323f5 | 2017-10-05 23:32:57 -0700 | [diff] [blame] | 1 | /* mz_strm.h -- Stream interface |
Nathan Moinvaziri | db95894 | 2021-01-23 16:18:11 -0800 | [diff] [blame] | 2 | part of the minizip-ng project |
Nathan Moinvaziri | d2a1a12 | 2017-10-01 22:42:35 -0700 | [diff] [blame] | 3 | |
Nathan Moinvaziri | db95894 | 2021-01-23 16:18:11 -0800 | [diff] [blame] | 4 | Copyright (C) 2010-2021 Nathan Moinvaziri |
| 5 | https://github.com/zlib-ng/minizip-ng |
Nathan Moinvaziri | d2a1a12 | 2017-10-01 22:42:35 -0700 | [diff] [blame] | 6 | |
| 7 | This program is distributed under the terms of the same license as zlib. |
| 8 | See the accompanying LICENSE file for the full text of the license. |
| 9 | */ |
| 10 | |
Nathan Moinvaziri | 408940f | 2018-05-09 09:42:31 -0700 | [diff] [blame] | 11 | #ifndef MZ_STREAM_H |
| 12 | #define MZ_STREAM_H |
Nathan Moinvaziri | d2a1a12 | 2017-10-01 22:42:35 -0700 | [diff] [blame] | 13 | |
Nathan Moinvaziri | d2a1a12 | 2017-10-01 22:42:35 -0700 | [diff] [blame] | 14 | #ifdef __cplusplus |
| 15 | extern "C" { |
| 16 | #endif |
| 17 | |
Nathan Moinvaziri | 0a59208 | 2017-10-02 22:11:03 -0700 | [diff] [blame] | 18 | /***************************************************************************/ |
| 19 | |
Nathan Moinvaziri | 016ad47 | 2017-10-09 23:36:30 -0700 | [diff] [blame] | 20 | #define MZ_STREAM_PROP_TOTAL_IN (1) |
| 21 | #define MZ_STREAM_PROP_TOTAL_IN_MAX (2) |
| 22 | #define MZ_STREAM_PROP_TOTAL_OUT (3) |
| 23 | #define MZ_STREAM_PROP_TOTAL_OUT_MAX (4) |
| 24 | #define MZ_STREAM_PROP_HEADER_SIZE (5) |
| 25 | #define MZ_STREAM_PROP_FOOTER_SIZE (6) |
| 26 | #define MZ_STREAM_PROP_DISK_SIZE (7) |
| 27 | #define MZ_STREAM_PROP_DISK_NUMBER (8) |
Nathan Moinvaziri | 05e9993 | 2017-10-10 19:18:05 -0700 | [diff] [blame] | 28 | #define MZ_STREAM_PROP_COMPRESS_LEVEL (9) |
Nathan Moinvaziri | c4668ed | 2020-10-25 11:56:19 -0700 | [diff] [blame] | 29 | #define MZ_STREAM_PROP_COMPRESS_METHOD (10) |
Nathan Moinvaziri | 3c43816 | 2019-04-28 09:23:56 -0700 | [diff] [blame] | 30 | #define MZ_STREAM_PROP_COMPRESS_WINDOW (11) |
Nathan Moinvaziri | 1e3300f | 2017-10-08 21:48:28 -0700 | [diff] [blame] | 31 | |
Nathan Moinvaziri | 0a59208 | 2017-10-02 22:11:03 -0700 | [diff] [blame] | 32 | /***************************************************************************/ |
| 33 | |
Nathan Moinvaziri | eb5d730 | 2017-10-05 21:26:34 -0700 | [diff] [blame] | 34 | typedef int32_t (*mz_stream_open_cb) (void *stream, const char *path, int32_t mode); |
Nathan Moinvaziri | 0a59208 | 2017-10-02 22:11:03 -0700 | [diff] [blame] | 35 | typedef int32_t (*mz_stream_is_open_cb) (void *stream); |
Nathan Moinvaziri | eb5d730 | 2017-10-05 21:26:34 -0700 | [diff] [blame] | 36 | typedef int32_t (*mz_stream_read_cb) (void *stream, void *buf, int32_t size); |
| 37 | typedef int32_t (*mz_stream_write_cb) (void *stream, const void *buf, int32_t size); |
Nathan Moinvaziri | 0a59208 | 2017-10-02 22:11:03 -0700 | [diff] [blame] | 38 | typedef int64_t (*mz_stream_tell_cb) (void *stream); |
Nathan Moinvaziri | eb5d730 | 2017-10-05 21:26:34 -0700 | [diff] [blame] | 39 | typedef int32_t (*mz_stream_seek_cb) (void *stream, int64_t offset, int32_t origin); |
Nathan Moinvaziri | 0a59208 | 2017-10-02 22:11:03 -0700 | [diff] [blame] | 40 | typedef int32_t (*mz_stream_close_cb) (void *stream); |
| 41 | typedef int32_t (*mz_stream_error_cb) (void *stream); |
| 42 | typedef void* (*mz_stream_create_cb) (void **stream); |
Nathan Moinvaziri | 088bfe6 | 2017-10-25 14:27:26 -0700 | [diff] [blame] | 43 | typedef void (*mz_stream_destroy_cb) (void **stream); |
Nathan Moinvaziri | 1e3300f | 2017-10-08 21:48:28 -0700 | [diff] [blame] | 44 | |
Nathan Moinvaziri | 016ad47 | 2017-10-09 23:36:30 -0700 | [diff] [blame] | 45 | typedef int32_t (*mz_stream_get_prop_int64_cb) (void *stream, int32_t prop, int64_t *value); |
| 46 | typedef int32_t (*mz_stream_set_prop_int64_cb) (void *stream, int32_t prop, int64_t value); |
Nathan Moinvaziri | 0a59208 | 2017-10-02 22:11:03 -0700 | [diff] [blame] | 47 | |
Nathan Moinvaziri | 32fd805 | 2019-07-04 10:32:02 -0700 | [diff] [blame] | 48 | typedef int32_t (*mz_stream_find_cb) (void *stream, const void *find, int32_t find_size, |
Nathan Moinvaziri | b08bd9a | 2018-11-08 14:52:52 -0800 | [diff] [blame] | 49 | int64_t max_seek, int64_t *position); |
| 50 | |
Nathan Moinvaziri | 0a59208 | 2017-10-02 22:11:03 -0700 | [diff] [blame] | 51 | /***************************************************************************/ |
Nathan Moinvaziri | d2a1a12 | 2017-10-01 22:42:35 -0700 | [diff] [blame] | 52 | |
Nathan Moinvaziri | dc6962b | 2020-06-14 15:19:14 -0700 | [diff] [blame] | 53 | typedef struct mz_stream_vtbl_s { |
Nathan Moinvaziri | 0a59208 | 2017-10-02 22:11:03 -0700 | [diff] [blame] | 54 | mz_stream_open_cb open; |
| 55 | mz_stream_is_open_cb is_open; |
| 56 | mz_stream_read_cb read; |
| 57 | mz_stream_write_cb write; |
| 58 | mz_stream_tell_cb tell; |
| 59 | mz_stream_seek_cb seek; |
| 60 | mz_stream_close_cb close; |
| 61 | mz_stream_error_cb error; |
| 62 | mz_stream_create_cb create; |
Nathan Moinvaziri | 088bfe6 | 2017-10-25 14:27:26 -0700 | [diff] [blame] | 63 | mz_stream_destroy_cb destroy; |
Nathan Moinvaziri | 8db28c9 | 2017-10-08 23:26:17 -0700 | [diff] [blame] | 64 | |
Nathan Moinvaziri | 016ad47 | 2017-10-09 23:36:30 -0700 | [diff] [blame] | 65 | mz_stream_get_prop_int64_cb get_prop_int64; |
| 66 | mz_stream_set_prop_int64_cb set_prop_int64; |
Nathan Moinvaziri | 1e3300f | 2017-10-08 21:48:28 -0700 | [diff] [blame] | 67 | } mz_stream_vtbl; |
| 68 | |
| 69 | typedef struct mz_stream_s { |
| 70 | mz_stream_vtbl *vtbl; |
| 71 | struct mz_stream_s *base; |
Nathan Moinvaziri | d2a1a12 | 2017-10-01 22:42:35 -0700 | [diff] [blame] | 72 | } mz_stream; |
| 73 | |
Nathan Moinvaziri | 0a59208 | 2017-10-02 22:11:03 -0700 | [diff] [blame] | 74 | /***************************************************************************/ |
| 75 | |
Nathan Moinvaziri | eb5d730 | 2017-10-05 21:26:34 -0700 | [diff] [blame] | 76 | int32_t mz_stream_open(void *stream, const char *path, int32_t mode); |
Nathan Moinvaziri | d2a1a12 | 2017-10-01 22:42:35 -0700 | [diff] [blame] | 77 | int32_t mz_stream_is_open(void *stream); |
Nathan Moinvaziri | eb5d730 | 2017-10-05 21:26:34 -0700 | [diff] [blame] | 78 | int32_t mz_stream_read(void *stream, void *buf, int32_t size); |
Nathan Moinvaziri | 3624400 | 2017-10-02 00:44:51 -0700 | [diff] [blame] | 79 | int32_t mz_stream_read_uint8(void *stream, uint8_t *value); |
| 80 | int32_t mz_stream_read_uint16(void *stream, uint16_t *value); |
| 81 | int32_t mz_stream_read_uint32(void *stream, uint32_t *value); |
Nathan Moinvaziri | 904c408 | 2018-10-08 23:31:21 -0700 | [diff] [blame] | 82 | int32_t mz_stream_read_int64(void *stream, int64_t *value); |
Nathan Moinvaziri | 3624400 | 2017-10-02 00:44:51 -0700 | [diff] [blame] | 83 | int32_t mz_stream_read_uint64(void *stream, uint64_t *value); |
Nathan Moinvaziri | eb5d730 | 2017-10-05 21:26:34 -0700 | [diff] [blame] | 84 | int32_t mz_stream_write(void *stream, const void *buf, int32_t size); |
Nathan Moinvaziri | 0a59208 | 2017-10-02 22:11:03 -0700 | [diff] [blame] | 85 | int32_t mz_stream_write_uint8(void *stream, uint8_t value); |
| 86 | int32_t mz_stream_write_uint16(void *stream, uint16_t value); |
| 87 | int32_t mz_stream_write_uint32(void *stream, uint32_t value); |
Nathan Moinvaziri | 904c408 | 2018-10-08 23:31:21 -0700 | [diff] [blame] | 88 | int32_t mz_stream_write_int64(void *stream, int64_t value); |
Nathan Moinvaziri | 0a59208 | 2017-10-02 22:11:03 -0700 | [diff] [blame] | 89 | int32_t mz_stream_write_uint64(void *stream, uint64_t value); |
| 90 | int32_t mz_stream_copy(void *target, void *source, int32_t len); |
Nathan Moinvaziri | 3c43816 | 2019-04-28 09:23:56 -0700 | [diff] [blame] | 91 | int32_t mz_stream_copy_to_end(void *target, void *source); |
Nathan Moinvaziri | c5da498 | 2018-10-18 11:02:59 -0700 | [diff] [blame] | 92 | int32_t mz_stream_copy_stream(void *target, mz_stream_write_cb write_cb, void *source, mz_stream_read_cb read_cb, int32_t len); |
Nathan Moinvaziri | 3c43816 | 2019-04-28 09:23:56 -0700 | [diff] [blame] | 93 | int32_t mz_stream_copy_stream_to_end(void *target, mz_stream_write_cb write_cb, void *source, mz_stream_read_cb read_cb); |
Nathan Moinvaziri | d2a1a12 | 2017-10-01 22:42:35 -0700 | [diff] [blame] | 94 | int64_t mz_stream_tell(void *stream); |
Nathan Moinvaziri | eb5d730 | 2017-10-05 21:26:34 -0700 | [diff] [blame] | 95 | int32_t mz_stream_seek(void *stream, int64_t offset, int32_t origin); |
Nathan Moinvaziri | 65dbda8 | 2018-11-07 20:23:42 -0800 | [diff] [blame] | 96 | int32_t mz_stream_find(void *stream, const void *find, int32_t find_size, int64_t max_seek, int64_t *position); |
| 97 | int32_t mz_stream_find_reverse(void *stream, const void *find, int32_t find_size, int64_t max_seek, int64_t *position); |
Nathan Moinvaziri | d2a1a12 | 2017-10-01 22:42:35 -0700 | [diff] [blame] | 98 | int32_t mz_stream_close(void *stream); |
| 99 | int32_t mz_stream_error(void *stream); |
| 100 | |
| 101 | int32_t mz_stream_set_base(void *stream, void *base); |
Nathan Moinvaziri | 627993e | 2018-07-22 09:06:16 -0700 | [diff] [blame] | 102 | void* mz_stream_get_interface(void *stream); |
Nathan Moinvaziri | 016ad47 | 2017-10-09 23:36:30 -0700 | [diff] [blame] | 103 | int32_t mz_stream_get_prop_int64(void *stream, int32_t prop, int64_t *value); |
| 104 | int32_t mz_stream_set_prop_int64(void *stream, int32_t prop, int64_t value); |
Nathan Moinvaziri | d2a1a12 | 2017-10-01 22:42:35 -0700 | [diff] [blame] | 105 | |
Nathan Moinvaziri | 8db28c9 | 2017-10-08 23:26:17 -0700 | [diff] [blame] | 106 | void* mz_stream_create(void **stream, mz_stream_vtbl *vtbl); |
Nathan Moinvaziri | 3624400 | 2017-10-02 00:44:51 -0700 | [diff] [blame] | 107 | void mz_stream_delete(void **stream); |
| 108 | |
Nathan Moinvaziri | 0a59208 | 2017-10-02 22:11:03 -0700 | [diff] [blame] | 109 | /***************************************************************************/ |
| 110 | |
Nathan Moinvaziri | 13a12e3 | 2017-12-26 12:40:30 -0800 | [diff] [blame] | 111 | int32_t mz_stream_raw_open(void *stream, const char *filename, int32_t mode); |
| 112 | int32_t mz_stream_raw_is_open(void *stream); |
| 113 | int32_t mz_stream_raw_read(void *stream, void *buf, int32_t size); |
| 114 | int32_t mz_stream_raw_write(void *stream, const void *buf, int32_t size); |
| 115 | int64_t mz_stream_raw_tell(void *stream); |
| 116 | int32_t mz_stream_raw_seek(void *stream, int64_t offset, int32_t origin); |
| 117 | int32_t mz_stream_raw_close(void *stream); |
| 118 | int32_t mz_stream_raw_error(void *stream); |
| 119 | |
| 120 | int32_t mz_stream_raw_get_prop_int64(void *stream, int32_t prop, int64_t *value); |
| 121 | int32_t mz_stream_raw_set_prop_int64(void *stream, int32_t prop, int64_t value); |
| 122 | |
Nathan Moinvaziri | 4f6a0e3 | 2017-11-10 08:45:14 -0800 | [diff] [blame] | 123 | void* mz_stream_raw_create(void **stream); |
| 124 | void mz_stream_raw_delete(void **stream); |
| 125 | |
| 126 | /***************************************************************************/ |
| 127 | |
Nathan Moinvaziri | d2a1a12 | 2017-10-01 22:42:35 -0700 | [diff] [blame] | 128 | #ifdef __cplusplus |
| 129 | } |
| 130 | #endif |
| 131 | |
| 132 | #endif |