zipruby1.9 0.3.4-mswin32 → 0.3.5-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +5 -0
- data/zipruby.c +40 -6
- metadata +3 -3
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/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: zipruby1.9
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: mswin32
|
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
|
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
version:
|
55
55
|
requirements: []
|
56
56
|
|
57
|
-
rubyforge_project:
|
57
|
+
rubyforge_project: zipruby
|
58
58
|
rubygems_version: 1.3.5
|
59
59
|
signing_key:
|
60
60
|
specification_version: 3
|