zipruby 0.2.3 → 0.2.4
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 +10 -0
- data/ext/zipruby.h +1 -1
- data/ext/zipruby_archive.c +115 -0
- data/ext/zipruby_zip_source_proc.c +64 -0
- data/ext/zipruby_zip_source_proc.h +14 -0
- data/zipruby.c +179 -0
- metadata +3 -1
data/README.txt
CHANGED
@@ -93,6 +93,16 @@ https://rubyforge.org/frs/?group_id=6124
|
|
93
93
|
ar.add_buffer('dirname/zoo.txt', 'Hello, world!')
|
94
94
|
# args: <entry name>, <source>
|
95
95
|
end
|
96
|
+
|
97
|
+
# add huge file
|
98
|
+
source = %w(London Bridge is falling down)
|
99
|
+
|
100
|
+
Zip::Archive.open('filename.zip') do |ar|
|
101
|
+
# lb.txt => 'LondonBridgeisfallingdown'
|
102
|
+
ar.add('lb.txt') do # add(<filename>, <mtime>)
|
103
|
+
source.shift # end of stream is nil
|
104
|
+
end
|
105
|
+
end
|
96
106
|
|
97
107
|
=== modifying zip archive
|
98
108
|
|
data/ext/zipruby.h
CHANGED
data/ext/zipruby_archive.c
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
#include "zip.h"
|
4
4
|
#include "zipruby.h"
|
5
5
|
#include "zipruby_archive.h"
|
6
|
+
#include "zipruby_zip_source_proc.h"
|
6
7
|
#include "ruby.h"
|
7
8
|
#include "rubyio.h"
|
8
9
|
|
@@ -19,12 +20,15 @@ static VALUE zipruby_archive_get_stat(int argc, VALUE *argv, VALUE self);
|
|
19
20
|
static VALUE zipruby_archive_add_buffer(VALUE self, VALUE name, VALUE source);
|
20
21
|
static VALUE zipruby_archive_add_file(int argc, VALUE *argv, VALUE self);
|
21
22
|
static VALUE zipruby_archive_add_filep(int argc, VALUE *argv, VALUE self);
|
23
|
+
static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self);
|
22
24
|
static VALUE zipruby_archive_replace_buffer(VALUE self, VALUE index, VALUE source);
|
23
25
|
static VALUE zipruby_archive_replace_file(VALUE self, VALUE index, VALUE fname);
|
24
26
|
static VALUE zipruby_archive_replace_filep(VALUE self, VALUE index, VALUE file);
|
27
|
+
static VALUE zipruby_archive_replace_function(int argc, VALUE *argv, VALUE self);
|
25
28
|
static VALUE zipruby_archive_add_or_replace_buffer(VALUE self, VALUE name, VALUE source);
|
26
29
|
static VALUE zipruby_archive_add_or_replace_file(int argc, VALUE *argv, VALUE self);
|
27
30
|
static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE self);
|
31
|
+
static VALUE zipruby_archive_add_or_replace_function(int argc, VALUE *argv, VALUE self);
|
28
32
|
static VALUE zipruby_archive_update(VALUE self, VALUE srcarchive);
|
29
33
|
static VALUE zipruby_archive_get_comment(int argc, VALUE *argv, VALUE self);
|
30
34
|
static VALUE zipruby_archive_set_comment(VALUE self, VALUE comment);
|
@@ -60,12 +64,15 @@ void Init_zipruby_archive() {
|
|
60
64
|
rb_define_method(Archive, "add_buffer", zipruby_archive_add_buffer, 2);
|
61
65
|
rb_define_method(Archive, "add_file", zipruby_archive_add_file, -1);
|
62
66
|
rb_define_method(Archive, "add_filep", zipruby_archive_add_filep, -1);
|
67
|
+
rb_define_method(Archive, "add", zipruby_archive_add_function, -1);
|
63
68
|
rb_define_method(Archive, "replace_buffer", zipruby_archive_replace_buffer, 2);
|
64
69
|
rb_define_method(Archive, "replace_file", zipruby_archive_replace_file, 2);
|
65
70
|
rb_define_method(Archive, "replace_filep", zipruby_archive_replace_filep, 2);
|
71
|
+
rb_define_method(Archive, "replace", zipruby_archive_replace_function, -1);
|
66
72
|
rb_define_method(Archive, "add_or_replace_buffer", zipruby_archive_add_or_replace_buffer, 2);
|
67
73
|
rb_define_method(Archive, "add_or_replace_file", zipruby_archive_add_or_replace_file, -1);
|
68
74
|
rb_define_method(Archive, "add_or_replace_filep", zipruby_archive_add_or_replace_filep, -1);
|
75
|
+
rb_define_method(Archive, "add_or_replace", zipruby_archive_add_or_replace_function, -1);
|
69
76
|
rb_define_method(Archive, "update", zipruby_archive_update, 1);
|
70
77
|
rb_define_method(Archive, "<<", zipruby_archive_add_filep, -1);
|
71
78
|
rb_define_method(Archive, "get_comment", zipruby_archive_get_comment, -1);
|
@@ -522,6 +529,114 @@ static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE s
|
|
522
529
|
}
|
523
530
|
}
|
524
531
|
|
532
|
+
/* */
|
533
|
+
static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self) {
|
534
|
+
VALUE name, mtime;
|
535
|
+
struct zipruby_archive *p_archive;
|
536
|
+
struct zip_source *zsource;
|
537
|
+
struct read_proc *z;
|
538
|
+
|
539
|
+
rb_scan_args(argc, argv, "11", &name, &mtime);
|
540
|
+
rb_need_block();
|
541
|
+
|
542
|
+
if (NIL_P(mtime)) {
|
543
|
+
mtime = rb_funcall(rb_cTime, rb_intern("now"), 0);
|
544
|
+
} else if (!rb_obj_is_instance_of(mtime, rb_cTime)) {
|
545
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected Time)", rb_class2name(CLASS_OF(mtime)));
|
546
|
+
}
|
547
|
+
|
548
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
549
|
+
Check_Archive(p_archive);
|
550
|
+
|
551
|
+
if ((z = malloc(sizeof(struct read_proc))) == NULL) {
|
552
|
+
zip_unchange_all(p_archive->archive);
|
553
|
+
zip_unchange_archive(p_archive->archive);
|
554
|
+
rb_raise(rb_eRuntimeError, "Add failed - %s: Cannot allocate memory", StringValuePtr(name));
|
555
|
+
}
|
556
|
+
|
557
|
+
z->proc = rb_block_proc();
|
558
|
+
z->mtime = mtime;
|
559
|
+
|
560
|
+
if ((zsource = zip_source_proc(p_archive->archive, z)) == NULL) {
|
561
|
+
free(z);
|
562
|
+
rb_raise(Error, "Add failed - %s: %s", StringValuePtr(name), zip_strerror(p_archive->archive));
|
563
|
+
}
|
564
|
+
|
565
|
+
if (zip_add(p_archive->archive, StringValuePtr(name), zsource) == -1) {
|
566
|
+
zip_source_free(zsource);
|
567
|
+
zip_unchange_all(p_archive->archive);
|
568
|
+
zip_unchange_archive(p_archive->archive);
|
569
|
+
rb_raise(Error, "Add file failed - %s: %s", StringValuePtr(name), zip_strerror(p_archive->archive));
|
570
|
+
}
|
571
|
+
|
572
|
+
return Qnil;
|
573
|
+
}
|
574
|
+
|
575
|
+
/* */
|
576
|
+
static VALUE zipruby_archive_replace_function(int argc, VALUE *argv, VALUE self) {
|
577
|
+
VALUE index, mtime;
|
578
|
+
struct zipruby_archive *p_archive;
|
579
|
+
struct zip_source *zsource;
|
580
|
+
struct read_proc *z;
|
581
|
+
|
582
|
+
rb_scan_args(argc, argv, "11", &index, &mtime);
|
583
|
+
rb_need_block();
|
584
|
+
Check_Type(index, T_FIXNUM);
|
585
|
+
|
586
|
+
if (NIL_P(mtime)) {
|
587
|
+
mtime = rb_funcall(rb_cTime, rb_intern("now"), 0);
|
588
|
+
} else if (!rb_obj_is_instance_of(mtime, rb_cTime)) {
|
589
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected Time)", rb_class2name(CLASS_OF(mtime)));
|
590
|
+
}
|
591
|
+
|
592
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
593
|
+
Check_Archive(p_archive);
|
594
|
+
|
595
|
+
if ((z = malloc(sizeof(struct read_proc))) == NULL) {
|
596
|
+
zip_unchange_all(p_archive->archive);
|
597
|
+
zip_unchange_archive(p_archive->archive);
|
598
|
+
rb_raise(rb_eRuntimeError, "Replace failed at %d: Cannot allocate memory", NUM2INT(index));
|
599
|
+
}
|
600
|
+
|
601
|
+
z->proc = rb_block_proc();
|
602
|
+
z->mtime = mtime;
|
603
|
+
|
604
|
+
if ((zsource = zip_source_proc(p_archive->archive, z)) == NULL) {
|
605
|
+
free(z);
|
606
|
+
rb_raise(Error, "Replace failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
|
607
|
+
}
|
608
|
+
|
609
|
+
if (zip_replace(p_archive->archive, NUM2INT(index), zsource) == -1) {
|
610
|
+
zip_source_free(zsource);
|
611
|
+
zip_unchange_all(p_archive->archive);
|
612
|
+
zip_unchange_archive(p_archive->archive);
|
613
|
+
rb_raise(Error, "Replace failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
|
614
|
+
}
|
615
|
+
|
616
|
+
return Qnil;
|
617
|
+
}
|
618
|
+
|
619
|
+
/* */
|
620
|
+
static VALUE zipruby_archive_add_or_replace_function(int argc, VALUE *argv, VALUE self) {
|
621
|
+
VALUE name, mtime;
|
622
|
+
struct zipruby_archive *p_archive;
|
623
|
+
int index;
|
624
|
+
|
625
|
+
rb_scan_args(argc, argv, "11", &name, &mtime);
|
626
|
+
Check_Type(name, T_STRING);
|
627
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
628
|
+
Check_Archive(p_archive);
|
629
|
+
|
630
|
+
index = zip_name_locate(p_archive->archive, StringValuePtr(name), ZIP_FL_NOCASE);
|
631
|
+
|
632
|
+
if (index >= 0) {
|
633
|
+
VALUE args[] = { INT2NUM(index), mtime };
|
634
|
+
return zipruby_archive_replace_function(2, args, self);
|
635
|
+
} else {
|
636
|
+
return zipruby_archive_add_function(argc, argv, self);
|
637
|
+
}
|
638
|
+
}
|
639
|
+
|
525
640
|
/* */
|
526
641
|
static VALUE zipruby_archive_update(VALUE self, VALUE srcarchive) {
|
527
642
|
struct zipruby_archive *p_archive, *p_srcarchive;
|
@@ -0,0 +1,64 @@
|
|
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 ssize_t read_proc(void *state, void *data, size_t len, enum zip_source_cmd cmd) {
|
9
|
+
struct read_proc *z;
|
10
|
+
VALUE src;
|
11
|
+
char *buf;
|
12
|
+
size_t n;
|
13
|
+
|
14
|
+
z = (struct read_proc *) state;
|
15
|
+
buf = (char *) data;
|
16
|
+
|
17
|
+
switch (cmd) {
|
18
|
+
case ZIP_SOURCE_OPEN:
|
19
|
+
return 0;
|
20
|
+
|
21
|
+
case ZIP_SOURCE_READ:
|
22
|
+
src = rb_funcall(z->proc, rb_intern("call"), 1, ULONG2NUM(len));
|
23
|
+
|
24
|
+
if (NIL_P(src)) {
|
25
|
+
return 0;
|
26
|
+
}
|
27
|
+
|
28
|
+
src = rb_check_convert_type(src, T_STRING, "String", "to_s");
|
29
|
+
n = RSTRING(src)->len;
|
30
|
+
|
31
|
+
if (n > 0) {
|
32
|
+
n = (n > len) ? len : n;
|
33
|
+
memcpy(buf, StringValuePtr(src), n);
|
34
|
+
}
|
35
|
+
|
36
|
+
return n;
|
37
|
+
|
38
|
+
case ZIP_SOURCE_CLOSE:
|
39
|
+
return 0;
|
40
|
+
|
41
|
+
case ZIP_SOURCE_STAT:
|
42
|
+
{
|
43
|
+
struct zip_stat *st = (struct zip_stat *)data;
|
44
|
+
zip_stat_init(st);
|
45
|
+
st->mtime = NUM2LONG(rb_funcall(z->mtime, rb_intern("tv_sec"), 0));
|
46
|
+
return sizeof(*st);
|
47
|
+
}
|
48
|
+
|
49
|
+
case ZIP_SOURCE_ERROR:
|
50
|
+
return 0;
|
51
|
+
|
52
|
+
case ZIP_SOURCE_FREE:
|
53
|
+
free(z);
|
54
|
+
return 0;
|
55
|
+
}
|
56
|
+
|
57
|
+
return -1;
|
58
|
+
}
|
59
|
+
|
60
|
+
struct zip_source *zip_source_proc(struct zip *za, struct read_proc *z) {
|
61
|
+
struct zip_source *zs;
|
62
|
+
zs = zip_source_function(za, read_proc, z);
|
63
|
+
return zs;
|
64
|
+
}
|
@@ -0,0 +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
|
data/zipruby.c
CHANGED
@@ -22,6 +22,7 @@ void Init_zipruby() {
|
|
22
22
|
#include "zip.h"
|
23
23
|
#include "zipruby.h"
|
24
24
|
#include "zipruby_archive.h"
|
25
|
+
#include "zipruby_zip_source_proc.h"
|
25
26
|
#include "ruby.h"
|
26
27
|
#include "rubyio.h"
|
27
28
|
|
@@ -38,12 +39,15 @@ static VALUE zipruby_archive_get_stat(int argc, VALUE *argv, VALUE self);
|
|
38
39
|
static VALUE zipruby_archive_add_buffer(VALUE self, VALUE name, VALUE source);
|
39
40
|
static VALUE zipruby_archive_add_file(int argc, VALUE *argv, VALUE self);
|
40
41
|
static VALUE zipruby_archive_add_filep(int argc, VALUE *argv, VALUE self);
|
42
|
+
static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self);
|
41
43
|
static VALUE zipruby_archive_replace_buffer(VALUE self, VALUE index, VALUE source);
|
42
44
|
static VALUE zipruby_archive_replace_file(VALUE self, VALUE index, VALUE fname);
|
43
45
|
static VALUE zipruby_archive_replace_filep(VALUE self, VALUE index, VALUE file);
|
46
|
+
static VALUE zipruby_archive_replace_function(int argc, VALUE *argv, VALUE self);
|
44
47
|
static VALUE zipruby_archive_add_or_replace_buffer(VALUE self, VALUE name, VALUE source);
|
45
48
|
static VALUE zipruby_archive_add_or_replace_file(int argc, VALUE *argv, VALUE self);
|
46
49
|
static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE self);
|
50
|
+
static VALUE zipruby_archive_add_or_replace_function(int argc, VALUE *argv, VALUE self);
|
47
51
|
static VALUE zipruby_archive_update(VALUE self, VALUE srcarchive);
|
48
52
|
static VALUE zipruby_archive_get_comment(int argc, VALUE *argv, VALUE self);
|
49
53
|
static VALUE zipruby_archive_set_comment(VALUE self, VALUE comment);
|
@@ -79,12 +83,15 @@ void Init_zipruby_archive() {
|
|
79
83
|
rb_define_method(Archive, "add_buffer", zipruby_archive_add_buffer, 2);
|
80
84
|
rb_define_method(Archive, "add_file", zipruby_archive_add_file, -1);
|
81
85
|
rb_define_method(Archive, "add_filep", zipruby_archive_add_filep, -1);
|
86
|
+
rb_define_method(Archive, "add", zipruby_archive_add_function, -1);
|
82
87
|
rb_define_method(Archive, "replace_buffer", zipruby_archive_replace_buffer, 2);
|
83
88
|
rb_define_method(Archive, "replace_file", zipruby_archive_replace_file, 2);
|
84
89
|
rb_define_method(Archive, "replace_filep", zipruby_archive_replace_filep, 2);
|
90
|
+
rb_define_method(Archive, "replace", zipruby_archive_replace_function, -1);
|
85
91
|
rb_define_method(Archive, "add_or_replace_buffer", zipruby_archive_add_or_replace_buffer, 2);
|
86
92
|
rb_define_method(Archive, "add_or_replace_file", zipruby_archive_add_or_replace_file, -1);
|
87
93
|
rb_define_method(Archive, "add_or_replace_filep", zipruby_archive_add_or_replace_filep, -1);
|
94
|
+
rb_define_method(Archive, "add_or_replace", zipruby_archive_add_or_replace_function, -1);
|
88
95
|
rb_define_method(Archive, "update", zipruby_archive_update, 1);
|
89
96
|
rb_define_method(Archive, "<<", zipruby_archive_add_filep, -1);
|
90
97
|
rb_define_method(Archive, "get_comment", zipruby_archive_get_comment, -1);
|
@@ -541,6 +548,114 @@ static VALUE zipruby_archive_add_or_replace_filep(int argc, VALUE *argv, VALUE s
|
|
541
548
|
}
|
542
549
|
}
|
543
550
|
|
551
|
+
/* */
|
552
|
+
static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self) {
|
553
|
+
VALUE name, mtime;
|
554
|
+
struct zipruby_archive *p_archive;
|
555
|
+
struct zip_source *zsource;
|
556
|
+
struct read_proc *z;
|
557
|
+
|
558
|
+
rb_scan_args(argc, argv, "11", &name, &mtime);
|
559
|
+
rb_need_block();
|
560
|
+
|
561
|
+
if (NIL_P(mtime)) {
|
562
|
+
mtime = rb_funcall(rb_cTime, rb_intern("now"), 0);
|
563
|
+
} else if (!rb_obj_is_instance_of(mtime, rb_cTime)) {
|
564
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected Time)", rb_class2name(CLASS_OF(mtime)));
|
565
|
+
}
|
566
|
+
|
567
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
568
|
+
Check_Archive(p_archive);
|
569
|
+
|
570
|
+
if ((z = malloc(sizeof(struct read_proc))) == NULL) {
|
571
|
+
zip_unchange_all(p_archive->archive);
|
572
|
+
zip_unchange_archive(p_archive->archive);
|
573
|
+
rb_raise(rb_eRuntimeError, "Add failed - %s: Cannot allocate memory", StringValuePtr(name));
|
574
|
+
}
|
575
|
+
|
576
|
+
z->proc = rb_block_proc();
|
577
|
+
z->mtime = mtime;
|
578
|
+
|
579
|
+
if ((zsource = zip_source_proc(p_archive->archive, z)) == NULL) {
|
580
|
+
free(z);
|
581
|
+
rb_raise(Error, "Add failed - %s: %s", StringValuePtr(name), zip_strerror(p_archive->archive));
|
582
|
+
}
|
583
|
+
|
584
|
+
if (zip_add(p_archive->archive, StringValuePtr(name), zsource) == -1) {
|
585
|
+
zip_source_free(zsource);
|
586
|
+
zip_unchange_all(p_archive->archive);
|
587
|
+
zip_unchange_archive(p_archive->archive);
|
588
|
+
rb_raise(Error, "Add file failed - %s: %s", StringValuePtr(name), zip_strerror(p_archive->archive));
|
589
|
+
}
|
590
|
+
|
591
|
+
return Qnil;
|
592
|
+
}
|
593
|
+
|
594
|
+
/* */
|
595
|
+
static VALUE zipruby_archive_replace_function(int argc, VALUE *argv, VALUE self) {
|
596
|
+
VALUE index, mtime;
|
597
|
+
struct zipruby_archive *p_archive;
|
598
|
+
struct zip_source *zsource;
|
599
|
+
struct read_proc *z;
|
600
|
+
|
601
|
+
rb_scan_args(argc, argv, "11", &index, &mtime);
|
602
|
+
rb_need_block();
|
603
|
+
Check_Type(index, T_FIXNUM);
|
604
|
+
|
605
|
+
if (NIL_P(mtime)) {
|
606
|
+
mtime = rb_funcall(rb_cTime, rb_intern("now"), 0);
|
607
|
+
} else if (!rb_obj_is_instance_of(mtime, rb_cTime)) {
|
608
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected Time)", rb_class2name(CLASS_OF(mtime)));
|
609
|
+
}
|
610
|
+
|
611
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
612
|
+
Check_Archive(p_archive);
|
613
|
+
|
614
|
+
if ((z = malloc(sizeof(struct read_proc))) == NULL) {
|
615
|
+
zip_unchange_all(p_archive->archive);
|
616
|
+
zip_unchange_archive(p_archive->archive);
|
617
|
+
rb_raise(rb_eRuntimeError, "Replace failed at %d: Cannot allocate memory", NUM2INT(index));
|
618
|
+
}
|
619
|
+
|
620
|
+
z->proc = rb_block_proc();
|
621
|
+
z->mtime = mtime;
|
622
|
+
|
623
|
+
if ((zsource = zip_source_proc(p_archive->archive, z)) == NULL) {
|
624
|
+
free(z);
|
625
|
+
rb_raise(Error, "Replace failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
|
626
|
+
}
|
627
|
+
|
628
|
+
if (zip_replace(p_archive->archive, NUM2INT(index), zsource) == -1) {
|
629
|
+
zip_source_free(zsource);
|
630
|
+
zip_unchange_all(p_archive->archive);
|
631
|
+
zip_unchange_archive(p_archive->archive);
|
632
|
+
rb_raise(Error, "Replace failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
|
633
|
+
}
|
634
|
+
|
635
|
+
return Qnil;
|
636
|
+
}
|
637
|
+
|
638
|
+
/* */
|
639
|
+
static VALUE zipruby_archive_add_or_replace_function(int argc, VALUE *argv, VALUE self) {
|
640
|
+
VALUE name, mtime;
|
641
|
+
struct zipruby_archive *p_archive;
|
642
|
+
int index;
|
643
|
+
|
644
|
+
rb_scan_args(argc, argv, "11", &name, &mtime);
|
645
|
+
Check_Type(name, T_STRING);
|
646
|
+
Data_Get_Struct(self, struct zipruby_archive, p_archive);
|
647
|
+
Check_Archive(p_archive);
|
648
|
+
|
649
|
+
index = zip_name_locate(p_archive->archive, StringValuePtr(name), ZIP_FL_NOCASE);
|
650
|
+
|
651
|
+
if (index >= 0) {
|
652
|
+
VALUE args[] = { INT2NUM(index), mtime };
|
653
|
+
return zipruby_archive_replace_function(2, args, self);
|
654
|
+
} else {
|
655
|
+
return zipruby_archive_add_function(argc, argv, self);
|
656
|
+
}
|
657
|
+
}
|
658
|
+
|
544
659
|
/* */
|
545
660
|
static VALUE zipruby_archive_update(VALUE self, VALUE srcarchive) {
|
546
661
|
struct zipruby_archive *p_archive, *p_srcarchive;
|
@@ -1474,3 +1589,67 @@ void Init_zipruby_zip() {
|
|
1474
1589
|
rb_define_const(Zip, "EM_TRAD_PKWARE", INT2NUM(ZIP_EM_TRAD_PKWARE));
|
1475
1590
|
// XXX: Strong Encryption Header not parsed yet
|
1476
1591
|
}
|
1592
|
+
#include <string.h>
|
1593
|
+
|
1594
|
+
#include "zip.h"
|
1595
|
+
#include "zipint.h"
|
1596
|
+
#include "zipruby_zip_source_proc.h"
|
1597
|
+
#include "ruby.h"
|
1598
|
+
|
1599
|
+
static ssize_t read_proc(void *state, void *data, size_t len, enum zip_source_cmd cmd) {
|
1600
|
+
struct read_proc *z;
|
1601
|
+
VALUE src;
|
1602
|
+
char *buf;
|
1603
|
+
size_t n;
|
1604
|
+
|
1605
|
+
z = (struct read_proc *) state;
|
1606
|
+
buf = (char *) data;
|
1607
|
+
|
1608
|
+
switch (cmd) {
|
1609
|
+
case ZIP_SOURCE_OPEN:
|
1610
|
+
return 0;
|
1611
|
+
|
1612
|
+
case ZIP_SOURCE_READ:
|
1613
|
+
src = rb_funcall(z->proc, rb_intern("call"), 1, ULONG2NUM(len));
|
1614
|
+
|
1615
|
+
if (NIL_P(src)) {
|
1616
|
+
return 0;
|
1617
|
+
}
|
1618
|
+
|
1619
|
+
src = rb_check_convert_type(src, T_STRING, "String", "to_s");
|
1620
|
+
n = RSTRING(src)->len;
|
1621
|
+
|
1622
|
+
if (n > 0) {
|
1623
|
+
n = (n > len) ? len : n;
|
1624
|
+
memcpy(buf, StringValuePtr(src), n);
|
1625
|
+
}
|
1626
|
+
|
1627
|
+
return n;
|
1628
|
+
|
1629
|
+
case ZIP_SOURCE_CLOSE:
|
1630
|
+
return 0;
|
1631
|
+
|
1632
|
+
case ZIP_SOURCE_STAT:
|
1633
|
+
{
|
1634
|
+
struct zip_stat *st = (struct zip_stat *)data;
|
1635
|
+
zip_stat_init(st);
|
1636
|
+
st->mtime = NUM2LONG(rb_funcall(z->mtime, rb_intern("tv_sec"), 0));
|
1637
|
+
return sizeof(*st);
|
1638
|
+
}
|
1639
|
+
|
1640
|
+
case ZIP_SOURCE_ERROR:
|
1641
|
+
return 0;
|
1642
|
+
|
1643
|
+
case ZIP_SOURCE_FREE:
|
1644
|
+
free(z);
|
1645
|
+
return 0;
|
1646
|
+
}
|
1647
|
+
|
1648
|
+
return -1;
|
1649
|
+
}
|
1650
|
+
|
1651
|
+
struct zip_source *zip_source_proc(struct zip *za, struct read_proc *z) {
|
1652
|
+
struct zip_source *zs;
|
1653
|
+
zs = zip_source_function(za, read_proc, z);
|
1654
|
+
return zs;
|
1655
|
+
}
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winebarrel
|
@@ -42,6 +42,8 @@ files:
|
|
42
42
|
- ext/zipruby_stat.h
|
43
43
|
- ext/zipruby_zip.c
|
44
44
|
- ext/zipruby_zip.h
|
45
|
+
- ext/zipruby_zip_source_proc.c
|
46
|
+
- ext/zipruby_zip_source_proc.h
|
45
47
|
- ext/zip_add.c
|
46
48
|
- ext/zip_add_dir.c
|
47
49
|
- ext/zip_close.c
|