zipruby 0.2.9 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of zipruby might be problematic. Click here for more details.
- data/LICENSE.libzip +27 -0
- data/README.txt +3 -3
- data/ext/tmpfile.c +175 -173
- data/ext/tmpfile.h +9 -9
- data/ext/zip.h +1 -1
- data/ext/zip_error_to_str.c +2 -0
- data/ext/zipint.h +1 -1
- data/ext/zipruby.c +18 -18
- data/ext/zipruby.h +28 -25
- data/ext/zipruby_archive.c +1330 -1326
- data/ext/zipruby_archive.h +23 -23
- data/ext/zipruby_error.c +10 -10
- data/ext/zipruby_error.h +6 -6
- data/ext/zipruby_file.c +398 -404
- data/ext/zipruby_file.h +23 -23
- data/ext/zipruby_stat.c +164 -164
- data/ext/zipruby_stat.h +12 -12
- data/ext/zipruby_zip.c +38 -38
- data/ext/zipruby_zip.h +6 -6
- data/ext/zipruby_zip_source_proc.c +67 -67
- data/ext/zipruby_zip_source_proc.h +14 -14
- data/zipruby.c +2200 -2200
- metadata +5 -6
- data/ext/libzip.mswin32.patch +0 -113
- data/ext/libzip.vcproj +0 -312
- data/ext/libzip.vcproj.LENOVO-72DB7FA8.sugawara.user +0 -37
data/ext/zipruby_file.h
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
#ifndef __ZIPRUBY_FILE_H__
|
2
|
-
#define __ZIPRUBY_FILE_H__
|
3
|
-
|
4
|
-
#include "zip.h"
|
5
|
-
#include "ruby.h"
|
6
|
-
|
7
|
-
struct zipruby_file {
|
8
|
-
VALUE v_archive;
|
9
|
-
struct zip *archive;
|
10
|
-
struct zip_file *file;
|
11
|
-
VALUE v_sb;
|
12
|
-
struct zip_stat *sb;
|
13
|
-
};
|
14
|
-
|
15
|
-
void Init_zipruby_file();
|
16
|
-
|
17
|
-
#define Check_File(p) do { \
|
18
|
-
if ((p)->archive == NULL || (p)->file == NULL || (p)->sb == NULL) { \
|
19
|
-
rb_raise(rb_eRuntimeError, "invalid Zip::File"); \
|
20
|
-
} \
|
21
|
-
} while(0)
|
22
|
-
|
23
|
-
#endif
|
1
|
+
#ifndef __ZIPRUBY_FILE_H__
|
2
|
+
#define __ZIPRUBY_FILE_H__
|
3
|
+
|
4
|
+
#include "zip.h"
|
5
|
+
#include "ruby.h"
|
6
|
+
|
7
|
+
struct zipruby_file {
|
8
|
+
VALUE v_archive;
|
9
|
+
struct zip *archive;
|
10
|
+
struct zip_file *file;
|
11
|
+
VALUE v_sb;
|
12
|
+
struct zip_stat *sb;
|
13
|
+
};
|
14
|
+
|
15
|
+
void Init_zipruby_file();
|
16
|
+
|
17
|
+
#define Check_File(p) do { \
|
18
|
+
if ((p)->archive == NULL || (p)->file == NULL || (p)->sb == NULL) { \
|
19
|
+
rb_raise(rb_eRuntimeError, "invalid Zip::File"); \
|
20
|
+
} \
|
21
|
+
} while(0)
|
22
|
+
|
23
|
+
#endif
|
data/ext/zipruby_stat.c
CHANGED
@@ -1,164 +1,164 @@
|
|
1
|
-
#include "zip.h"
|
2
|
-
#include "zipruby.h"
|
3
|
-
#include "zipruby_archive.h"
|
4
|
-
#include "zipruby_stat.h"
|
5
|
-
#include "ruby.h"
|
6
|
-
|
7
|
-
static VALUE zipruby_stat_alloc(VALUE klass);
|
8
|
-
static void zipruby_stat_free(struct zipruby_stat *p);
|
9
|
-
static VALUE zipruby_stat_initialize(int argc, VALUE *argv, VALUE self);
|
10
|
-
static VALUE zipruby_stat_name(VALUE self);
|
11
|
-
static VALUE zipruby_stat_index(VALUE self);
|
12
|
-
static VALUE zipruby_stat_crc(VALUE self);
|
13
|
-
static VALUE zipruby_stat_size(VALUE self);
|
14
|
-
static VALUE zipruby_stat_mtime(VALUE self);
|
15
|
-
static VALUE zipruby_stat_comp_size(VALUE self);
|
16
|
-
static VALUE zipruby_stat_comp_method(VALUE self);
|
17
|
-
static VALUE zipruby_stat_encryption_method(VALUE self);
|
18
|
-
|
19
|
-
extern VALUE Zip;
|
20
|
-
extern VALUE Archive;
|
21
|
-
VALUE Stat;
|
22
|
-
extern VALUE Error;
|
23
|
-
|
24
|
-
void Init_zipruby_stat() {
|
25
|
-
Stat = rb_define_class_under(Zip, "Stat", rb_cObject);
|
26
|
-
rb_define_alloc_func(Stat, zipruby_stat_alloc);
|
27
|
-
rb_define_method(Stat, "initialize", zipruby_stat_initialize, -1);
|
28
|
-
rb_define_method(Stat, "name", zipruby_stat_name, 0);
|
29
|
-
rb_define_method(Stat, "index", zipruby_stat_index, 0);
|
30
|
-
rb_define_method(Stat, "crc", zipruby_stat_crc, 0);
|
31
|
-
rb_define_method(Stat, "size", zipruby_stat_size, 0);
|
32
|
-
rb_define_method(Stat, "mtime", zipruby_stat_mtime, 0);
|
33
|
-
rb_define_method(Stat, "comp_size", zipruby_stat_comp_size, 0);
|
34
|
-
rb_define_method(Stat, "comp_method", zipruby_stat_comp_method, 0);
|
35
|
-
rb_define_method(Stat, "encryption_method", zipruby_stat_encryption_method, 0);
|
36
|
-
}
|
37
|
-
|
38
|
-
static VALUE zipruby_stat_alloc(VALUE klass) {
|
39
|
-
struct zipruby_stat *p = ALLOC(struct zipruby_stat);
|
40
|
-
|
41
|
-
p->sb = ALLOC(struct zip_stat);
|
42
|
-
zip_stat_init(p->sb);
|
43
|
-
|
44
|
-
return Data_Wrap_Struct(klass, 0, zipruby_stat_free, p);
|
45
|
-
}
|
46
|
-
|
47
|
-
static void zipruby_stat_free(struct zipruby_stat *p) {
|
48
|
-
xfree(p->sb);
|
49
|
-
xfree(p);
|
50
|
-
}
|
51
|
-
|
52
|
-
/* */
|
53
|
-
static VALUE zipruby_stat_initialize(int argc, VALUE *argv, VALUE self) {
|
54
|
-
VALUE archive, index, flags;
|
55
|
-
struct zipruby_archive *p_archive;
|
56
|
-
struct zipruby_stat *p_stat;
|
57
|
-
char *fname = NULL;
|
58
|
-
int i_index = -1, i_flags = 0;
|
59
|
-
|
60
|
-
rb_scan_args(argc, argv, "21", &archive, &index, &flags);
|
61
|
-
|
62
|
-
if (!rb_obj_is_instance_of(archive, Archive)) {
|
63
|
-
rb_raise(rb_eTypeError, "wrong argument type %s (expected Zip::Archive)", rb_class2name(CLASS_OF(archive)));
|
64
|
-
}
|
65
|
-
|
66
|
-
switch (TYPE(index)) {
|
67
|
-
case T_STRING: fname = RSTRING_PTR(index); break;
|
68
|
-
case T_FIXNUM: i_index = NUM2INT(index); break;
|
69
|
-
default:
|
70
|
-
rb_raise(rb_eTypeError, "wrong argument type %s (expected String or Fixnum)", rb_class2name(CLASS_OF(index)));
|
71
|
-
}
|
72
|
-
|
73
|
-
if (!NIL_P(flags)) {
|
74
|
-
i_flags = NUM2INT(flags);
|
75
|
-
}
|
76
|
-
|
77
|
-
Data_Get_Struct(archive, struct zipruby_archive, p_archive);
|
78
|
-
Check_Archive(p_archive);
|
79
|
-
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
80
|
-
|
81
|
-
if (fname) {
|
82
|
-
if (zip_stat(p_archive->archive, fname, i_flags, p_stat->sb) != 0) {
|
83
|
-
rb_raise(Error, "Obtain file status failed - %s: %s", fname, zip_strerror(p_archive->archive));
|
84
|
-
}
|
85
|
-
} else {
|
86
|
-
if (zip_stat_index(p_archive->archive, i_index, i_flags, p_stat->sb) != 0) {
|
87
|
-
rb_raise(Error, "Obtain file status failed at %d: %s", i_index, zip_strerror(p_archive->archive));
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
return Qnil;
|
92
|
-
}
|
93
|
-
|
94
|
-
/* */
|
95
|
-
static VALUE zipruby_stat_name(VALUE self) {
|
96
|
-
struct zipruby_stat *p_stat;
|
97
|
-
|
98
|
-
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
99
|
-
|
100
|
-
return p_stat->sb->name ? rb_str_new2(p_stat->sb->name) : Qnil;
|
101
|
-
}
|
102
|
-
|
103
|
-
/* */
|
104
|
-
static VALUE zipruby_stat_index(VALUE self) {
|
105
|
-
struct zipruby_stat *p_stat;
|
106
|
-
|
107
|
-
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
108
|
-
|
109
|
-
return INT2NUM(p_stat->sb->index);
|
110
|
-
}
|
111
|
-
|
112
|
-
/* */
|
113
|
-
static VALUE zipruby_stat_crc(VALUE self) {
|
114
|
-
struct zipruby_stat *p_stat;
|
115
|
-
|
116
|
-
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
117
|
-
|
118
|
-
return UINT2NUM(p_stat->sb->crc);
|
119
|
-
}
|
120
|
-
|
121
|
-
/* */
|
122
|
-
static VALUE zipruby_stat_size(VALUE self) {
|
123
|
-
struct zipruby_stat *p_stat;
|
124
|
-
|
125
|
-
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
126
|
-
|
127
|
-
return LONG2NUM(p_stat->sb->size);
|
128
|
-
}
|
129
|
-
|
130
|
-
/* */
|
131
|
-
static VALUE zipruby_stat_mtime(VALUE self) {
|
132
|
-
struct zipruby_stat *p_stat;
|
133
|
-
|
134
|
-
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
135
|
-
|
136
|
-
return rb_funcall(rb_cTime, rb_intern("at"), 1, LONG2NUM((long) p_stat->sb->mtime));
|
137
|
-
}
|
138
|
-
|
139
|
-
/* */
|
140
|
-
static VALUE zipruby_stat_comp_size(VALUE self) {
|
141
|
-
struct zipruby_stat *p_stat;
|
142
|
-
|
143
|
-
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
144
|
-
|
145
|
-
return LONG2NUM(p_stat->sb->comp_size);
|
146
|
-
}
|
147
|
-
|
148
|
-
/* */
|
149
|
-
static VALUE zipruby_stat_comp_method(VALUE self) {
|
150
|
-
struct zipruby_stat *p_stat;
|
151
|
-
|
152
|
-
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
153
|
-
|
154
|
-
return INT2NUM(p_stat->sb->comp_method);
|
155
|
-
}
|
156
|
-
|
157
|
-
/* */
|
158
|
-
static VALUE zipruby_stat_encryption_method(VALUE self) {
|
159
|
-
struct zipruby_stat *p_stat;
|
160
|
-
|
161
|
-
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
162
|
-
|
163
|
-
return INT2NUM(p_stat->sb->encryption_method);
|
164
|
-
}
|
1
|
+
#include "zip.h"
|
2
|
+
#include "zipruby.h"
|
3
|
+
#include "zipruby_archive.h"
|
4
|
+
#include "zipruby_stat.h"
|
5
|
+
#include "ruby.h"
|
6
|
+
|
7
|
+
static VALUE zipruby_stat_alloc(VALUE klass);
|
8
|
+
static void zipruby_stat_free(struct zipruby_stat *p);
|
9
|
+
static VALUE zipruby_stat_initialize(int argc, VALUE *argv, VALUE self);
|
10
|
+
static VALUE zipruby_stat_name(VALUE self);
|
11
|
+
static VALUE zipruby_stat_index(VALUE self);
|
12
|
+
static VALUE zipruby_stat_crc(VALUE self);
|
13
|
+
static VALUE zipruby_stat_size(VALUE self);
|
14
|
+
static VALUE zipruby_stat_mtime(VALUE self);
|
15
|
+
static VALUE zipruby_stat_comp_size(VALUE self);
|
16
|
+
static VALUE zipruby_stat_comp_method(VALUE self);
|
17
|
+
static VALUE zipruby_stat_encryption_method(VALUE self);
|
18
|
+
|
19
|
+
extern VALUE Zip;
|
20
|
+
extern VALUE Archive;
|
21
|
+
VALUE Stat;
|
22
|
+
extern VALUE Error;
|
23
|
+
|
24
|
+
void Init_zipruby_stat() {
|
25
|
+
Stat = rb_define_class_under(Zip, "Stat", rb_cObject);
|
26
|
+
rb_define_alloc_func(Stat, zipruby_stat_alloc);
|
27
|
+
rb_define_method(Stat, "initialize", zipruby_stat_initialize, -1);
|
28
|
+
rb_define_method(Stat, "name", zipruby_stat_name, 0);
|
29
|
+
rb_define_method(Stat, "index", zipruby_stat_index, 0);
|
30
|
+
rb_define_method(Stat, "crc", zipruby_stat_crc, 0);
|
31
|
+
rb_define_method(Stat, "size", zipruby_stat_size, 0);
|
32
|
+
rb_define_method(Stat, "mtime", zipruby_stat_mtime, 0);
|
33
|
+
rb_define_method(Stat, "comp_size", zipruby_stat_comp_size, 0);
|
34
|
+
rb_define_method(Stat, "comp_method", zipruby_stat_comp_method, 0);
|
35
|
+
rb_define_method(Stat, "encryption_method", zipruby_stat_encryption_method, 0);
|
36
|
+
}
|
37
|
+
|
38
|
+
static VALUE zipruby_stat_alloc(VALUE klass) {
|
39
|
+
struct zipruby_stat *p = ALLOC(struct zipruby_stat);
|
40
|
+
|
41
|
+
p->sb = ALLOC(struct zip_stat);
|
42
|
+
zip_stat_init(p->sb);
|
43
|
+
|
44
|
+
return Data_Wrap_Struct(klass, 0, zipruby_stat_free, p);
|
45
|
+
}
|
46
|
+
|
47
|
+
static void zipruby_stat_free(struct zipruby_stat *p) {
|
48
|
+
xfree(p->sb);
|
49
|
+
xfree(p);
|
50
|
+
}
|
51
|
+
|
52
|
+
/* */
|
53
|
+
static VALUE zipruby_stat_initialize(int argc, VALUE *argv, VALUE self) {
|
54
|
+
VALUE archive, index, flags;
|
55
|
+
struct zipruby_archive *p_archive;
|
56
|
+
struct zipruby_stat *p_stat;
|
57
|
+
char *fname = NULL;
|
58
|
+
int i_index = -1, i_flags = 0;
|
59
|
+
|
60
|
+
rb_scan_args(argc, argv, "21", &archive, &index, &flags);
|
61
|
+
|
62
|
+
if (!rb_obj_is_instance_of(archive, Archive)) {
|
63
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected Zip::Archive)", rb_class2name(CLASS_OF(archive)));
|
64
|
+
}
|
65
|
+
|
66
|
+
switch (TYPE(index)) {
|
67
|
+
case T_STRING: fname = RSTRING_PTR(index); break;
|
68
|
+
case T_FIXNUM: i_index = NUM2INT(index); break;
|
69
|
+
default:
|
70
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected String or Fixnum)", rb_class2name(CLASS_OF(index)));
|
71
|
+
}
|
72
|
+
|
73
|
+
if (!NIL_P(flags)) {
|
74
|
+
i_flags = NUM2INT(flags);
|
75
|
+
}
|
76
|
+
|
77
|
+
Data_Get_Struct(archive, struct zipruby_archive, p_archive);
|
78
|
+
Check_Archive(p_archive);
|
79
|
+
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
80
|
+
|
81
|
+
if (fname) {
|
82
|
+
if (zip_stat(p_archive->archive, fname, i_flags, p_stat->sb) != 0) {
|
83
|
+
rb_raise(Error, "Obtain file status failed - %s: %s", fname, zip_strerror(p_archive->archive));
|
84
|
+
}
|
85
|
+
} else {
|
86
|
+
if (zip_stat_index(p_archive->archive, i_index, i_flags, p_stat->sb) != 0) {
|
87
|
+
rb_raise(Error, "Obtain file status failed at %d: %s", i_index, zip_strerror(p_archive->archive));
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
return Qnil;
|
92
|
+
}
|
93
|
+
|
94
|
+
/* */
|
95
|
+
static VALUE zipruby_stat_name(VALUE self) {
|
96
|
+
struct zipruby_stat *p_stat;
|
97
|
+
|
98
|
+
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
99
|
+
|
100
|
+
return p_stat->sb->name ? rb_str_new2(p_stat->sb->name) : Qnil;
|
101
|
+
}
|
102
|
+
|
103
|
+
/* */
|
104
|
+
static VALUE zipruby_stat_index(VALUE self) {
|
105
|
+
struct zipruby_stat *p_stat;
|
106
|
+
|
107
|
+
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
108
|
+
|
109
|
+
return INT2NUM(p_stat->sb->index);
|
110
|
+
}
|
111
|
+
|
112
|
+
/* */
|
113
|
+
static VALUE zipruby_stat_crc(VALUE self) {
|
114
|
+
struct zipruby_stat *p_stat;
|
115
|
+
|
116
|
+
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
117
|
+
|
118
|
+
return UINT2NUM(p_stat->sb->crc);
|
119
|
+
}
|
120
|
+
|
121
|
+
/* */
|
122
|
+
static VALUE zipruby_stat_size(VALUE self) {
|
123
|
+
struct zipruby_stat *p_stat;
|
124
|
+
|
125
|
+
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
126
|
+
|
127
|
+
return LONG2NUM(p_stat->sb->size);
|
128
|
+
}
|
129
|
+
|
130
|
+
/* */
|
131
|
+
static VALUE zipruby_stat_mtime(VALUE self) {
|
132
|
+
struct zipruby_stat *p_stat;
|
133
|
+
|
134
|
+
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
135
|
+
|
136
|
+
return rb_funcall(rb_cTime, rb_intern("at"), 1, LONG2NUM((long) p_stat->sb->mtime));
|
137
|
+
}
|
138
|
+
|
139
|
+
/* */
|
140
|
+
static VALUE zipruby_stat_comp_size(VALUE self) {
|
141
|
+
struct zipruby_stat *p_stat;
|
142
|
+
|
143
|
+
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
144
|
+
|
145
|
+
return LONG2NUM(p_stat->sb->comp_size);
|
146
|
+
}
|
147
|
+
|
148
|
+
/* */
|
149
|
+
static VALUE zipruby_stat_comp_method(VALUE self) {
|
150
|
+
struct zipruby_stat *p_stat;
|
151
|
+
|
152
|
+
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
153
|
+
|
154
|
+
return INT2NUM(p_stat->sb->comp_method);
|
155
|
+
}
|
156
|
+
|
157
|
+
/* */
|
158
|
+
static VALUE zipruby_stat_encryption_method(VALUE self) {
|
159
|
+
struct zipruby_stat *p_stat;
|
160
|
+
|
161
|
+
Data_Get_Struct(self, struct zipruby_stat, p_stat);
|
162
|
+
|
163
|
+
return INT2NUM(p_stat->sb->encryption_method);
|
164
|
+
}
|
data/ext/zipruby_stat.h
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
#ifndef __ZIPRUBY_STAT_H__
|
2
|
-
#define __ZIPRUBY_STAT_H__
|
3
|
-
|
4
|
-
#include "zip.h"
|
5
|
-
|
6
|
-
struct zipruby_stat {
|
7
|
-
struct zip_stat *sb;
|
8
|
-
};
|
9
|
-
|
10
|
-
void Init_zipruby_stat();
|
11
|
-
|
12
|
-
#endif
|
1
|
+
#ifndef __ZIPRUBY_STAT_H__
|
2
|
+
#define __ZIPRUBY_STAT_H__
|
3
|
+
|
4
|
+
#include "zip.h"
|
5
|
+
|
6
|
+
struct zipruby_stat {
|
7
|
+
struct zip_stat *sb;
|
8
|
+
};
|
9
|
+
|
10
|
+
void Init_zipruby_stat();
|
11
|
+
|
12
|
+
#endif
|
data/ext/zipruby_zip.c
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
#include "ruby.h"
|
2
|
-
#include "zip.h"
|
3
|
-
#include "zipruby.h"
|
4
|
-
#include "zipruby_zip.h"
|
5
|
-
|
6
|
-
VALUE Zip;
|
7
|
-
|
8
|
-
void Init_zipruby_zip() {
|
9
|
-
Zip = rb_define_module("Zip");
|
10
|
-
rb_define_const(Zip, "VERSION", rb_str_new2(VERSION));
|
11
|
-
|
12
|
-
rb_define_const(Zip, "CREATE", INT2NUM(ZIP_CREATE));
|
13
|
-
rb_define_const(Zip, "EXCL", INT2NUM(ZIP_EXCL));
|
14
|
-
rb_define_const(Zip, "CHECKCONS", INT2NUM(ZIP_CHECKCONS));
|
15
|
-
rb_define_const(Zip, "TRUNC", INT2NUM(ZIP_TRUNC));
|
16
|
-
|
17
|
-
rb_define_const(Zip, "FL_NOCASE", INT2NUM(ZIP_FL_NOCASE));
|
18
|
-
rb_define_const(Zip, "FL_NODIR", INT2NUM(ZIP_FL_NODIR));
|
19
|
-
rb_define_const(Zip, "FL_COMPRESSED", INT2NUM(ZIP_FL_COMPRESSED));
|
20
|
-
rb_define_const(Zip, "FL_UNCHANGED", INT2NUM(ZIP_FL_UNCHANGED));
|
21
|
-
|
22
|
-
rb_define_const(Zip, "CM_DEFAULT" , INT2NUM(ZIP_CM_DEFAULT));
|
23
|
-
rb_define_const(Zip, "CM_STORE", INT2NUM(ZIP_CM_STORE));
|
24
|
-
rb_define_const(Zip, "CM_SHRINK", INT2NUM(ZIP_CM_SHRINK));
|
25
|
-
rb_define_const(Zip, "CM_REDUCE_1", INT2NUM(ZIP_CM_REDUCE_1));
|
26
|
-
rb_define_const(Zip, "CM_REDUCE_2", INT2NUM(ZIP_CM_REDUCE_2));
|
27
|
-
rb_define_const(Zip, "CM_REDUCE_3", INT2NUM(ZIP_CM_REDUCE_3));
|
28
|
-
rb_define_const(Zip, "CM_REDUCE_4", INT2NUM(ZIP_CM_REDUCE_4));
|
29
|
-
rb_define_const(Zip, "CM_IMPLODE", INT2NUM(ZIP_CM_IMPLODE));
|
30
|
-
rb_define_const(Zip, "CM_DEFLATE", INT2NUM(ZIP_CM_DEFLATE));
|
31
|
-
rb_define_const(Zip, "CM_DEFLATE64", INT2NUM(ZIP_CM_DEFLATE64));
|
32
|
-
rb_define_const(Zip, "CM_PKWARE_IMPLODE", INT2NUM(ZIP_CM_PKWARE_IMPLODE));
|
33
|
-
rb_define_const(Zip, "CM_BZIP2", INT2NUM(ZIP_CM_BZIP2));
|
34
|
-
|
35
|
-
rb_define_const(Zip, "EM_NONE", INT2NUM(ZIP_EM_NONE));
|
36
|
-
rb_define_const(Zip, "EM_TRAD_PKWARE", INT2NUM(ZIP_EM_TRAD_PKWARE));
|
37
|
-
// XXX: Strong Encryption Header not parsed yet
|
38
|
-
}
|
1
|
+
#include "ruby.h"
|
2
|
+
#include "zip.h"
|
3
|
+
#include "zipruby.h"
|
4
|
+
#include "zipruby_zip.h"
|
5
|
+
|
6
|
+
VALUE Zip;
|
7
|
+
|
8
|
+
void Init_zipruby_zip() {
|
9
|
+
Zip = rb_define_module("Zip");
|
10
|
+
rb_define_const(Zip, "VERSION", rb_str_new2(VERSION));
|
11
|
+
|
12
|
+
rb_define_const(Zip, "CREATE", INT2NUM(ZIP_CREATE));
|
13
|
+
rb_define_const(Zip, "EXCL", INT2NUM(ZIP_EXCL));
|
14
|
+
rb_define_const(Zip, "CHECKCONS", INT2NUM(ZIP_CHECKCONS));
|
15
|
+
rb_define_const(Zip, "TRUNC", INT2NUM(ZIP_TRUNC));
|
16
|
+
|
17
|
+
rb_define_const(Zip, "FL_NOCASE", INT2NUM(ZIP_FL_NOCASE));
|
18
|
+
rb_define_const(Zip, "FL_NODIR", INT2NUM(ZIP_FL_NODIR));
|
19
|
+
rb_define_const(Zip, "FL_COMPRESSED", INT2NUM(ZIP_FL_COMPRESSED));
|
20
|
+
rb_define_const(Zip, "FL_UNCHANGED", INT2NUM(ZIP_FL_UNCHANGED));
|
21
|
+
|
22
|
+
rb_define_const(Zip, "CM_DEFAULT" , INT2NUM(ZIP_CM_DEFAULT));
|
23
|
+
rb_define_const(Zip, "CM_STORE", INT2NUM(ZIP_CM_STORE));
|
24
|
+
rb_define_const(Zip, "CM_SHRINK", INT2NUM(ZIP_CM_SHRINK));
|
25
|
+
rb_define_const(Zip, "CM_REDUCE_1", INT2NUM(ZIP_CM_REDUCE_1));
|
26
|
+
rb_define_const(Zip, "CM_REDUCE_2", INT2NUM(ZIP_CM_REDUCE_2));
|
27
|
+
rb_define_const(Zip, "CM_REDUCE_3", INT2NUM(ZIP_CM_REDUCE_3));
|
28
|
+
rb_define_const(Zip, "CM_REDUCE_4", INT2NUM(ZIP_CM_REDUCE_4));
|
29
|
+
rb_define_const(Zip, "CM_IMPLODE", INT2NUM(ZIP_CM_IMPLODE));
|
30
|
+
rb_define_const(Zip, "CM_DEFLATE", INT2NUM(ZIP_CM_DEFLATE));
|
31
|
+
rb_define_const(Zip, "CM_DEFLATE64", INT2NUM(ZIP_CM_DEFLATE64));
|
32
|
+
rb_define_const(Zip, "CM_PKWARE_IMPLODE", INT2NUM(ZIP_CM_PKWARE_IMPLODE));
|
33
|
+
rb_define_const(Zip, "CM_BZIP2", INT2NUM(ZIP_CM_BZIP2));
|
34
|
+
|
35
|
+
rb_define_const(Zip, "EM_NONE", INT2NUM(ZIP_EM_NONE));
|
36
|
+
rb_define_const(Zip, "EM_TRAD_PKWARE", INT2NUM(ZIP_EM_TRAD_PKWARE));
|
37
|
+
// XXX: Strong Encryption Header not parsed yet
|
38
|
+
}
|
data/ext/zipruby_zip.h
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#ifndef __ZIPRUBY_ZIP_H__
|
2
|
-
#define __ZIPRUBY_ZIP_H__
|
3
|
-
|
4
|
-
void Init_zipruby_zip();
|
5
|
-
|
6
|
-
#endif
|
1
|
+
#ifndef __ZIPRUBY_ZIP_H__
|
2
|
+
#define __ZIPRUBY_ZIP_H__
|
3
|
+
|
4
|
+
void Init_zipruby_zip();
|
5
|
+
|
6
|
+
#endif
|
@@ -1,67 +1,67 @@
|
|
1
|
-
#include <string.h>
|
2
|
-
|
3
|
-
#include "zip.h"
|
4
|
-
#include "zipint.h"
|
5
|
-
#include "zipruby_zip_source_proc.h"
|
6
|
-
#include "ruby.h"
|
7
|
-
|
8
|
-
static VALUE proc_call(VALUE proc) {
|
9
|
-
return rb_funcall(proc, rb_intern("call"), 0);
|
10
|
-
}
|
11
|
-
|
12
|
-
static ssize_t read_proc(void *state, void *data, size_t len, enum zip_source_cmd cmd) {
|
13
|
-
struct read_proc *z;
|
14
|
-
VALUE src;
|
15
|
-
char *buf;
|
16
|
-
size_t n;
|
17
|
-
|
18
|
-
z = (struct read_proc *) state;
|
19
|
-
buf = (char *) data;
|
20
|
-
|
21
|
-
switch (cmd) {
|
22
|
-
case ZIP_SOURCE_OPEN:
|
23
|
-
return 0;
|
24
|
-
|
25
|
-
case ZIP_SOURCE_READ:
|
26
|
-
src = rb_protect(proc_call, z->proc, NULL);
|
27
|
-
|
28
|
-
if (TYPE(src) != T_STRING) {
|
29
|
-
return 0;
|
30
|
-
}
|
31
|
-
|
32
|
-
n = RSTRING_LEN(src);
|
33
|
-
|
34
|
-
if (n > 0) {
|
35
|
-
n = (n > len) ? len : n;
|
36
|
-
memcpy(buf, RSTRING_PTR(src), n);
|
37
|
-
}
|
38
|
-
|
39
|
-
return n;
|
40
|
-
|
41
|
-
case ZIP_SOURCE_CLOSE:
|
42
|
-
return 0;
|
43
|
-
|
44
|
-
case ZIP_SOURCE_STAT:
|
45
|
-
{
|
46
|
-
struct zip_stat *st = (struct zip_stat *)data;
|
47
|
-
zip_stat_init(st);
|
48
|
-
st->mtime = NUM2LONG(rb_funcall(z->mtime, rb_intern("tv_sec"), 0));
|
49
|
-
return sizeof(*st);
|
50
|
-
}
|
51
|
-
|
52
|
-
case ZIP_SOURCE_ERROR:
|
53
|
-
return 0;
|
54
|
-
|
55
|
-
case ZIP_SOURCE_FREE:
|
56
|
-
free(z);
|
57
|
-
return 0;
|
58
|
-
}
|
59
|
-
|
60
|
-
return -1;
|
61
|
-
}
|
62
|
-
|
63
|
-
struct zip_source *zip_source_proc(struct zip *za, struct read_proc *z) {
|
64
|
-
struct zip_source *zs;
|
65
|
-
zs = zip_source_function(za, read_proc, z);
|
66
|
-
return zs;
|
67
|
-
}
|
1
|
+
#include <string.h>
|
2
|
+
|
3
|
+
#include "zip.h"
|
4
|
+
#include "zipint.h"
|
5
|
+
#include "zipruby_zip_source_proc.h"
|
6
|
+
#include "ruby.h"
|
7
|
+
|
8
|
+
static VALUE proc_call(VALUE proc) {
|
9
|
+
return rb_funcall(proc, rb_intern("call"), 0);
|
10
|
+
}
|
11
|
+
|
12
|
+
static ssize_t read_proc(void *state, void *data, size_t len, enum zip_source_cmd cmd) {
|
13
|
+
struct read_proc *z;
|
14
|
+
VALUE src;
|
15
|
+
char *buf;
|
16
|
+
size_t n;
|
17
|
+
|
18
|
+
z = (struct read_proc *) state;
|
19
|
+
buf = (char *) data;
|
20
|
+
|
21
|
+
switch (cmd) {
|
22
|
+
case ZIP_SOURCE_OPEN:
|
23
|
+
return 0;
|
24
|
+
|
25
|
+
case ZIP_SOURCE_READ:
|
26
|
+
src = rb_protect(proc_call, z->proc, NULL);
|
27
|
+
|
28
|
+
if (TYPE(src) != T_STRING) {
|
29
|
+
return 0;
|
30
|
+
}
|
31
|
+
|
32
|
+
n = RSTRING_LEN(src);
|
33
|
+
|
34
|
+
if (n > 0) {
|
35
|
+
n = (n > len) ? len : n;
|
36
|
+
memcpy(buf, RSTRING_PTR(src), n);
|
37
|
+
}
|
38
|
+
|
39
|
+
return n;
|
40
|
+
|
41
|
+
case ZIP_SOURCE_CLOSE:
|
42
|
+
return 0;
|
43
|
+
|
44
|
+
case ZIP_SOURCE_STAT:
|
45
|
+
{
|
46
|
+
struct zip_stat *st = (struct zip_stat *)data;
|
47
|
+
zip_stat_init(st);
|
48
|
+
st->mtime = NUM2LONG(rb_funcall(z->mtime, rb_intern("tv_sec"), 0));
|
49
|
+
return sizeof(*st);
|
50
|
+
}
|
51
|
+
|
52
|
+
case ZIP_SOURCE_ERROR:
|
53
|
+
return 0;
|
54
|
+
|
55
|
+
case ZIP_SOURCE_FREE:
|
56
|
+
free(z);
|
57
|
+
return 0;
|
58
|
+
}
|
59
|
+
|
60
|
+
return -1;
|
61
|
+
}
|
62
|
+
|
63
|
+
struct zip_source *zip_source_proc(struct zip *za, struct read_proc *z) {
|
64
|
+
struct zip_source *zs;
|
65
|
+
zs = zip_source_function(za, read_proc, z);
|
66
|
+
return zs;
|
67
|
+
}
|
@@ -1,14 +1,14 @@
|
|
1
|
-
#ifndef __ZIPRUBY_ZIP_SOURCE_PROC_H__
|
2
|
-
#define __ZIPRUBY_ZIP_SOURCE_PROC_H__
|
3
|
-
|
4
|
-
#include "zip.h"
|
5
|
-
#include "ruby.h"
|
6
|
-
|
7
|
-
struct read_proc {
|
8
|
-
VALUE proc;
|
9
|
-
VALUE mtime;
|
10
|
-
};
|
11
|
-
|
12
|
-
struct zip_source *zip_source_proc(struct zip *za, struct read_proc *z);
|
13
|
-
|
14
|
-
#endif
|
1
|
+
#ifndef __ZIPRUBY_ZIP_SOURCE_PROC_H__
|
2
|
+
#define __ZIPRUBY_ZIP_SOURCE_PROC_H__
|
3
|
+
|
4
|
+
#include "zip.h"
|
5
|
+
#include "ruby.h"
|
6
|
+
|
7
|
+
struct read_proc {
|
8
|
+
VALUE proc;
|
9
|
+
VALUE mtime;
|
10
|
+
};
|
11
|
+
|
12
|
+
struct zip_source *zip_source_proc(struct zip *za, struct read_proc *z);
|
13
|
+
|
14
|
+
#endif
|