tarruby 0.1.3-mswin32 → 0.1.4-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/README.txt CHANGED
@@ -48,11 +48,16 @@ gem install tarruby
48
48
 
49
49
  require 'tarruby'
50
50
 
51
+ buf = 'ABCDEFG'
52
+
51
53
  Tar.open('bar.tar', File::CREAT | File::WRONLY, 0644, Tar::GNU | Tar::VERBOSE) do |tar|
52
54
  Dir.glob('**/*.c').each do |filename|
53
55
  tar.append_file(filename)
54
56
  end
55
57
 
58
+ # append from buffer
59
+ tar.append_buffer('zoo.txt, buf)
60
+
56
61
  ##if append directory
57
62
  #tar.append_tree('dirname')
58
63
  end
data/ext/tarruby.c CHANGED
@@ -33,7 +33,7 @@
33
33
 
34
34
  #define INT2TIME(i) rb_funcall(rb_cTime, rb_intern("at"), 1, INT2NUM(i))
35
35
 
36
- #define VERSION "0.1.3"
36
+ #define VERSION "0.1.4"
37
37
 
38
38
  static VALUE Tar;
39
39
  static VALUE Error;
@@ -271,6 +271,35 @@ static VALUE tarruby_append_file(int argc, VALUE *argv, VALUE self) {
271
271
  return Qnil;
272
272
  }
273
273
 
274
+ static int tarruby_append_buffer0(char *buf, int len, void *data) {
275
+ char **p_buffer = (char **) data;
276
+ memcpy(buf, *p_buffer, len);
277
+ p_buffer += len;
278
+ return len;
279
+ }
280
+
281
+ /* */
282
+ static VALUE tarruby_append_buffer(VALUE self, VALUE savename, VALUE buffer) {
283
+ struct tarruby_tar *p_tar;
284
+ char *s_savename, *s_buffer;
285
+ int i_size;
286
+
287
+ Check_Type(savename, T_STRING);
288
+ Check_Type(buffer, T_STRING);
289
+ s_savename = RSTRING_PTR(savename);
290
+ strip_sep(s_savename);
291
+ s_buffer = RSTRING_PTR(buffer);
292
+ i_size = RSTRING_LEN(buffer);
293
+
294
+ Data_Get_Struct(self, struct tarruby_tar, p_tar);
295
+
296
+ if (tar_append_function(p_tar->tar, s_savename, i_size, (void *) &s_buffer, tarruby_append_buffer0) != 0) {
297
+ rb_raise(Error, "Append buffer failed: %s", strerror(errno));
298
+ }
299
+
300
+ return Qnil;
301
+ }
302
+
274
303
  /* */
275
304
  static VALUE tarruby_append_tree(int argc, VALUE *argv, VALUE self) {
276
305
  VALUE realdir, savedir;
@@ -323,7 +352,7 @@ static VALUE tarruby_extract_file(VALUE self, VALUE realname) {
323
352
  static int tarruby_extract_buffer0(char *buf, int len, void *data) {
324
353
  VALUE buffer = (VALUE) data;
325
354
  rb_str_buf_cat(buffer, buf, len);
326
- return 0;
355
+ return len;
327
356
  }
328
357
 
329
358
  /* */
@@ -650,6 +679,7 @@ void DLLEXPORT Init_tarruby() {
650
679
  #endif
651
680
  rb_define_method(Tar, "close", tarruby_close, 0);
652
681
  rb_define_method(Tar, "append_file", tarruby_append_file, -1);
682
+ rb_define_method(Tar, "append_buffer", tarruby_append_buffer, 2);
653
683
  rb_define_method(Tar, "append_tree", tarruby_append_tree, -1);
654
684
  rb_define_method(Tar, "extract_file", tarruby_extract_file, 1);
655
685
  rb_define_method(Tar, "extract_buffer", tarruby_extract_buffer, 0);
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tarruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
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-09-14 00:00:00 +09:00
12
+ date: 2008-09-16 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15