zipruby 0.3.0 → 0.3.1

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/ChangeLog ADDED
@@ -0,0 +1,10 @@
1
+ 2009-05-16 winebarrel
2
+
3
+ * improve Zip::Archive#open_buffer, add_io, replace_io, replace_function
4
+
5
+ * fixes bug: Zip::Archive#add_io, <<
6
+
7
+ * add method: Zip::Archive#add_dir
8
+
9
+ * zipruby/README.txt: fixes example code.
10
+
data/README.txt CHANGED
@@ -68,32 +68,36 @@ https://rubyforge.org/frs/?group_id=6124
68
68
 
69
69
  require 'zipruby'
70
70
 
71
+ bar_txt = open('bar.txt')
72
+
71
73
  Zip::Archive.open('filename.zip', Zip::CREATE) do |ar|
72
- ar.add_file('foo.txt') # add file to zip archive
74
+ # if overwrite: ..., Zip::CREATE | Zip::TRUNC) do |ar|
75
+
76
+ ar.add_file('foo.txt') # add file to zip archive
73
77
 
74
78
  # add file to zip archive from File object
75
- open('bar.txt') do |f|
76
- ar << f # or ar.add_io(f)
77
- end
79
+ ar << bar_txt # or ar.add_io(bar_txt)
78
80
 
79
81
  # add file to zip archive from buffer
80
82
  ar.add_buffer('zoo.txt', 'Hello, world!')
81
83
  end
82
84
 
85
+ bar_txt.rewind
86
+
83
87
  # include directory in zip archive
84
88
  Zip::Archive.open('filename.zip') do |ar|
85
89
  ar.add_file('dirname/foo.txt', 'foo.txt')
86
- # args: <entry name>, <source>
90
+ # args: <entry name> , <source>
87
91
 
88
- open('bar.txt') do |f|
89
- ar.add_io('dirname/bar.txt', f)
90
- # args: <entry name>, <source>
91
- end
92
+ ar.add_io('dirname/bar.txt', bar_txt)
93
+ # args: <entry name> , <source>
92
94
 
93
95
  ar.add_buffer('dirname/zoo.txt', 'Hello, world!')
94
- # args: <entry name>, <source>
96
+ # args: <entry name> , <source>
95
97
  end
96
98
 
99
+ bar_txt.close # close file after archive closed
100
+
97
101
  # add huge file
98
102
  source = %w(London Bridge is falling down)
99
103
 
@@ -108,18 +112,18 @@ https://rubyforge.org/frs/?group_id=6124
108
112
 
109
113
  require 'zipruby'
110
114
 
115
+ bar_txt = open('bar.txt')
116
+
111
117
  Zip::Archive.open('filename.zip') do |ar|
112
118
  # replace file in zip archive
113
119
  ar.replace_file(0, 'foo.txt')
114
120
 
115
121
  # replace file in zip archive with File object
116
- open('bar.txt') do |f|
117
- ar.replace_io(1, f)
118
- end
119
-
122
+ ar.replace_io(1, bar_txt)
123
+
120
124
  # if commit changes
121
125
  # ar.commit
122
-
126
+
123
127
  # replace file in zip archive with buffer
124
128
  ar.replace_buffer(2, 'Hello, world!')
125
129
  # or
@@ -128,7 +132,7 @@ https://rubyforge.org/frs/?group_id=6124
128
132
  # ar.replace_buffer('entry name', 'Hello, world!', Zip::FL_NOCASE)
129
133
 
130
134
  # add or replace file in zip archive
131
- ar.add_or_replace_file(3, 'foo.txt')
135
+ ar.add_or_replace_file('zoo.txt', 'foo.txt')
132
136
  end
133
137
 
134
138
  # append comment
@@ -140,6 +144,8 @@ https://rubyforge.org/frs/?group_id=6124
140
144
  EOS
141
145
  end
142
146
 
147
+ bar_txt.close # close file after archive closed
148
+
143
149
  # ar1 import ar2 entries
144
150
  Zip::Archive.open('ar1.zip') do |ar1|
145
151
  Zip::Archive.open('ar2.zip') do |ar2|
