zipruby 0.2.5-mswin32 → 0.2.6-mswin32
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 +17 -2
- data/lib/i386-mswin32/zipruby.so +0 -0
- data/zipruby.c +240 -42
- metadata +3 -3
data/README.txt
CHANGED
@@ -116,10 +116,17 @@ https://rubyforge.org/frs/?group_id=6124
|
|
116
116
|
open('bar.txt') do |f|
|
117
117
|
ar.replace_filep(1, f)
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
|
+
# if commit changes
|
121
|
+
# ar.commit
|
122
|
+
|
120
123
|
# replace file in zip archive with buffer
|
121
124
|
ar.replace_buffer(2, 'Hello, world!')
|
122
|
-
|
125
|
+
# or
|
126
|
+
# ar.replace_buffer('entry name', 'Hello, world!')
|
127
|
+
# if ignore case distinctions
|
128
|
+
# ar.replace_buffer('entry name', 'Hello, world!', Zip::FL_NOCASE)
|
129
|
+
|
123
130
|
# add or replace file in zip archive
|
124
131
|
ar.add_or_replace_file(3, 'foo.txt')
|
125
132
|
end
|
@@ -146,9 +153,17 @@ https://rubyforge.org/frs/?group_id=6124
|
|
146
153
|
|
147
154
|
# encrypt
|
148
155
|
Zip::Archive.encrypt('filename.zip', 'password')
|
156
|
+
# or
|
157
|
+
# Zip::Archive.encrypt('filename.zip') do |ar|
|
158
|
+
# ar.encrypt('filename.zip', 'password')
|
159
|
+
# end
|
149
160
|
|
150
161
|
# decrypt
|
151
162
|
Zip::Archive.decrypt('filename.zip', 'password')
|
163
|
+
# or
|
164
|
+
# Zip::Archive.decrypt('filename.zip') do |ar|
|
165
|
+
# ar.decrypt('filename.zip', 'password')
|
166
|
+
# end
|
152
167
|
|
153
168
|
== License
|
154
169
|
Copyright (c) 2008 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
data/lib/i386-mswin32/zipruby.so
CHANGED
Binary file
|
data/zipruby.c
CHANGED
@@ -27,6 +27,7 @@ void Init_zipruby() {
|
|
27
27
|
#include "rubyio.h"
|
28
28
|
|
29
29
|
static VALUE zipruby_archive_alloc(VALUE klass);
|
30
|
+
static void zipruby_archive_mark(struct zipruby_archive *p);
|
30
31
|
static void zipruby_archive_free(struct zipruby_archive *p);
|
31
32
|
static VALUE zipruby_archive_s_open(int argc, VALUE *argv, VALUE self);
|
32
33
|
static VALUE zipruby_archive_s_decrypt(VALUE self, VALUE path, VALUE password);
|
@@ -40,15 +41,15 @@ static VALUE zipruby_archive_add_buffer(VALUE self, VALUE name, VALUE source);
|
|
40
41
|
static VALUE zipruby_archive_add_file(int argc, VALUE *argv, VALUE self);
|
41
42
|
static VALUE zipruby_archive_add_filep(int argc, VALUE *argv, VALUE self);
|
42
43
|
static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self);
|
43
|
-
static VALUE zipruby_archive_replace_buffer(
|
44
|
-
static VALUE zipruby_archive_replace_file(
|
44
|
+
static VALUE zipruby_archive_replace_buffer(int argc, VALUE *argv, VALUE self);
|
45
|
+
static VALUE zipruby_archive_replace_file(int argc, VALUE* argv, VALUE self);
|
45
46
|
static VALUE zipruby_archive_replace_filep(VALUE self, VALUE index, VALUE file);
|
46
47
|
static VALUE zipruby_archive_replace_function(int argc, VALUE *argv, VALUE self);
|
47
|
-
static VALUE zipruby_archive_add_or_replace_buffer(
|
48
|
+
static VALUE zipruby_archive_add_or_replace_buffer(int argc, VALUE *argv, VALUE self);
|
48
49
|
static VALUE zipruby_archive_add_or_replace_file(int argc, VALUE *argv, VALUE self);
|
49
50
|
static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE self);
|
50
51
|
static VALUE zipruby_archive_add_or_replace_function(int argc, VALUE *argv, VALUE self);
|
51
|
-
static VALUE zipruby_archive_update(VALUE
|
52
|
+
static VALUE zipruby_archive_update(int argc, VALUE *argv, VALUE self);
|
52
53
|
static VALUE zipruby_archive_get_comment(int argc, VALUE *argv, VALUE self);
|
53
54
|
static VALUE zipruby_archive_set_comment(VALUE self, VALUE comment);
|
54
55
|
static VALUE zipruby_archive_locate_name(int argc, VALUE *argv, VALUE self);
|
@@ -61,6 +62,10 @@ static VALUE zipruby_archive_funchange_all(VALUE self);
|
|
61
62
|
static VALUE zipruby_archive_unchange(VALUE self);
|
62
63
|
static VALUE zipruby_archive_revert(VALUE self);
|
63
64
|
static VALUE zipruby_archive_each(VALUE self);
|
65
|
+
static VALUE zipruby_archive_commit(VALUE self);
|
66
|
+
static VALUE zipruby_archive_is_open(VALUE self);
|
67
|
+
static VALUE zipruby_archive_decrypt(VALUE self, VALUE password);
|
68
|
+
static VALUE zipruby_archive_encrypt(VALUE self, VALUE password);
|
64
69
|
|
65
70
|
extern VALUE Zip;
|
66
71
|
VALUE Archive;
|
@@ -84,15 +89,15 @@ void Init_zipruby_archive() {
|
|
84
89
|
rb_define_method(Archive, "add_file", zipruby_archive_add_file, -1);
|
85
90
|
rb_define_method(Archive, "add_filep", zipruby_archive_add_filep, -1);
|
86
91
|
rb_define_method(Archive, "add", zipruby_archive_add_function, -1);
|
87
|
-
rb_define_method(Archive, "replace_buffer", zipruby_archive_replace_buffer,
|
88
|
-
rb_define_method(Archive, "replace_file", zipruby_archive_replace_file,
|
92
|
+
rb_define_method(Archive, "replace_buffer", zipruby_archive_replace_buffer, -1);
|
93
|
+
rb_define_method(Archive, "replace_file", zipruby_archive_replace_file, -1);
|
89
94
|
rb_define_method(Archive, "replace_filep", zipruby_archive_replace_filep, 2);
|
90
95
|
rb_define_method(Archive, "replace", zipruby_archive_replace_function, -1);
|
91
|
-
rb_define_method(Archive, "add_or_replace_buffer", zipruby_archive_add_or_replace_buffer,
|
96
|
+
rb_define_method(Archive, "add_or_replace_buffer", zipruby_archive_add_or_replace_buffer, -1);
|
92
97
|
rb_define_method(Archive, "add_or_replace_file", zipruby_archive_add_or_replace_file, -1);
|
93
98
|
rb_define_method(Archive, "add_or_replace_filep", zipruby_archive_add_or_replace_filep, -1);
|
94
99
|
rb_define_method(Archive, "add_or_replace", zipruby_archive_add_or_replace_function, -1);
|
95
|
-
rb_define_method(Archive, "update", zipruby_archive_update, 1);
|
100
|
+
rb_define_method(Archive, "update", zipruby_archive_update, -1);
|
96
101
|
rb_define_method(Archive, "<<", zipruby_archive_add_filep, -1);
|
97
102
|
rb_define_method(Archive, "get_comment", zipruby_archive_get_comment, -1);
|
98
103
|
rb_define_method(Archive, "comment", zipruby_archive_get_comment, -1);
|
@@ -108,14 +113,24 @@ void Init_zipruby_archive() {
|
|
108
113
|
rb_define_method(Archive, "frevert", zipruby_archive_unchange, 1);
|
109
114
|
rb_define_method(Archive, "revert", zipruby_archive_revert, 0);
|
110
115
|
rb_define_method(Archive, "each", zipruby_archive_each, 0);
|
116
|
+
rb_define_method(Archive, "commit", zipruby_archive_commit, 0);
|
117
|
+
rb_define_method(Archive, "open?", zipruby_archive_is_open, 0);
|
118
|
+
rb_define_method(Archive, "decrypt", zipruby_archive_decrypt, 1);
|
119
|
+
rb_define_method(Archive, "encrypt", zipruby_archive_encrypt, 1);
|
111
120
|
}
|
112
121
|
|
113
122
|
static VALUE zipruby_archive_alloc(VALUE klass) {
|
114
123
|
struct zipruby_archive *p = ALLOC(struct zipruby_archive);
|
115
124
|
|
116
125
|
p->archive = NULL;
|
126
|
+
p->path = Qnil;
|
127
|
+
p->flags = 0;
|
117
128
|
|
118
|
-
return Data_Wrap_Struct(klass,
|
129
|
+
return Data_Wrap_Struct(klass, zipruby_archive_mark, zipruby_archive_free, p);
|
130
|
+
}
|
131
|
+
|
132
|
+
static void zipruby_archive_mark(struct zipruby_archive *p) {
|
133
|
+
rb_gc_mark(p->path);
|
119
134
|
}
|
120
135
|
|
121
136
|
static void zipruby_archive_free(struct zipruby_archive *p) {
|
@@ -146,6 +161,9 @@ static VALUE zipruby_archive_s_open(int argc, VALUE *argv, VALUE self) {
|
|
146
161
|
rb_raise(Error, "Open archive failed - %s: %s", StringValuePtr(path), errstr);
|
147
162
|
}
|
148
163
|
|
164
|
+
p_archive->path = path;
|
165
|
+
p_archive->flags = i_flags;
|
166
|
+
|
149
167
|
if (rb_block_given_p()) {
|
150
168
|
VALUE retval;
|
151
169
|
int status;
|
@@ -219,6 +237,10 @@ static VALUE zipruby_archive_s_encrypt(VALUE self, VALUE path, VALUE password) {
|
|
219
237
|
static VALUE zipruby_archive_close(VALUE self) {
|
220
238
|
struct zipruby_archive *p_archive;
|
221
239
|
|
240
|
+
if (!zipruby_archive_is_open(self)) {
|
241
|
+
return Qfalse;
|
242
|
+
}
|
243
|
+
|
222
244
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
223
245
|
Check_Archive(p_archive);
|
224
246
|
|
@@ -229,8 +251,10 @@ static VALUE zipruby_archive_close(VALUE self) {
|
|
229
251
|
}
|
230
252
|
|
231
253
|
p_archive->archive = NULL;
|
254
|
+
p_archive->path = Qnil;
|
255
|
+
p_archive->flags = 0;
|
232
256
|
|
233
|
-
return
|
257
|
+
return Qtrue;
|
234
258
|
}
|
235
259
|
|
236
260
|
/* */
|
@@ -339,24 +363,31 @@ static VALUE zipruby_archive_add_buffer(VALUE self, VALUE name, VALUE source) {
|
|
339
363
|
}
|
340
364
|
|
341
365
|
/* */
|
342
|
-
static VALUE zipruby_archive_replace_buffer(
|
366
|
+
static VALUE zipruby_archive_replace_buffer(int argc, VALUE *argv, VALUE self) {
|
343
367
|
struct zipruby_archive *p_archive;
|
344
368
|
struct zip_source *zsource;
|
345
|
-
|
369
|
+
VALUE index, source, flags;
|
370
|
+
int i_index, i_flags = 0;
|
346
371
|
char *data;
|
347
372
|
off_t len;
|
348
373
|
|
374
|
+
rb_scan_args(argc, argv, "21", &index, &source, &flags);
|
375
|
+
|
349
376
|
if (!rb_obj_is_instance_of(index, rb_cString) && !rb_obj_is_instance_of(index, rb_cFixnum)) {
|
350
377
|
rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
|
351
378
|
}
|
352
379
|
|
380
|
+
if (!NIL_P(flags)) {
|
381
|
+
i_flags = NUM2INT(flags);
|
382
|
+
}
|
383
|
+
|
353
384
|
Check_Type(source, T_STRING);
|
354
385
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
355
386
|
Check_Archive(p_archive);
|
356
387
|
|
357
388
|
if (rb_obj_is_instance_of(index, rb_cFixnum)) {
|
358
389
|
i_index = NUM2INT(index);
|
359
|
-
} else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index),
|
390
|
+
} else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), i_flags)) == -1) {
|
360
391
|
rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", StringValuePtr(index));
|
361
392
|
}
|
362
393
|
|
@@ -384,18 +415,26 @@ static VALUE zipruby_archive_replace_buffer(VALUE self, VALUE index, VALUE sourc
|
|
384
415
|
}
|
385
416
|
|
386
417
|
/* */
|
387
|
-
static VALUE zipruby_archive_add_or_replace_buffer(
|
418
|
+
static VALUE zipruby_archive_add_or_replace_buffer(int argc, VALUE *argv, VALUE self) {
|
388
419
|
struct zipruby_archive *p_archive;
|
389
|
-
|
420
|
+
VALUE name, source, flags;
|
421
|
+
int index, i_flags = 0;
|
422
|
+
|
423
|
+
rb_scan_args(argc, argv, "21", &name, &source, &flags);
|
424
|
+
|
425
|
+
if (!NIL_P(flags)) {
|
426
|
+
i_flags = NUM2INT(flags);
|
427
|
+
}
|
390
428
|
|
391
429
|
Check_Type(name, T_STRING);
|
392
430
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
393
431
|
Check_Archive(p_archive);
|
394
432
|
|
395
|
-
index = zip_name_locate(p_archive->archive, StringValuePtr(name),
|
433
|
+
index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
|
396
434
|
|
397
435
|
if (index >= 0) {
|
398
|
-
|
436
|
+
VALUE _args[] = { INT2NUM(index), source };
|
437
|
+
return zipruby_archive_replace_buffer(2, _args, self);
|
399
438
|
} else {
|
400
439
|
return zipruby_archive_add_buffer(self, name, source);
|
401
440
|
}
|
@@ -439,22 +478,29 @@ static VALUE zipruby_archive_add_file(int argc, VALUE *argv, VALUE self) {
|
|
439
478
|
}
|
440
479
|
|
441
480
|
/* */
|
442
|
-
static VALUE zipruby_archive_replace_file(
|
481
|
+
static VALUE zipruby_archive_replace_file(int argc, VALUE* argv, VALUE self) {
|
443
482
|
struct zipruby_archive *p_archive;
|
444
483
|
struct zip_source *zsource;
|
445
|
-
|
484
|
+
VALUE index, fname, flags;
|
485
|
+
int i_index, i_flags = 0;
|
486
|
+
|
487
|
+
rb_scan_args(argc, argv, "21", &index, &fname, &flags);
|
446
488
|
|
447
489
|
if (!rb_obj_is_instance_of(index, rb_cString) && !rb_obj_is_instance_of(index, rb_cFixnum)) {
|
448
490
|
rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
|
449
491
|
}
|
450
492
|
|
493
|
+
if (!NIL_P(flags)) {
|
494
|
+
i_flags = NUM2INT(flags);
|
495
|
+
}
|
496
|
+
|
451
497
|
Check_Type(fname, T_STRING);
|
452
498
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
453
499
|
Check_Archive(p_archive);
|
454
500
|
|
455
501
|
if (rb_obj_is_instance_of(index, rb_cFixnum)) {
|
456
502
|
i_index = NUM2INT(index);
|
457
|
-
} else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index),
|
503
|
+
} else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), i_flags)) == -1) {
|
458
504
|
rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", StringValuePtr(index));
|
459
505
|
}
|
460
506
|
|
@@ -474,11 +520,16 @@ static VALUE zipruby_archive_replace_file(VALUE self, VALUE index, VALUE fname)
|
|
474
520
|
|
475
521
|
/* */
|
476
522
|
static VALUE zipruby_archive_add_or_replace_file(int argc, VALUE *argv, VALUE self) {
|
477
|
-
VALUE name, fname;
|
523
|
+
VALUE name, fname, flags;
|
478
524
|
struct zipruby_archive *p_archive;
|
479
|
-
int index;
|
525
|
+
int index, i_flags = 0;
|
480
526
|
|
481
|
-
rb_scan_args(argc, argv, "
|
527
|
+
rb_scan_args(argc, argv, "12", &name, &fname, &flags);
|
528
|
+
|
529
|
+
if (NIL_P(flags) && FIXNUM_P(fname)) {
|
530
|
+
flags = fname;
|
531
|
+
fname = Qnil;
|
532
|
+
}
|
482
533
|
|
483
534
|
if (NIL_P(fname)) {
|
484
535
|
fname = name;
|
@@ -491,16 +542,22 @@ static VALUE zipruby_archive_add_or_replace_file(int argc, VALUE *argv, VALUE se
|
|
491
542
|
name = rb_funcall(rb_cFile, rb_intern("basename"), 1, fname);
|
492
543
|
}
|
493
544
|
|
545
|
+
if (!NIL_P(flags)) {
|
546
|
+
i_flags = NUM2INT(flags);
|
547
|
+
}
|
548
|
+
|
494
549
|
Check_Type(name, T_STRING);
|
495
550
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
496
551
|
Check_Archive(p_archive);
|
497
552
|
|
498
|
-
index = zip_name_locate(p_archive->archive, StringValuePtr(name),
|
553
|
+
index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
|
499
554
|
|
500
555
|
if (index >= 0) {
|
501
|
-
|
556
|
+
VALUE _args[] = { INT2NUM(index), fname };
|
557
|
+
return zipruby_archive_replace_file(2, _args, self);
|
502
558
|
} else {
|
503
|
-
|
559
|
+
VALUE _args[] = { name, fname };
|
560
|
+
return zipruby_archive_add_file(2, _args, self);
|
504
561
|
}
|
505
562
|
}
|
506
563
|
|
@@ -529,20 +586,28 @@ static VALUE zipruby_archive_add_filep(int argc, VALUE *argv, VALUE self) {
|
|
529
586
|
/* */
|
530
587
|
static VALUE zipruby_archive_replace_filep(VALUE self, VALUE index, VALUE file) {
|
531
588
|
VALUE source;
|
589
|
+
VALUE _args[2];
|
532
590
|
|
533
591
|
Check_Type(file, T_FILE);
|
534
592
|
source = rb_funcall(file, rb_intern("read"), 0);
|
535
593
|
|
536
|
-
|
594
|
+
_args[0] = index;
|
595
|
+
_args[1] = source;
|
596
|
+
return zipruby_archive_replace_buffer(2, _args, self);
|
537
597
|
}
|
538
598
|
|
539
599
|
/* */
|
540
600
|
static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE self) {
|
541
|
-
VALUE name, file;
|
601
|
+
VALUE name, file, flags;
|
542
602
|
struct zipruby_archive *p_archive;
|
543
|
-
int index;
|
603
|
+
int index, i_flags = 0;
|
544
604
|
|
545
|
-
rb_scan_args(argc, argv, "
|
605
|
+
rb_scan_args(argc, argv, "12", &name, &file, &flags);
|
606
|
+
|
607
|
+
if (NIL_P(flags) && FIXNUM_P(file)) {
|
608
|
+
flags = file;
|
609
|
+
file = Qnil;
|
610
|
+
}
|
546
611
|
|
547
612
|
if (NIL_P(file)) {
|
548
613
|
file = name;
|
@@ -555,16 +620,21 @@ static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE s
|
|
555
620
|
name = rb_funcall(rb_cFile, rb_intern("basename"), 1, rb_funcall(file, rb_intern("path"), 0));
|
556
621
|
}
|
557
622
|
|
623
|
+
if (!NIL_P(flags)) {
|
624
|
+
i_flags = NUM2INT(flags);
|
625
|
+
}
|
626
|
+
|
558
627
|
Check_Type(name, T_STRING);
|
559
628
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
560
629
|
Check_Archive(p_archive);
|
561
630
|
|
562
|
-
index = zip_name_locate(p_archive->archive, StringValuePtr(name),
|
631
|
+
index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
|
563
632
|
|
564
633
|
if (index >= 0) {
|
565
634
|
return zipruby_archive_replace_filep(self, INT2NUM(index), file);
|
566
635
|
} else {
|
567
|
-
|
636
|
+
VALUE _args[] = { name, file };
|
637
|
+
return zipruby_archive_add_filep(2, _args, self);
|
568
638
|
}
|
569
639
|
}
|
570
640
|
|
@@ -657,34 +727,52 @@ static VALUE zipruby_archive_replace_function(int argc, VALUE *argv, VALUE self)
|
|
657
727
|
|
658
728
|
/* */
|
659
729
|
static VALUE zipruby_archive_add_or_replace_function(int argc, VALUE *argv, VALUE self) {
|
660
|
-
VALUE name, mtime;
|
730
|
+
VALUE name, mtime, flags;
|
661
731
|
struct zipruby_archive *p_archive;
|
662
|
-
int index;
|
732
|
+
int index, i_flags = 0;
|
733
|
+
|
734
|
+
rb_scan_args(argc, argv, "12", &name, &mtime, &flags);
|
735
|
+
|
736
|
+
if (NIL_P(flags) && FIXNUM_P(mtime)) {
|
737
|
+
flags = mtime;
|
738
|
+
mtime = Qnil;
|
739
|
+
}
|
740
|
+
|
741
|
+
if (!NIL_P(flags)) {
|
742
|
+
i_flags = NUM2INT(flags);
|
743
|
+
}
|
663
744
|
|
664
|
-
rb_scan_args(argc, argv, "11", &name, &mtime);
|
665
745
|
Check_Type(name, T_STRING);
|
666
746
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
667
747
|
Check_Archive(p_archive);
|
668
748
|
|
669
|
-
index = zip_name_locate(p_archive->archive, StringValuePtr(name),
|
749
|
+
index = zip_name_locate(p_archive->archive, StringValuePtr(name), i_flags);
|
670
750
|
|
671
751
|
if (index >= 0) {
|
672
|
-
VALUE
|
673
|
-
return zipruby_archive_replace_function(2,
|
752
|
+
VALUE _args[] = { INT2NUM(index), mtime };
|
753
|
+
return zipruby_archive_replace_function(2, _args, self);
|
674
754
|
} else {
|
675
|
-
|
755
|
+
VALUE _args[] = { name, mtime };
|
756
|
+
return zipruby_archive_add_function(2, _args, self);
|
676
757
|
}
|
677
758
|
}
|
678
759
|
|
679
760
|
/* */
|
680
|
-
static VALUE zipruby_archive_update(VALUE
|
761
|
+
static VALUE zipruby_archive_update(int argc, VALUE *argv, VALUE self) {
|
681
762
|
struct zipruby_archive *p_archive, *p_srcarchive;
|
682
|
-
|
763
|
+
VALUE srcarchive, flags;
|
764
|
+
int i, num_files, i_flags = 0;
|
765
|
+
|
766
|
+
rb_scan_args(argc, argv, "11", &srcarchive, &flags);
|
683
767
|
|
684
768
|
if (!rb_obj_is_instance_of(srcarchive, Archive)) {
|
685
769
|
rb_raise(rb_eTypeError, "wrong argument type %s (expected Zip::Archive)", rb_class2name(CLASS_OF(srcarchive)));
|
686
770
|
}
|
687
771
|
|
772
|
+
if (!NIL_P(flags)) {
|
773
|
+
i_flags = NUM2INT(flags);
|
774
|
+
}
|
775
|
+
|
688
776
|
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
689
777
|
Check_Archive(p_archive);
|
690
778
|
Data_Get_Struct(srcarchive, struct zipruby_archive, p_srcarchive);
|
@@ -754,7 +842,7 @@ static VALUE zipruby_archive_update(VALUE self, VALUE srcarchive) {
|
|
754
842
|
rb_raise(Error, "Update archive failed: %s", zip_strerror(p_srcarchive->archive));
|
755
843
|
}
|
756
844
|
|
757
|
-
index = zip_name_locate(p_archive->archive, name,
|
845
|
+
index = zip_name_locate(p_archive->archive, name, i_flags);
|
758
846
|
|
759
847
|
if (index >= 0) {
|
760
848
|
if (zip_replace(p_archive->archive, i, zsource) == -1) {
|
@@ -995,6 +1083,116 @@ static VALUE zipruby_archive_each(VALUE self) {
|
|
995
1083
|
|
996
1084
|
return Qnil;
|
997
1085
|
}
|
1086
|
+
|
1087
|
+
/* */
|
1088
|
+
static VALUE zipruby_archive_commit(VALUE self) {
|
1089
|
+
struct zipruby_archive *p_archive;
|
1090
|
+
int errorp;
|
1091
|
+
|
1092
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
1093
|
+
Check_Archive(p_archive);
|
1094
|
+
|
1095
|
+
if (zip_close(p_archive->archive) == -1) {
|
1096
|
+
zip_unchange_all(p_archive->archive);
|
1097
|
+
zip_unchange_archive(p_archive->archive);
|
1098
|
+
rb_raise(Error, "Commit archive failed: %s", zip_strerror(p_archive->archive));
|
1099
|
+
}
|
1100
|
+
|
1101
|
+
p_archive->archive = NULL;
|
1102
|
+
p_archive->flags = (p_archive->flags & ~(ZIP_CREATE | ZIP_EXCL));
|
1103
|
+
|
1104
|
+
if ((p_archive->archive = zip_open(StringValuePtr(p_archive->path), p_archive->flags, &errorp)) == NULL) {
|
1105
|
+
char errstr[ERRSTR_BUFSIZE];
|
1106
|
+
zip_error_to_str(errstr, ERRSTR_BUFSIZE, errorp, errno);
|
1107
|
+
rb_raise(Error, "Commit archive failed: %s", errstr);
|
1108
|
+
}
|
1109
|
+
|
1110
|
+
return Qnil;
|
1111
|
+
}
|
1112
|
+
|
1113
|
+
/* */
|
1114
|
+
static VALUE zipruby_archive_is_open(VALUE self) {
|
1115
|
+
struct zipruby_archive *p_archive;
|
1116
|
+
|
1117
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
1118
|
+
return (p_archive->archive != NULL) ? Qtrue : Qfalse;
|
1119
|
+
}
|
1120
|
+
|
1121
|
+
/* */
|
1122
|
+
static VALUE zipruby_archive_decrypt(VALUE self, VALUE password) {
|
1123
|
+
struct zipruby_archive *p_archive;
|
1124
|
+
long pwdlen;
|
1125
|
+
int errorp;
|
1126
|
+
|
1127
|
+
Check_Type(password, T_STRING);
|
1128
|
+
pwdlen = RSTRING(password)->len;
|
1129
|
+
|
1130
|
+
if (pwdlen < 1) {
|
1131
|
+
rb_raise(Error, "Decrypt archive failed: Password is empty");
|
1132
|
+
} else if (pwdlen > 0xff) {
|
1133
|
+
rb_raise(Error, "Decrypt archive failed: Password is too long");
|
1134
|
+
}
|
1135
|
+
|
1136
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
1137
|
+
Check_Archive(p_archive);
|
1138
|
+
|
1139
|
+
if (zip_close(p_archive->archive) == -1) {
|
1140
|
+
zip_unchange_all(p_archive->archive);
|
1141
|
+
zip_unchange_archive(p_archive->archive);
|
1142
|
+
rb_raise(Error, "Decrypt archive failed: %s", zip_strerror(p_archive->archive));
|
1143
|
+
}
|
1144
|
+
|
1145
|
+
p_archive->archive = NULL;
|
1146
|
+
p_archive->flags = (p_archive->flags & ~(ZIP_CREATE | ZIP_EXCL));
|
1147
|
+
|
1148
|
+
zipruby_archive_s_decrypt(Archive, p_archive->path, password);
|
1149
|
+
|
1150
|
+
if ((p_archive->archive = zip_open(StringValuePtr(p_archive->path), p_archive->flags, &errorp)) == NULL) {
|
1151
|
+
char errstr[ERRSTR_BUFSIZE];
|
1152
|
+
zip_error_to_str(errstr, ERRSTR_BUFSIZE, errorp, errno);
|
1153
|
+
rb_raise(Error, "Decrypt archive failed: %s", errstr);
|
1154
|
+
}
|
1155
|
+
|
1156
|
+
return Qnil;
|
1157
|
+
}
|
1158
|
+
|
1159
|
+
/* */
|
1160
|
+
static VALUE zipruby_archive_encrypt(VALUE self, VALUE password) {
|
1161
|
+
struct zipruby_archive *p_archive;
|
1162
|
+
long pwdlen;
|
1163
|
+
int errorp;
|
1164
|
+
|
1165
|
+
Check_Type(password, T_STRING);
|
1166
|
+
pwdlen = RSTRING(password)->len;
|
1167
|
+
|
1168
|
+
if (pwdlen < 1) {
|
1169
|
+
rb_raise(Error, "Encrypt archive failed: Password is empty");
|
1170
|
+
} else if (pwdlen > 0xff) {
|
1171
|
+
rb_raise(Error, "Encrypt archive failed: Password is too long");
|
1172
|
+
}
|
1173
|
+
|
1174
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
1175
|
+
Check_Archive(p_archive);
|
1176
|
+
|
1177
|
+
if (zip_close(p_archive->archive) == -1) {
|
1178
|
+
zip_unchange_all(p_archive->archive);
|
1179
|
+
zip_unchange_archive(p_archive->archive);
|
1180
|
+
rb_raise(Error, "Encrypt archive failed: %s", zip_strerror(p_archive->archive));
|
1181
|
+
}
|
1182
|
+
|
1183
|
+
p_archive->archive = NULL;
|
1184
|
+
p_archive->flags = (p_archive->flags & ~(ZIP_CREATE | ZIP_EXCL));
|
1185
|
+
|
1186
|
+
zipruby_archive_s_encrypt(Archive, p_archive->path, password);
|
1187
|
+
|
1188
|
+
if ((p_archive->archive = zip_open(StringValuePtr(p_archive->path), p_archive->flags, &errorp)) == NULL) {
|
1189
|
+
char errstr[ERRSTR_BUFSIZE];
|
1190
|
+
zip_error_to_str(errstr, ERRSTR_BUFSIZE, errorp, errno);
|
1191
|
+
rb_raise(Error, "Encrypt archive failed: %s", errstr);
|
1192
|
+
}
|
1193
|
+
|
1194
|
+
return Qnil;
|
1195
|
+
}
|
998
1196
|
#include "zipruby.h"
|
999
1197
|
#include "zipruby_error.h"
|
1000
1198
|
#include "ruby.h"
|
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.2.
|
4
|
+
version: 0.2.6
|
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: 2008-
|
12
|
+
date: 2008-07-13 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -49,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
49
|
requirements: []
|
50
50
|
|
51
51
|
rubyforge_project: zipruby
|
52
|
-
rubygems_version: 1.
|
52
|
+
rubygems_version: 1.0.1
|
53
53
|
signing_key:
|
54
54
|
specification_version: 2
|
55
55
|
summary: Ruby bindings for libzip.
|