-
Notifications
You must be signed in to change notification settings - Fork 1
/
zip.h
105 lines (88 loc) · 3.78 KB
/
zip.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//============================================================================
// Mini Spin-X Library
//
// Copyright (c) 2024, Jarkko Lempiainen
// All rights reserved.
//============================================================================
#ifndef PFC_CORE_ZIP_H
#define PFC_CORE_ZIP_H
//----------------------------------------------------------------------------
//============================================================================
// interface
//============================================================================
// external
#include "streams.h"
#include "sxp_extlibs/zlib/src/zlib.h"
namespace pfc
{
// new
class zip_input_stream;
class zip_output_stream;
//----------------------------------------------------------------------------
//============================================================================
// zip_input_stream
//============================================================================
class zip_input_stream: public bin_input_stream_base
{
public:
// construction
zip_input_stream(bin_input_stream_base&, usize_t stream_size_);
virtual ~zip_input_stream();
//--------------------------------------------------------------------------
private:
zip_input_stream(const zip_input_stream&); // not implemented
void operator=(const zip_input_stream&); // not implemented
//--------------------------------------------------------------------------
// stream implementation
virtual usize_t update_buffer_impl(void*, usize_t num_bytes_, bool exact_);
virtual void rewind_impl();
virtual void rewind_impl(usize_t num_bytes_);
virtual void skip_impl();
virtual void seek_impl(usize_t abs_pos_);
//--------------------------------------------------------------------------
// helpers
void init_stream();
static void *alloc(void*, unsigned items_, unsigned size_);
static void free(void*, void *data_);
//--------------------------------------------------------------------------
enum {compressed_buffer_size=4096};
enum {uncompressed_buffer_size=4096};
bin_input_stream_base &m_stream;
usize_t m_stream_size;
z_stream m_state;
uint8_t m_buffer_compressed[compressed_buffer_size];
uint8_t m_buffer_uncompressed[uncompressed_buffer_size];
};
//----------------------------------------------------------------------------
//============================================================================
// zip_output_stream
//============================================================================
class zip_output_stream: public bin_output_stream_base
{
public:
// construction
zip_output_stream(bin_output_stream_base&);
virtual ~zip_output_stream();
//--------------------------------------------------------------------------
private:
zip_output_stream(const zip_output_stream&); // not implemented
void operator=(const zip_output_stream&); // not implemented
//--------------------------------------------------------------------------
// stream implementation
virtual void flush_buffer_impl(const void*, usize_t num_bytes_);
//--------------------------------------------------------------------------
// helpers
void init_stream();
static void *alloc(void*, unsigned items_, unsigned size_);
static void free(void*, void *data_);
//--------------------------------------------------------------------------
enum {uncompressed_buffer_size=4096};
enum {compressed_buffer_size=uncompressed_buffer_size};
bin_output_stream_base &m_stream;
z_stream m_state;
uint8_t m_buffer_uncompressed[uncompressed_buffer_size];
};
//----------------------------------------------------------------------------
//============================================================================
} // namespace pfc
#endif