@@ -152,16 +158,16 @@ https://rubyforge.org/frs/?group_id=6124
152
158
  require 'zipruby'
153
159
 
154
160
  # encrypt
155
- Zip::Archive.encrypt('filename.zip', 'password')
161
+ Zip::Archive.encrypt('filename.zip', 'password') # return true if encrypted
156
162
  # or
157
- # Zip::Archive.encrypt('filename.zip') do |ar|
163
+ # Zip::Archive.open('filename.zip') do |ar|
158
164
  # ar.encrypt('password')
159
165
  # end
160
166
 
161
167
  # decrypt
162
- Zip::Archive.decrypt('filename.zip', 'password')
168
+ Zip::Archive.decrypt('filename.zip', 'password') # return true if encrypted
163
169
  # or
164
- # Zip::Archive.decrypt('filename.zip') do |ar|
170
+ # Zip::Archive.open('filename.zip') do |ar|
165
171
  # ar.decrypt('password')
166
172
  # end
167
173
 
@@ -182,10 +188,14 @@ https://rubyforge.org/frs/?group_id=6124
182
188
  puts f.name
183
189
  end
184
190
  end
185
-
186
- # read from stream
187
- zip_data = open('foo.zip').raed
188
- stream = lambda { return !zip_data.slice(0, 256) }
191
+
192
+ # read from stream
193
+ zip_data = open('foo.zip') do |f|
194
+ f.binmode
195
+ f.read
196
+ end
197
+
198
+ stream = lambda { return zip_data.slice!(0, 256) }
189
199
 
190
200
  Zip::Archive.open_buffer(stream) do |ar|
191
201
  puts ar.num_files
@@ -198,7 +208,44 @@ https://rubyforge.org/frs/?group_id=6124
198
208
  end
199
209
  end
200
210
 
211
+ === adding directory recursively
212
+
213
+ require 'zipruby'
214
+
215
+ Zip::Archive.open('filename.zip', Zip::CREATE) do |ar|
216
+ ar.add_dir('dir')
217
+
218
+ Dir.glob('dir/**/*').each do |path|
219
+ if File.directory?(path)
220
+ ar.add_dir(path)
221
+ else
222
+ ar.add_file(path, path) # add_file(<entry name>, <source path>)
223
+ end
224
+ end
225
+ end
226
+
227
+ === extract all files
228
+
229
+ require 'zipruby'
230
+ require 'fileutils'
231
+
232
+ Zip::Archive.open('filename.zip') do |ar|
233
+ ar.each do |zf|
234
+ if zf.directory?
235
+ FileUtils.mkdir_p(zf.name)
236
+ else
237
+ dirname = File.dirname(zf.name)
238
+ FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
239
+
240
+ open(zf.name, 'wb') do |f|
241
+ f << zf.read
242
+ end
243
+ end
244
+ end
245
+ end
246
+
201
247
  == License
248
+
202
249
  Copyright (c) 2008,2009 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
203
250
  All rights reserved.
204
251
 
@@ -226,6 +273,7 @@ https://rubyforge.org/frs/?group_id=6124
226
273
  DAMAGE.
227
274
 
228
275
  === libzip
276
+
229
277
  Zip/Ruby contains libzip.
230
278
 
231
279
  libzip is a C library for reading, creating, and modifying zip archives.
data/ext/zipruby.h CHANGED
@@ -19,7 +19,9 @@
19
19
  } \
20
20
  } while(0)
21
21
 
22
- #define VERSION "0.3.0"
22
+ #define TIME2LONG(v) NUM2LONG(rb_funcall((v), rb_intern("tv_sec"), 0))
23
+
24
+ #define VERSION "0.3.1"
23
25
  #define ERRSTR_BUFSIZE 256
24
26
  #define DATA_BUFSIZE 8192
25
27
 
@@ -4,6 +4,7 @@
4
4
  #include "zipruby.h"
5
5
  #include "zipruby_archive.h"
6
6
  #include "zipruby_zip_source_proc.h"
7
+ #include "zipruby_zip_source_io.h"
7
8
  #include "tmpfile.h"
