blob: 8b0027cf50387e9fc4bae3cd85546d9520cf0f9e [file] [log] [blame]
Nathan Moinvaziriaa323f52017-10-05 23:32:57 -07001/* mz_strm.h -- Stream interface
Nathan Moinvaziridb958942021-01-23 16:18:11 -08002 part of the minizip-ng project
Nathan Moinvazirid2a1a122017-10-01 22:42:35 -07003
Nathan Moinvaziridb958942021-01-23 16:18:11 -08004 Copyright (C) 2010-2021 Nathan Moinvaziri
5 https://github.com/zlib-ng/minizip-ng
Nathan Moinvazirid2a1a122017-10-01 22:42:35 -07006
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 Moinvaziri408940f2018-05-09 09:42:31 -070011#ifndef MZ_STREAM_H
12#define MZ_STREAM_H
Nathan Moinvazirid2a1a122017-10-01 22:42:35 -070013
Nathan Moinvazirid2a1a122017-10-01 22:42:35 -070014#ifdef __cplusplus
15extern "C" {
16#endif
17
Nathan Moinvaziri0a592082017-10-02 22:11:03 -070018/***************************************************************************/
19
Nathan Moinvaziri016ad472017-10-09 23:36:30 -070020#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 Moinvaziri05e99932017-10-10 19:18:05 -070028#define MZ_STREAM_PROP_COMPRESS_LEVEL (9)
Nathan Moinvaziric4668ed2020-10-25 11:56:19 -070029#define MZ_STREAM_PROP_COMPRESS_METHOD (10)
Nathan Moinvaziri3c438162019-04-28 09:23:56 -070030#define MZ_STREAM_PROP_COMPRESS_WINDOW (11)
Nathan Moinvaziri1e3300f2017-10-08 21:48:28 -070031
Nathan Moinvaziri0a592082017-10-02 22:11:03 -070032/***************************************************************************/
33
Nathan Moinvazirieb5d7302017-10-05 21:26:34 -070034typedef int32_t (*mz_stream_open_cb) (void *stream, const char *path, int32_t mode);
Nathan Moinvaziri0a592082017-10-02 22:11:03 -070035typedef int32_t (*mz_stream_is_open_cb) (void *stream);
Nathan Moinvazirieb5d7302017-10-05 21:26:34 -070036typedef int32_t (*mz_stream_read_cb) (void *stream, void *buf, int32_t size);
37typedef int32_t (*mz_stream_write_cb) (void *stream, const void *buf, int32_t size);
Nathan Moinvaziri0a592082017-10-02 22:11:03 -070038typedef int64_t (*mz_stream_tell_cb) (void *stream);
Nathan Moinvazirieb5d7302017-10-05 21:26:34 -070039typedef int32_t (*mz_stream_seek_cb) (void *stream, int64_t offset, int32_t origin);
Nathan Moinvaziri0a592082017-10-02 22:11:03 -070040typedef int32_t (*mz_stream_close_cb) (void *stream);
41typedef int32_t (*mz_stream_error_cb) (void *stream);
42typedef void* (*mz_stream_create_cb) (void **stream);
Nathan Moinvaziri088bfe62017-10-25 14:27:26 -070043typedef void (*mz_stream_destroy_cb) (void **stream);
Nathan Moinvaziri1e3300f2017-10-08 21:48:28 -070044
Nathan Moinvaziri016ad472017-10-09 23:36:30 -070045typedef int32_t (*mz_stream_get_prop_int64_cb) (void *stream, int32_t prop, int64_t *value);
46typedef int32_t (*mz_stream_set_prop_int64_cb) (void *stream, int32_t prop, int64_t value);
Nathan Moinvaziri0a592082017-10-02 22:11:03 -070047
Nathan Moinvaziri32fd8052019-07-04 10:32:02 -070048typedef int32_t (*mz_stream_find_cb) (void *stream, const void *find, int32_t find_size,
Nathan Moinvazirib08bd9a2018-11-08 14:52:52 -080049 int64_t max_seek, int64_t *position);
50
Nathan Moinvaziri0a592082017-10-02 22:11:03 -070051/***************************************************************************/
Nathan Moinvazirid2a1a122017-10-01 22:42:35 -070052
Nathan Moinvaziridc6962b2020-06-14 15:19:14 -070053typedef struct mz_stream_vtbl_s {
Nathan Moinvaziri0a592082017-10-02 22:11:03 -070054 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 Moinvaziri088bfe62017-10-25 14:27:26 -070063 mz_stream_destroy_cb destroy;
Nathan Moinvaziri8db28c92017-10-08 23:26:17 -070064
Nathan Moinvaziri016ad472017-10-09 23:36:30 -070065 mz_stream_get_prop_int64_cb get_prop_int64;
66 mz_stream_set_prop_int64_cb set_prop_int64;
Nathan Moinvaziri1e3300f2017-10-08 21:48:28 -070067} mz_stream_vtbl;
68
69typedef struct mz_stream_s {
70 mz_stream_vtbl *vtbl;
71 struct mz_stream_s *base;
Nathan Moinvazirid2a1a122017-10-01 22:42:35 -070072} mz_stream;
73
Nathan Moinvaziri0a592082017-10-02 22:11:03 -070074/***************************************************************************/
75
Nathan Moinvazirieb5d7302017-10-05 21:26:34 -070076int32_t mz_stream_open(void *stream, const char *path, int32_t mode);
Nathan Moinvazirid2a1a122017-10-01 22:42:35 -070077int32_t mz_stream_is_open(void *stream);
Nathan Moinvazirieb5d7302017-10-05 21:26:34 -070078int32_t mz_stream_read(void *stream, void *buf, int32_t size);
Nathan Moinvaziri36244002017-10-02 00:44:51 -070079int32_t mz_stream_read_uint8(void *stream, uint8_t *value);
80int32_t mz_stream_read_uint16(void *stream, uint16_t *value);
81int32_t mz_stream_read_uint32(void *stream, uint32_t *value);
Nathan Moinvaziri904c4082018-10-08 23:31:21 -070082int32_t mz_stream_read_int64(void *stream, int64_t *value);
Nathan Moinvaziri36244002017-10-02 00:44:51 -070083int32_t mz_stream_read_uint64(void *stream, uint64_t *value);
Nathan Moinvazirieb5d7302017-10-05 21:26:34 -070084int32_t mz_stream_write(void *stream, const void *buf, int32_t size);
Nathan Moinvaziri0a592082017-10-02 22:11:03 -070085int32_t mz_stream_write_uint8(void *stream, uint8_t value);
86int32_t mz_stream_write_uint16(void *stream, uint16_t value);
87int32_t mz_stream_write_uint32(void *stream, uint32_t value);
Nathan Moinvaziri904c4082018-10-08 23:31:21 -070088int32_t mz_stream_write_int64(void *stream, int64_t value);
Nathan Moinvaziri0a592082017-10-02 22:11:03 -070089int32_t mz_stream_write_uint64(void *stream, uint64_t value);
90int32_t mz_stream_copy(void *target, void *source, int32_t len);
Nathan Moinvaziri3c438162019-04-28 09:23:56 -070091int32_t mz_stream_copy_to_end(void *target, void *source);
Nathan Moinvaziric5da4982018-10-18 11:02:59 -070092int32_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 Moinvaziri3c438162019-04-28 09:23:56 -070093int32_t mz_stream_copy_stream_to_end(void *target, mz_stream_write_cb write_cb, void *source, mz_stream_read_cb read_cb);
Nathan Moinvazirid2a1a122017-10-01 22:42:35 -070094int64_t mz_stream_tell(void *stream);
Nathan Moinvazirieb5d7302017-10-05 21:26:34 -070095int32_t mz_stream_seek(void *stream, int64_t offset, int32_t origin);
Nathan Moinvaziri65dbda82018-11-07 20:23:42 -080096int32_t mz_stream_find(void *stream, const void *find, int32_t find_size, int64_t max_seek, int64_t *position);
97int32_t mz_stream_find_reverse(void *stream, const void *find, int32_t find_size, int64_t max_seek, int64_t *position);
Nathan Moinvazirid2a1a122017-10-01 22:42:35 -070098int32_t mz_stream_close(void *stream);
99int32_t mz_stream_error(void *stream);
100
101int32_t mz_stream_set_base(void *stream, void *base);
Nathan Moinvaziri627993e2018-07-22 09:06:16 -0700102void* mz_stream_get_interface(void *stream);
Nathan Moinvaziri016ad472017-10-09 23:36:30 -0700103int32_t mz_stream_get_prop_int64(void *stream, int32_t prop, int64_t *value);
104int32_t mz_stream_set_prop_int64(void *stream, int32_t prop, int64_t value);
Nathan Moinvazirid2a1a122017-10-01 22:42:35 -0700105
Nathan Moinvaziri8db28c92017-10-08 23:26:17 -0700106void* mz_stream_create(void **stream, mz_stream_vtbl *vtbl);
Nathan Moinvaziri36244002017-10-02 00:44:51 -0700107void mz_stream_delete(void **stream);
108
Nathan Moinvaziri0a592082017-10-02 22:11:03 -0700109/***************************************************************************/
110
Nathan Moinvaziri13a12e32017-12-26 12:40:30 -0800111int32_t mz_stream_raw_open(void *stream, const char *filename, int32_t mode);
112int32_t mz_stream_raw_is_open(void *stream);
113int32_t mz_stream_raw_read(void *stream, void *buf, int32_t size);
114int32_t mz_stream_raw_write(void *stream, const void *buf, int32_t size);
115int64_t mz_stream_raw_tell(void *stream);
116int32_t mz_stream_raw_seek(void *stream, int64_t offset, int32_t origin);
117int32_t mz_stream_raw_close(void *stream);
118int32_t mz_stream_raw_error(void *stream);
119
120int32_t mz_stream_raw_get_prop_int64(void *stream, int32_t prop, int64_t *value);
121int32_t mz_stream_raw_set_prop_int64(void *stream, int32_t prop, int64_t value);
122
Nathan Moinvaziri4f6a0e32017-11-10 08:45:14 -0800123void* mz_stream_raw_create(void **stream);
124void mz_stream_raw_delete(void **stream);
125
126/***************************************************************************/
127
Nathan Moinvazirid2a1a122017-10-01 22:42:35 -0700128#ifdef __cplusplus
129}
130#endif
131
132#endif