zipruby 0.3.4 → 0.3.5
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/README.txt +5 -0
- data/ext/zip_close.c +13 -4
- data/ext/zip_new.c +1 -0
- data/ext/zipint.h +2 -0
- data/ext/zipruby.h +1 -1
- data/ext/zipruby_archive.c +33 -6
- data/ext/zipruby_zip.c +7 -0
- data/zipruby.c +40 -6
- metadata +2 -2
data/README.txt
CHANGED
@@ -72,6 +72,7 @@ https://rubyforge.org/frs/?group_id=6124
|
|
72
72
|
|
73
73
|
Zip::Archive.open('filename.zip', Zip::CREATE) do |ar|
|
74
74
|
# if overwrite: ..., Zip::CREATE | Zip::TRUNC) do |ar|
|
75
|
+
# specifies compression level: ..., Zip::CREATE, Zip::BEST_SPEED) do |ar|
|
75
76
|
|
76
77
|
ar.add_file('foo.txt') # add file to zip archive
|
77
78
|
|
@@ -183,6 +184,10 @@ https://rubyforge.org/frs/?group_id=6124
|
|
183
184
|
Zip::Archive.open_buffer(buf, Zip::CREATE) do |ar|
|
184
185
|
ar.add_buffer('bar.txt', 'zoo');
|
185
186
|
end
|
187
|
+
|
188
|
+
buf2 = Zip::Archive.open_buffer(Zip::CREATE) do |ar|
|
189
|
+
ar.add_buffer('bar.txt', 'zoo');
|
190
|
+
end
|
186
191
|
|
187
192
|
Zip::Archive.open_buffer(buf) do |ar|
|
188
193
|
ar.each do |f|
|
data/ext/zip_close.c
CHANGED
@@ -55,8 +55,11 @@
|
|
55
55
|
static int add_data(struct zip *, int, struct zip_dirent *, FILE *);
|
56
56
|
static int add_data_comp(zip_source_callback, void *, struct zip_stat *,
|
57
57
|
FILE *, struct zip_error *);
|
58
|
+
// modified for Zip/Ruby by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
59
|
+
//static int add_data_uncomp(zip_source_callback, void *, struct zip_stat *,
|
60
|
+
// FILE *, struct zip_error *);
|
58
61
|
static int add_data_uncomp(zip_source_callback, void *, struct zip_stat *,
|
59
|
-
FILE *, struct zip_error
|
62
|
+
FILE *, struct zip_error *, int comp_level);
|
60
63
|
static void ch_set_error(struct zip_error *, zip_source_callback, void *);
|
61
64
|
// modified for Zip/Ruby by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
62
65
|
//static int copy_data(FILE *, off_t, FILE *, struct zip_error *);
|
@@ -297,7 +300,7 @@ add_data(struct zip *za, int idx, struct zip_dirent *de, FILE *ft)
|
|
297
300
|
return -1;
|
298
301
|
}
|
299
302
|
else {
|
300
|
-
if (add_data_uncomp(cb, ud, &st, ft, &za->error) < 0)
|
303
|
+
if (add_data_uncomp(cb, ud, &st, ft, &za->error, za->comp_level) < 0)
|
301
304
|
return -1;
|
302
305
|
}
|
303
306
|
|
@@ -358,9 +361,13 @@ add_data_comp(zip_source_callback cb, void *ud, struct zip_stat *st,FILE *ft,
|
|
358
361
|
|
359
362
|
|
360
363
|
|
364
|
+
// modified for Zip/Ruby by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
365
|
+
//static int
|
366
|
+
//add_data_uncomp(zip_source_callback cb, void *ud, struct zip_stat *st,
|
367
|
+
// FILE *ft, struct zip_error *error)
|
361
368
|
static int
|
362
369
|
add_data_uncomp(zip_source_callback cb, void *ud, struct zip_stat *st,
|
363
|
-
FILE *ft, struct zip_error *error)
|
370
|
+
FILE *ft, struct zip_error *error, int comp_level)
|
364
371
|
{
|
365
372
|
char b1[BUFSIZE], b2[BUFSIZE];
|
366
373
|
int end, flush, ret;
|
@@ -379,7 +386,9 @@ add_data_uncomp(zip_source_callback cb, void *ud, struct zip_stat *st,
|
|
379
386
|
zstr.avail_out = 0;
|
380
387
|
|
381
388
|
/* -15: undocumented feature of zlib to _not_ write a zlib header */
|
382
|
-
|
389
|
+
// modified for Zip/Ruby by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
390
|
+
//deflateInit2(&zstr, Z_BEST_COMPRESSION, Z_DEFLATED, -15, 9,
|
391
|
+
deflateInit2(&zstr, comp_level, Z_DEFLATED, -15, 9,
|
383
392
|
Z_DEFAULT_STRATEGY);
|
384
393
|
|
385
394
|
zstr.next_out = (Bytef *)b2;
|
data/ext/zip_new.c
CHANGED
data/ext/zipint.h
CHANGED
@@ -112,6 +112,8 @@ struct zip {
|
|
112
112
|
int nfile; /* number of opened files within archive */
|
113
113
|
int nfile_alloc; /* number of files allocated */
|
114
114
|
struct zip_file **file; /* opened files within archive */
|
115
|
+
// modified for Zip/Ruby by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
116
|
+
int comp_level;
|
115
117
|
};
|
116
118
|
|
117
119
|
/* file in zip archive, part of API */
|
data/ext/zipruby.h
CHANGED
data/ext/zipruby_archive.c
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
#include <errno.h>
|
2
|
+
#include <zlib.h>
|
2
3
|
|
3
4
|
#include "zip.h"
|
5
|
+
#include "zipint.h"
|
4
6
|
#include "zipruby.h"
|
5
7
|
#include "zipruby_archive.h"
|
6
8
|
#include "zipruby_zip_source_proc.h"
|
@@ -140,19 +142,28 @@ static void zipruby_archive_free(struct zipruby_archive *p) {
|
|
140
142
|
|
141
143
|
/* */
|
142
144
|
static VALUE zipruby_archive_s_open(int argc, VALUE *argv, VALUE self) {
|
143
|
-
VALUE path, flags;
|
145
|
+
VALUE path, flags, comp_level;
|
144
146
|
VALUE archive;
|
145
147
|
struct zipruby_archive *p_archive;
|
146
148
|
int i_flags = 0;
|
147
149
|
int errorp;
|
150
|
+
int i_comp_level = Z_BEST_COMPRESSION;
|
148
151
|
|
149
|
-
rb_scan_args(argc, argv, "
|
152
|
+
rb_scan_args(argc, argv, "12", &path, &flags, &comp_level);
|
150
153
|
Check_Type(path, T_STRING);
|
151
154
|
|
152
155
|
if (!NIL_P(flags)) {
|
153
156
|
i_flags = NUM2INT(flags);
|
154
157
|
}
|
155
158
|
|
159
|
+
if (!NIL_P(comp_level)) {
|
160
|
+
i_comp_level = NUM2INT(comp_level);
|
161
|
+
|
162
|
+
if (i_comp_level != Z_DEFAULT_COMPRESSION && i_comp_level != Z_NO_COMPRESSION && (i_comp_level < Z_BEST_SPEED || Z_BEST_COMPRESSION < i_comp_level)) {
|
163
|
+
rb_raise(rb_eArgError, "Wrong compression level %d", i_comp_level);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
156
167
|
archive = rb_funcall(Archive, rb_intern("new"), 0);
|
157
168
|
Data_Get_Struct(archive, struct zipruby_archive, p_archive);
|
158
169
|
|
@@ -162,6 +173,7 @@ static VALUE zipruby_archive_s_open(int argc, VALUE *argv, VALUE self) {
|
|
162
173
|
rb_raise(Error, "Open archive failed - %s: %s", RSTRING_PTR(path), errstr);
|
163
174
|
}
|
164
175
|
|
176
|
+
p_archive->archive->comp_level = i_comp_level;
|
165
177
|
p_archive->path = path;
|
166
178
|
p_archive->flags = i_flags;
|
167
179
|
p_archive->sources = rb_ary_new();
|
@@ -185,16 +197,19 @@ static VALUE zipruby_archive_s_open(int argc, VALUE *argv, VALUE self) {
|
|
185
197
|
|
186
198
|
/* */
|
187
199
|
static VALUE zipruby_archive_s_open_buffer(int argc, VALUE *argv, VALUE self) {
|
188
|
-
VALUE buffer, flags;
|
200
|
+
VALUE buffer, flags, comp_level;
|
189
201
|
VALUE archive;
|
190
202
|
struct zipruby_archive *p_archive;
|
191
203
|
void *data = NULL;
|
192
204
|
int len = 0, i_flags = 0;
|
193
205
|
int errorp;
|
206
|
+
int i_comp_level = Z_BEST_COMPRESSION;
|
207
|
+
int buffer_is_temporary = 0;
|
194
208
|
|
195
|
-
rb_scan_args(argc, argv, "
|
209
|
+
rb_scan_args(argc, argv, "03", &buffer, &flags, &comp_level);
|
196
210
|
|
197
|
-
if (FIXNUM_P(buffer) && NIL_P(
|
211
|
+
if (FIXNUM_P(buffer) && NIL_P(comp_level)) {
|
212
|
+
comp_level = flags;
|
198
213
|
flags = buffer;
|
199
214
|
buffer = Qnil;
|
200
215
|
}
|
@@ -203,9 +218,20 @@ static VALUE zipruby_archive_s_open_buffer(int argc, VALUE *argv, VALUE self) {
|
|
203
218
|
i_flags = NUM2INT(flags);
|
204
219
|
}
|
205
220
|
|
221
|
+
if (!NIL_P(comp_level)) {
|
222
|
+
i_comp_level = NUM2INT(comp_level);
|
223
|
+
|
224
|
+
if (i_comp_level != Z_DEFAULT_COMPRESSION && i_comp_level != Z_NO_COMPRESSION && (i_comp_level < Z_BEST_SPEED || Z_BEST_COMPRESSION < i_comp_level)) {
|
225
|
+
rb_raise(rb_eArgError, "Wrong compression level %d", i_comp_level);
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
206
229
|
if (i_flags & ZIP_CREATE) {
|
207
230
|
if (!NIL_P(buffer)) {
|
208
231
|
Check_Type(buffer, T_STRING);
|
232
|
+
} else {
|
233
|
+
buffer = rb_str_new("", 0);
|
234
|
+
buffer_is_temporary = 1;
|
209
235
|
}
|
210
236
|
|
211
237
|
i_flags = (i_flags | ZIP_TRUNC);
|
@@ -232,6 +258,7 @@ static VALUE zipruby_archive_s_open_buffer(int argc, VALUE *argv, VALUE self) {
|
|
232
258
|
rb_raise(Error, "Open archive failed: %s", errstr);
|
233
259
|
}
|
234
260
|
|
261
|
+
p_archive->archive->comp_level = i_comp_level;
|
235
262
|
p_archive->path = rb_str_new2(p_archive->tmpfilnam);
|
236
263
|
p_archive->flags = i_flags;
|
237
264
|
p_archive->buffer = buffer;
|
@@ -248,7 +275,7 @@ static VALUE zipruby_archive_s_open_buffer(int argc, VALUE *argv, VALUE self) {
|
|
248
275
|
rb_jump_tag(status);
|
249
276
|
}
|
250
277
|
|
251
|
-
return retval;
|
278
|
+
return buffer_is_temporary ? buffer : retval;
|
252
279
|
} else {
|
253
280
|
return archive;
|
254
281
|
}
|
data/ext/zipruby_zip.c
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
#include <zlib.h>
|
2
|
+
|
1
3
|
#include "ruby.h"
|
2
4
|
#include "zip.h"
|
3
5
|
#include "zipruby.h"
|
@@ -35,4 +37,9 @@ void Init_zipruby_zip() {
|
|
35
37
|
rb_define_const(Zip, "EM_NONE", INT2NUM(ZIP_EM_NONE));
|
36
38
|
rb_define_const(Zip, "EM_TRAD_PKWARE", INT2NUM(ZIP_EM_TRAD_PKWARE));
|
37
39
|
// XXX: Strong Encryption Header not parsed yet
|
40
|
+
|
41
|
+
rb_define_const(Zip, "NO_COMPRESSION", INT2NUM(Z_NO_COMPRESSION));
|
42
|
+
rb_define_const(Zip, "BEST_SPEED", INT2NUM(Z_BEST_SPEED));
|
43
|
+
rb_define_const(Zip, "BEST_COMPRESSION", INT2NUM(Z_BEST_COMPRESSION));
|
44
|
+
rb_define_const(Zip, "DEFAULT_COMPRESSION", INT2NUM(Z_DEFAULT_COMPRESSION));
|
38
45
|
}
|
data/zipruby.c
CHANGED
@@ -193,8 +193,10 @@ void Init_zipruby() {
|
|
193
193
|
Init_zipruby_error();
|
194
194
|
}
|
195
195
|
#include <errno.h>
|
196
|
+
#include <zlib.h>
|
196
197
|
|
197
198
|
#include "zip.h"
|
199
|
+
#include "zipint.h"
|
198
200
|
#include "zipruby.h"
|
199
201
|
#include "zipruby_archive.h"
|
200
202
|
#include "zipruby_zip_source_proc.h"
|
@@ -334,19 +336,28 @@ static void zipruby_archive_free(struct zipruby_archive *p) {
|
|
334
336
|
|
335
337
|
/* */
|
336
338
|
static VALUE zipruby_archive_s_open(int argc, VALUE *argv, VALUE self) {
|
337
|
-
VALUE path, flags;
|
339
|
+
VALUE path, flags, comp_level;
|
338
340
|
VALUE archive;
|
339
341
|
struct zipruby_archive *p_archive;
|
340
342
|
int i_flags = 0;
|
341
343
|
int errorp;
|
344
|
+
int i_comp_level = Z_BEST_COMPRESSION;
|
342
345
|
|
343
|
-
rb_scan_args(argc, argv, "
|
346
|
+
rb_scan_args(argc, argv, "12", &path, &flags, &comp_level);
|
344
347
|
Check_Type(path, T_STRING);
|
345
348
|
|
346
349
|
if (!NIL_P(flags)) {
|
347
350
|
i_flags = NUM2INT(flags);
|
348
351
|
}
|
349
352
|
|
353
|
+
if (!NIL_P(comp_level)) {
|
354
|
+
i_comp_level = NUM2INT(comp_level);
|
355
|
+
|
356
|
+
if (i_comp_level != Z_DEFAULT_COMPRESSION && i_comp_level != Z_NO_COMPRESSION && (i_comp_level < Z_BEST_SPEED || Z_BEST_COMPRESSION < i_comp_level)) {
|
357
|
+
rb_raise(rb_eArgError, "Wrong compression level %d", i_comp_level);
|
358
|
+
}
|
359
|
+
}
|
360
|
+
|
350
361
|
archive = rb_funcall(Archive, rb_intern("new"), 0);
|
351
362
|
Data_Get_Struct(archive, struct zipruby_archive, p_archive);
|
352
363
|
|
@@ -356,6 +367,7 @@ static VALUE zipruby_archive_s_open(int argc, VALUE *argv, VALUE self) {
|
|
356
367
|
rb_raise(Error, "Open archive failed - %s: %s", RSTRING_PTR(path), errstr);
|
357
368
|
}
|
358
369
|
|
370
|
+
p_archive->archive->comp_level = i_comp_level;
|
359
371
|
p_archive->path = path;
|
360
372
|
p_archive->flags = i_flags;
|
361
373
|
p_archive->sources = rb_ary_new();
|
@@ -379,16 +391,19 @@ static VALUE zipruby_archive_s_open(int argc, VALUE *argv, VALUE self) {
|
|
379
391
|
|
380
392
|
/* */
|
381
393
|
static VALUE zipruby_archive_s_open_buffer(int argc, VALUE *argv, VALUE self) {
|
382
|
-
VALUE buffer, flags;
|
394
|
+
VALUE buffer, flags, comp_level;
|
383
395
|
VALUE archive;
|
384
396
|
struct zipruby_archive *p_archive;
|
385
397
|
void *data = NULL;
|
386
398
|
int len = 0, i_flags = 0;
|
387
399
|
int errorp;
|
400
|
+
int i_comp_level = Z_BEST_COMPRESSION;
|
401
|
+
int buffer_is_temporary = 0;
|
388
402
|
|
389
|
-
rb_scan_args(argc, argv, "
|
403
|
+
rb_scan_args(argc, argv, "03", &buffer, &flags, &comp_level);
|
390
404
|
|
391
|
-
if (FIXNUM_P(buffer) && NIL_P(
|
405
|
+
if (FIXNUM_P(buffer) && NIL_P(comp_level)) {
|
406
|
+
comp_level = flags;
|
392
407
|
flags = buffer;
|
393
408
|
buffer = Qnil;
|
394
409
|
}
|
@@ -397,9 +412,20 @@ static VALUE zipruby_archive_s_open_buffer(int argc, VALUE *argv, VALUE self) {
|
|
397
412
|
i_flags = NUM2INT(flags);
|
398
413
|
}
|
399
414
|
|
415
|
+
if (!NIL_P(comp_level)) {
|
416
|
+
i_comp_level = NUM2INT(comp_level);
|
417
|
+
|
418
|
+
if (i_comp_level != Z_DEFAULT_COMPRESSION && i_comp_level != Z_NO_COMPRESSION && (i_comp_level < Z_BEST_SPEED || Z_BEST_COMPRESSION < i_comp_level)) {
|
419
|
+
rb_raise(rb_eArgError, "Wrong compression level %d", i_comp_level);
|
420
|
+
}
|
421
|
+
}
|
422
|
+
|
400
423
|
if (i_flags & ZIP_CREATE) {
|
401
424
|
if (!NIL_P(buffer)) {
|
402
425
|
Check_Type(buffer, T_STRING);
|
426
|
+
} else {
|
427
|
+
buffer = rb_str_new("", 0);
|
428
|
+
buffer_is_temporary = 1;
|
403
429
|
}
|
404
430
|
|
405
431
|
i_flags = (i_flags | ZIP_TRUNC);
|
@@ -426,6 +452,7 @@ static VALUE zipruby_archive_s_open_buffer(int argc, VALUE *argv, VALUE self) {
|
|
426
452
|
rb_raise(Error, "Open archive failed: %s", errstr);
|
427
453
|
}
|
428
454
|
|
455
|
+
p_archive->archive->comp_level = i_comp_level;
|
429
456
|
p_archive->path = rb_str_new2(p_archive->tmpfilnam);
|
430
457
|
p_archive->flags = i_flags;
|
431
458
|
p_archive->buffer = buffer;
|
@@ -442,7 +469,7 @@ static VALUE zipruby_archive_s_open_buffer(int argc, VALUE *argv, VALUE self) {
|
|
442
469
|
rb_jump_tag(status);
|
443
470
|
}
|
444
471
|
|
445
|
-
return retval;
|
472
|
+
return buffer_is_temporary ? buffer : retval;
|
446
473
|
} else {
|
447
474
|
return archive;
|
448
475
|
}
|
@@ -2262,6 +2289,8 @@ VALUE zipruby_stat_is_directory(VALUE self) {
|
|
2262
2289
|
return Qfalse;
|
2263
2290
|
}
|
2264
2291
|
}
|
2292
|
+
#include <zlib.h>
|
2293
|
+
|
2265
2294
|
#include "ruby.h"
|
2266
2295
|
#include "zip.h"
|
2267
2296
|
#include "zipruby.h"
|
@@ -2299,6 +2328,11 @@ void Init_zipruby_zip() {
|
|
2299
2328
|
rb_define_const(Zip, "EM_NONE", INT2NUM(ZIP_EM_NONE));
|
2300
2329
|
rb_define_const(Zip, "EM_TRAD_PKWARE", INT2NUM(ZIP_EM_TRAD_PKWARE));
|
2301
2330
|
// XXX: Strong Encryption Header not parsed yet
|
2331
|
+
|
2332
|
+
rb_define_const(Zip, "NO_COMPRESSION", INT2NUM(Z_NO_COMPRESSION));
|
2333
|
+
rb_define_const(Zip, "BEST_SPEED", INT2NUM(Z_BEST_SPEED));
|
2334
|
+
rb_define_const(Zip, "BEST_COMPRESSION", INT2NUM(Z_BEST_COMPRESSION));
|
2335
|
+
rb_define_const(Zip, "DEFAULT_COMPRESSION", INT2NUM(Z_DEFAULT_COMPRESSION));
|
2302
2336
|
}
|
2303
2337
|
#include <string.h>
|
2304
2338
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zipruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winebarrel
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-24 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|