8
9
  #include "ruby.h"
9
10
  #ifndef RUBY_VM
@@ -24,7 +25,7 @@ static VALUE zipruby_archive_fopen(int argc, VALUE *argv, VALUE self);
24
25
  static VALUE zipruby_archive_get_stat(int argc, VALUE *argv, VALUE self);
25
26
  static VALUE zipruby_archive_add_buffer(VALUE self, VALUE name, VALUE source);
26
27
  static VALUE zipruby_archive_add_file(int argc, VALUE *argv, VALUE self);
27
- static VALUE zipruby_archive_add_io(VALUE self, VALUE name, VALUE io);
28
+ static VALUE zipruby_archive_add_io(int argc, VALUE *argv, VALUE self);
28
29
  static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self);
29
30
  static VALUE zipruby_archive_replace_buffer(int argc, VALUE *argv, VALUE self);
30
31
  static VALUE zipruby_archive_replace_file(int argc, VALUE* argv, VALUE self);
@@ -52,6 +53,7 @@ static VALUE zipruby_archive_is_open(VALUE self);
52
53
  static VALUE zipruby_archive_decrypt(VALUE self, VALUE password);
53
54
  static VALUE zipruby_archive_encrypt(VALUE self, VALUE password);
54
55
  static VALUE zipruby_archive_read(VALUE self);
56
+ static VALUE zipruby_archive_add_dir(VALUE self, VALUE name);
55
57
 
56
58
  extern VALUE Zip;
57
59
  VALUE Archive;
