-
Notifications
You must be signed in to change notification settings - Fork 90
/
pkg2zip_out.c
118 lines (106 loc) · 1.81 KB
/
pkg2zip_out.c
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
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "pkg2zip_out.h"
#include "pkg2zip_sys.h"
#include "pkg2zip_zip.h"
static zip out_zip;
static int out_zipped;
static sys_file out_file;
static uint64_t out_file_offset;
void out_begin(const char* name, int zipped)
{
if (zipped)
{
zip_create(&out_zip, name);
}
out_zipped = zipped;
}
void out_end(void)
{
if (out_zipped)
{
zip_close(&out_zip);
}
}
void out_add_folder(const char* path)
{
if (out_zipped)
{
zip_add_folder(&out_zip, path);
}
else
{
sys_mkdir(path);
}
}
uint64_t out_begin_file(const char* name, int compress)
{
if (out_zipped)
{
return zip_begin_file(&out_zip, name, compress);
}
else
{
out_file = sys_create(name);
out_file_offset = 0;
return 0;
}
}
void out_end_file(void)
{
if (out_zipped)
{
zip_end_file(&out_zip);
}
else
{
sys_close(out_file);
}
}
void out_write(const void* buffer, uint32_t size)
{
if (out_zipped)
{
zip_write_file(&out_zip, buffer, size);
}
else
{
sys_write(out_file, out_file_offset, buffer, size);
out_file_offset += size;
}
}
void out_write_at(uint64_t offset, const void* buffer, uint32_t size)
{
if (out_zipped)
{
zip_write_file_at(&out_zip, offset, buffer, size);
}
else
{
sys_write(out_file, offset, buffer, size);
}
}
void out_set_offset(uint64_t offset)
{
if (out_zipped)
{
zip_set_offset(&out_zip, offset);
}
else
{
out_file_offset = offset;
}
}
uint32_t out_zip_get_crc32(void)
{
if (out_zipped)
{
return zip_get_crc32(&out_zip);
}
return 0;
}
void out_zip_set_crc32(uint32_t crc)
{
if (out_zipped)
{
zip_set_crc32(&out_zip, crc);
}
}