@@ -74,7 +76,7 @@ void Init_zipruby_archive() {
74
76
  rb_define_method(Archive, "get_stat", zipruby_archive_get_stat, -1);
75
77
  rb_define_method(Archive, "add_buffer", zipruby_archive_add_buffer, 2);
76
78
  rb_define_method(Archive, "add_file", zipruby_archive_add_file, -1);
77
- rb_define_method(Archive, "add_io", zipruby_archive_add_io, 2);
79
+ rb_define_method(Archive, "add_io", zipruby_archive_add_io, -1);
78
80
  rb_define_method(Archive, "add", zipruby_archive_add_function, -1);
79
81
  rb_define_method(Archive, "replace_buffer", zipruby_archive_replace_buffer, -1);
80
82
  rb_define_method(Archive, "replace_file", zipruby_archive_replace_file, -1);
@@ -85,7 +87,7 @@ void Init_zipruby_archive() {
85
87
  rb_define_method(Archive, "add_or_replace_io", zipruby_archive_add_or_replace_io, -1);
86
88
  rb_define_method(Archive, "add_or_replace", zipruby_archive_add_or_replace_function, -1);
87
89
  rb_define_method(Archive, "update", zipruby_archive_update, -1);
88
- rb_define_method(Archive, "<<", zipruby_archive_add_io, 2);
90
+ rb_define_method(Archive, "<<", zipruby_archive_add_io, -1);
89
91
  rb_define_method(Archive, "get_comment", zipruby_archive_get_comment, -1);
90
92
  rb_define_method(Archive, "comment", zipruby_archive_get_comment, -1);
91
93
  rb_define_method(Archive, "comment=", zipruby_archive_set_comment, 1);
@@ -105,6 +107,7 @@ void Init_zipruby_archive() {
105
107
  rb_define_method(Archive, "decrypt", zipruby_archive_decrypt, 1);
106
108
  rb_define_method(Archive, "encrypt", zipruby_archive_encrypt, 1);
107
109
  rb_define_method(Archive, "read", zipruby_archive_read, 0);
110
+ rb_define_method(Archive, "add_dir", zipruby_archive_add_dir, 1);
108
111
  }
109
112
 
110
113
  static VALUE zipruby_archive_alloc(VALUE klass) {
@@ -641,28 +644,122 @@ static VALUE zipruby_archive_add_or_replace_file(int argc, VALUE *argv, VALUE se
641
644
  }
642
645
 
643
646
  /* */
644
- static VALUE zipruby_archive_add_io(VALUE self, VALUE name, VALUE io) {
645
- VALUE source;
647
+ static VALUE zipruby_archive_add_io(int argc, VALUE *argv, VALUE self) {
648
+ VALUE name, file, mtime;
649
+ struct zipruby_archive *p_archive;
650
+ struct zip_source *zsource;
651
+ struct read_io *z;
646
652
 
647
- Check_IO(io);
648
- source = rb_funcall(io, rb_intern("read"), 0);
653
+ rb_scan_args(argc, argv, "11", &name, &file);
654
+
655
+ if (NIL_P(file)) {
656
+ file = name;
657
+ name = Qnil;
658
+ }
659
+
660
+ Check_IO(file);
661
+
662
+ if (NIL_P(name)) {
663
+ if (rb_obj_is_kind_of(file, rb_cFile)) {
664
+ name = rb_funcall(rb_cFile, rb_intern("basename"), 1, rb_funcall(file, rb_intern("path"), 0));
665
+ } else {
666
+ rb_raise(rb_eRuntimeError, "Add io failed - %s: Entry name is not given", RSTRING(rb_inspect(file)));
667
+ }
668
+ }
669
+
670
+ if (rb_obj_is_kind_of(file, rb_cFile)) {
671
+ mtime = rb_funcall(file, rb_intern("mtime"), 0);
672
+ } else {
673
+ mtime = rb_funcall(rb_cTime, rb_intern("now"), 0);
674
+ }
675
+
676
+ Data_Get_Struct(self, struct zipruby_archive, p_archive);
677
+ Check_Archive(p_archive);
678
+
679
+ if ((z = malloc(sizeof(struct read_io))) == NULL) {
680
+ zip_unchange_all(p_archive->archive);
681
+ zip_unchange_archive(p_archive->archive);
682
+ rb_raise(rb_eRuntimeError, "Add io failed - %s: Cannot allocate memory", RSTRING(rb_inspect(file)));
683
+ }
684
+
685
+ z->io = file;
686
+ z->mtime = TIME2LONG(mtime);
687
+
688
+ if ((zsource = zip_source_io(p_archive->archive, z)) == NULL) {
689
+ free(z);
690
+ rb_raise(Error, "Add io failed - %s: %s", RSTRING(rb_inspect(file)), zip_strerror(p_archive->archive));
691
+ }
649
692
 
650
- return zipruby_archive_add_buffer(self, name, source);
693
+ if (zip_add(p_archive->archive, RSTRING_PTR(name), zsource) == -1) {
694
+ zip_source_free(zsource);
695
+ zip_unchange_all(p_archive->archive);
696
+ zip_unchange_archive(p_archive->archive);
697
+ rb_raise(Error, "Add io failed - %s: %s", RSTRING_PTR(name), zip_strerror(p_archive->archive));
698
+ }
699
+
700
+ return Qnil;
651
701
  }
652
702
 
653
703
  /* */
654
704
  static VALUE zipruby_archive_replace_io(int argc, VALUE *argv, VALUE self) {
655
- VALUE source, io, index, flags;
656
- VALUE _args[3];
705
+ VALUE file, index, flags, mtime;
706
+ struct zipruby_archive *p_archive;
707
+ struct zip_source *zsource;
708
+ struct read_io *z;
709
+ int i_index, i_flags = 0;
657
710
 
658
- rb_scan_args(argc, argv, "21", &index, &io, &flags);
659
- Check_IO(io);
660
- source = rb_funcall(io, rb_intern("read"), 0);
711
+ rb_scan_args(argc, argv, "21", &index, &file, &flags);
712
+
713
+ if (TYPE(index) != T_STRING && !FIXNUM_P(index)) {
714
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
715
+ }
716
+
717
+ Check_IO(file);
718
+
719
+ if (!NIL_P(flags)) {
720
+ i_flags = NUM2INT(flags);
721
+ }
722
+
723
+ if (rb_obj_is_kind_of(file, rb_cFile)) {
724
+ mtime = rb_funcall(file, rb_intern("mtime"), 0);
725
+ } else {
726
+ mtime = rb_funcall(rb_cTime, rb_intern("now"), 0);
727
+ }
728
+
729
+ Data_Get_Struct(self, struct zipruby_archive, p_archive);
730
+ Check_Archive(p_archive);
661
731
 
662
- _args[0] = index;
663
- _args[1] = source;
664
- _args[2] = flags;
665
- return zipruby_archive_replace_buffer(2, _args, self);
732
+ if (FIXNUM_P(index)) {
733
+ i_index = NUM2INT(index);
734
+ } else if ((i_index = zip_name_locate(p_archive->archive, RSTRING_PTR(index), i_flags)) == -1) {
735
+ rb_raise(Error, "Replace io failed - %s: Archive does not contain a file", RSTRING_PTR(index));
736
+ }
737
+
738
+ Data_Get_Struct(self, struct zipruby_archive, p_archive);
739
+ Check_Archive(p_archive);
740
+
741
+ if ((z = malloc(sizeof(struct read_io))) == NULL) {
742
+ zip_unchange_all(p_archive->archive);
743
+ zip_unchange_archive(p_archive->archive);
744
+ rb_raise(rb_eRuntimeError, "Replace io failed at %d - %s: Cannot allocate memory", i_index, RSTRING(rb_inspect(file)));
745
+ }
746
+
747
+ z->io = file;
748
+ z->mtime = TIME2LONG(mtime);
749
+
750
+ if ((zsource = zip_source_io(p_archive->archive, z)) == NULL) {
751
+ free(z);
752
+ rb_raise(Error, "Replace io failed at %d - %s: %s", i_index, RSTRING(rb_inspect(file)), zip_strerror(p_archive->archive));
753
+ }
754
+
755
+ if (zip_replace(p_archive->archive, i_index, zsource) == -1) {
756
+ zip_source_free(zsource);
757
+ zip_unchange_all(p_archive->archive);
758
+ zip_unchange_archive(p_archive->archive);
759
+ rb_raise(Error, "Replace io failed at %d - %s: %s", i_index, RSTRING(rb_inspect(file)), zip_strerror(p_archive->archive));
760
+ }
761
+
762
+ return Qnil;
666
763
  }
667
764
 
668
765
  /* */
@@ -688,7 +785,8 @@ static VALUE zipruby_archive_add_or_replace_io(int argc, VALUE *argv, VALUE self
688
785
  VALUE _args[] = {INT2NUM(index), io, flags};
689
786
  return zipruby_archive_replace_io(2, _args, self);
690
787
  } else {
691
- return zipruby_archive_add_io(self, name, io);
788
+ VALUE _args[2] = { name, io };
789
+ return zipruby_archive_add_io(2, _args, self);
692
790
  }
693
791
  }
694
792
 
@@ -719,7 +817,7 @@ static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self) {
719
817
  }
720
818
 
721
819
  z->proc = rb_block_proc();
722
- z->mtime = mtime;
820
+ z->mtime = TIME2LONG(mtime);
723
821
 
724
822
  if ((zsource = zip_source_proc(p_archive->archive, z)) == NULL) {
725
823
  free(z);
@@ -738,14 +836,18 @@ static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self) {
738
836
 
739
837
  /* */
740
838
  static VALUE zipruby_archive_replace_function(int argc, VALUE *argv, VALUE self) {
741
- VALUE index, mtime;
839
+ VALUE index, flags, mtime;
742
840
  struct zipruby_archive *p_archive;
743
841
  struct zip_source *zsource;
744
842
  struct read_proc *z;
843
+ int i_index, i_flags = 0;
745
844
 
746
- rb_scan_args(argc, argv, "11", &index, &mtime);
845
+ rb_scan_args(argc, argv, "12", &index, &mtime, &flags);
747
846
  rb_need_block();
748
- Check_Type(index, T_FIXNUM);
847
+
848
+ if (TYPE(index) != T_STRING && !FIXNUM_P(index)) {
849
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
850
+ }
749
851
 
750
852
  if (NIL_P(mtime)) {
751
853
  mtime = rb_funcall(rb_cTime, rb_intern("now"), 0);
@@ -753,28 +855,38 @@ static VALUE zipruby_archive_replace_function(int argc, VALUE *argv, VALUE self)
753
855
  rb_raise(rb_eTypeError, "wrong argument type %s (expected Time)", rb_class2name(CLASS_OF(mtime)));
754
856
  }
755
857
 
858
+ if (!NIL_P(flags)) {
859
+ i_flags = NUM2INT(flags);
860
+ }
861
+
756
862
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
757
863
  Check_Archive(p_archive);
758
864
 
865
+ if (FIXNUM_P(index)) {
866
+ i_index = NUM2INT(index);
867
+ } else if ((i_index = zip_name_locate(p_archive->archive, RSTRING_PTR(index), i_flags)) == -1) {
868
+ rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", RSTRING_PTR(index));
869
+ }
870
+
759
871
  if ((z = malloc(sizeof(struct read_proc))) == NULL) {
760
872
  zip_unchange_all(p_archive->archive);
761
873
  zip_unchange_archive(p_archive->archive);
762
- rb_raise(rb_eRuntimeError, "Replace failed at %d: Cannot allocate memory", NUM2INT(index));
874
+ rb_raise(rb_eRuntimeError, "Replace failed at %d: Cannot allocate memory", i_index);
763
875
  }
764
876
 
765
877
  z->proc = rb_block_proc();
766
- z->mtime = mtime;
878
+ z->mtime = TIME2LONG(mtime);
767
879
 
768
880
  if ((zsource = zip_source_proc(p_archive->archive, z)) == NULL) {
769
881
  free(z);
770
- rb_raise(Error, "Replace failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
882
+ rb_raise(Error, "Replace failed at %d: %s", i_index, zip_strerror(p_archive->archive));
771
883
  }
772
884
 
773
- if (zip_replace(p_archive->archive, NUM2INT(index), zsource) == -1) {
885
+ if (zip_replace(p_archive->archive, i_index, zsource) == -1) {
774
886
  zip_source_free(zsource);
775
887
  zip_unchange_all(p_archive->archive);
776
888
  zip_unchange_archive(p_archive->archive);
777
- rb_raise(Error, "Replace failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
889
+ rb_raise(Error, "Replace failed at %d: %s", i_index, zip_strerror(p_archive->archive));
778
890
  }
779
891
 
780
892
  return Qnil;
@@ -1328,3 +1440,20 @@ static VALUE zipruby_archive_read(VALUE self) {
1328
1440
 
1329
1441
  return retval;
1330
1442
  }
1443
+
1444
+ /* */
1445
+ static VALUE zipruby_archive_add_dir(VALUE self, VALUE name) {
1446
+ struct zipruby_archive *p_archive;
1447
+
1448
+ Check_Type(name, T_STRING);
1449
+ Data_Get_Struct(self, struct zipruby_archive, p_archive);
1450
+ Check_Archive(p_archive);
1451
+
1452
+ if (zip_add_dir(p_archive->archive, RSTRING_PTR(name)) == -1) {
1453
+ zip_unchange_all(p_archive->archive);
1454
+ zip_unchange_archive(p_archive->archive);
1455
+ rb_raise(Error, "Add dir failed - %s: %s", RSTRING_PTR(name), zip_strerror(p_archive->archive));
1456
+ }
1457
+
1458
+ return Qnil;
1459
+ }
data/ext/zipruby_file.c CHANGED
@@ -31,6 +31,7 @@ static VALUE zipruby_file_mtime(VALUE self);
31
31
  static VALUE zipruby_file_comp_size(VALUE self);
32
32
  static VALUE zipruby_file_comp_method(VALUE self);
33
33
  static VALUE zipruby_file_encryption_method(VALUE self);
34
+ static VALUE zipruby_file_is_directory(VALUE self);
34
35
 
35
36
  extern VALUE Zip;
36
37
  extern VALUE Archive;
@@ -60,6 +61,7 @@ void Init_zipruby_file() {
60
61
  rb_define_method(File, "comp_size", zipruby_file_comp_size, 0);
61
62
  rb_define_method(File, "comp_method", zipruby_file_comp_method, 0);
62
63
  rb_define_method(File, "encryption_method", zipruby_file_encryption_method, 0);
64
+ rb_define_method(File, "directory?", zipruby_file_is_directory, 0);
63
65
  }
64
66
 
65
67
  static VALUE zipruby_file_alloc(VALUE klass) {
@@ -324,7 +326,7 @@ static VALUE zipruby_file_name(VALUE self) {
324
326
  Data_Get_Struct(self, struct zipruby_file, p_file);
325
327
  Check_File(p_file);
326
328
 
327
- return rb_funcall(p_file->v_sb, rb_intern("name"), 0);
329
+ return zipruby_stat_name(p_file->v_sb);
328
330
  }
329
331
 
330
332
  /* */
@@ -334,7 +336,7 @@ static VALUE zipruby_file_index(VALUE self) {
334
336
  Data_Get_Struct(self, struct zipruby_file, p_file);
335
337
  Check_File(p_file);
336
338
 
337
- return rb_funcall(p_file->v_sb, rb_intern("index"), 0);
339
+ return zipruby_stat_index(p_file->v_sb);
338
340
  }
339
341
 
340
342
  /* */
@@ -344,7 +346,7 @@ static VALUE zipruby_file_crc(VALUE self) {
344
346
  Data_Get_Struct(self, struct zipruby_file, p_file);
345
347
  Check_File(p_file);
346
348
 
347
- return rb_funcall(p_file->v_sb, rb_intern("crc"), 0);
349
+ return zipruby_stat_crc(p_file->v_sb);
348
350
  }
349
351
 
350
352
  /* */
@@ -354,7 +356,7 @@ static VALUE zipruby_file_size(VALUE self) {
354
356
  Data_Get_Struct(self, struct zipruby_file, p_file);
355
357
  Check_File(p_file);
356
358
 
357
- return rb_funcall(p_file->v_sb, rb_intern("size"), 0);
359
+ return zipruby_stat_size(p_file->v_sb);
358
360
  }
359
361
 
360
362
  /* */
@@ -364,7 +366,7 @@ static VALUE zipruby_file_mtime(VALUE self) {
364
366
  Data_Get_Struct(self, struct zipruby_file, p_file);
365
367
  Check_File(p_file);
366
368
 
367
- return rb_funcall(p_file->v_sb, rb_intern("mtime"), 0);
369
+ return zipruby_stat_mtime(p_file->v_sb);
368
370
  }
369
371
 
370
372
  /* */
@@ -374,7 +376,7 @@ static VALUE zipruby_file_comp_size(VALUE self) {
374
376
  Data_Get_Struct(self, struct zipruby_file, p_file);
375
377
  Check_File(p_file);
376
378
 
377
- return rb_funcall(p_file->v_sb, rb_intern("comp_size"), 0);
379
+ return zipruby_stat_comp_size(p_file->v_sb);
378
380
  }
379
381
 
380
382
  /* */
@@ -384,7 +386,7 @@ static VALUE zipruby_file_comp_method(VALUE self) {
384
386
  Data_Get_Struct(self, struct zipruby_file, p_file);
385
387
  Check_File(p_file);
386
388
 
387
- return rb_funcall(p_file->v_sb, rb_intern("comp_method"), 0);
389
+ return zipruby_stat_comp_method(p_file->v_sb);
388
390
  }
389
391
 
390
392
  /* */
@@ -394,5 +396,15 @@ static VALUE zipruby_file_encryption_method(VALUE self) {
394
396
  Data_Get_Struct(self, struct zipruby_file, p_file);
395
397
  Check_File(p_file);
396
398
 
397
- return rb_funcall(p_file->v_sb, rb_intern("encryption_method"), 0);
399
+ return zipruby_stat_encryption_method(p_file->v_sb);
400
+ }
401
+
402
+ /* */
403
+ static VALUE zipruby_file_is_directory(VALUE self) {
404
+ struct zipruby_file *p_file;
405
+
406
+ Data_Get_Struct(self, struct zipruby_file, p_file);
407
+ Check_File(p_file);
408
+
409
+ return zipruby_stat_is_directory(p_file->v_sb);
398
410
  }