tarruby 0.1.0-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +99 -0
- data/ext/tarruby.c +648 -0
- data/lib/i386-mswin32/tarruby.so +0 -0
- metadata +57 -0
data/README.txt
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
= TAR/Ruby
|
2
|
+
|
3
|
+
Copyright (c) 2008 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
Ruby bindings for libtar.
|
8
|
+
|
9
|
+
libtar is a C library for manipulating POSIX tar files.
|
10
|
+
|
11
|
+
== Project Page
|
12
|
+
|
13
|
+
http://rubyforge.org/projects/tarruby
|
14
|
+
|
15
|
+
== Install
|
16
|
+
|
17
|
+
gem install tarruby
|
18
|
+
|
19
|
+
== Example
|
20
|
+
=== reading tar archive
|
21
|
+
|
22
|
+
require 'tarruby'
|
23
|
+
|
24
|
+
Tar.open('foo.tar', File::RDONLY) do |tar|
|
25
|
+
while tar.read # or 'tar.each do ...'
|
26
|
+
puts tar.pathname
|
27
|
+
tar.print_long_ls
|
28
|
+
|
29
|
+
if tar.reg? # regular file
|
30
|
+
tar.extract_file('bar.txt')
|
31
|
+
|
32
|
+
##if extract buffer
|
33
|
+
#puts tar.extract_buffer
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
##if extract all files
|
38
|
+
#tar.extract_all
|
39
|
+
end
|
40
|
+
|
41
|
+
##for gzip archive
|
42
|
+
#Tar.gzopen('foo.tar.gz', ...
|
43
|
+
|
44
|
+
##for bzip2 archive
|
45
|
+
#Tar.bzopen('foo.tar.bz2', ...
|
46
|
+
|
47
|
+
=== creating tar archive
|
48
|
+
|
49
|
+
require 'tarruby'
|
50
|
+
|
51
|
+
Tar.open('bar.tar', File::CREAT | File::WRONLY) do |tar|
|
52
|
+
Dir.glob('**/*.c').each do |filename|
|
53
|
+
tar.append_file(filename)
|
54
|
+
end
|
55
|
+
|
56
|
+
##if append directory
|
57
|
+
#tar.append_tree('dirname')
|
58
|
+
end
|
59
|
+
|
60
|
+
##for gzip archive
|
61
|
+
#Tar.gzopen('foo.tar.gz', ...
|
62
|
+
|
63
|
+
##for bzip2 archive
|
64
|
+
#Tar.bzopen('foo.tar.bz2', ...
|
65
|
+
|
66
|
+
== License
|
67
|
+
Copyright (c) 2008 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
68
|
+
All rights reserved.
|
69
|
+
|
70
|
+
Redistribution and use in source and binary forms, with or without modification,
|
71
|
+
are permitted provided that the following conditions are met:
|
72
|
+
|
73
|
+
* Redistributions of source code must retain the above copyright notice,
|
74
|
+
this list of conditions and the following disclaimer.
|
75
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
76
|
+
this list of conditions and the following disclaimer in the documentation
|
77
|
+
and/or other materials provided with the distribution.
|
78
|
+
* The names of its contributors may be used to endorse or promote products
|
79
|
+
derived from this software without specific prior written permission.
|
80
|
+
|
81
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
82
|
+
ANY EXPRESS OR IMPLIED WARRANTIES,
|
83
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
84
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
85
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
86
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
87
|
+
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
88
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
89
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
90
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
91
|
+
DAMAGE.
|
92
|
+
|
93
|
+
=== libtar
|
94
|
+
TAR/Ruby contains libtar.
|
95
|
+
|
96
|
+
* libtar is a C library for manipulating POSIX tar files.
|
97
|
+
* http://www.feep.net/libtar/
|
98
|
+
* patches
|
99
|
+
* https://lists.feep.net:8080/pipermail/libtar/2007-July/000240.html
|
data/ext/tarruby.c
ADDED
@@ -0,0 +1,648 @@
|
|
1
|
+
#include <fcntl.h>
|
2
|
+
#include <errno.h>
|
3
|
+
#ifdef HAVE_ZLIB_H
|
4
|
+
#include <zlib.h>
|
5
|
+
#endif
|
6
|
+
#ifdef HAVE_BZLIB_H
|
7
|
+
#include <bzlib.h>
|
8
|
+
#endif
|
9
|
+
#include "libtar.h"
|
10
|
+
#include "ruby.h"
|
11
|
+
|
12
|
+
#ifndef RSTRING_PTR
|
13
|
+
#define RSTRING_PTR(s) (RSTRING(s)->ptr)
|
14
|
+
#endif
|
15
|
+
#ifndef RSTRING_LEN
|
16
|
+
#define RSTRING_LEN(s) (RSTRING(s)->len)
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#ifdef TARRUBY_EXPORTS
|
20
|
+
#define DLLEXPORT __declspec(dllexport)
|
21
|
+
#else
|
22
|
+
#define DLLEXPORT
|
23
|
+
#endif
|
24
|
+
|
25
|
+
#ifndef S_ISREG
|
26
|
+
#define S_ISREG(m) (((m) & (_S_IFMT)) == (_S_IFREG))
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#ifndef O_ACCMODE
|
30
|
+
#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
|
31
|
+
#endif
|
32
|
+
|
33
|
+
#define INT2TIME(i) rb_funcall(rb_cTime, rb_intern("at"), 1, INT2NUM(i))
|
34
|
+
|
35
|
+
#define VERSION "0.1.0"
|
36
|
+
|
37
|
+
static VALUE Tar;
|
38
|
+
static VALUE Error;
|
39
|
+
|
40
|
+
struct tarruby_tar {
|
41
|
+
TAR *tar;
|
42
|
+
int extracted;
|
43
|
+
};
|
44
|
+
|
45
|
+
#ifdef HAVE_ZLIB_H
|
46
|
+
// copy from libtar.c
|
47
|
+
// Copyright 1998-2003 University of Illinois Board of Trustees
|
48
|
+
// Copyright 1998-2003 Mark D. Roth
|
49
|
+
static int gzopen_frontend(char *pathname, int oflags, int mode) {
|
50
|
+
char *gzoflags;
|
51
|
+
gzFile gzf;
|
52
|
+
#ifndef _WIN32
|
53
|
+
int fd;
|
54
|
+
#endif
|
55
|
+
|
56
|
+
switch (oflags & O_ACCMODE) {
|
57
|
+
case O_WRONLY:
|
58
|
+
gzoflags = "wb";
|
59
|
+
break;
|
60
|
+
|
61
|
+
case O_RDONLY:
|
62
|
+
gzoflags = "rb";
|
63
|
+
break;
|
64
|
+
|
65
|
+
default:
|
66
|
+
case O_RDWR:
|
67
|
+
errno = EINVAL;
|
68
|
+
return -1;
|
69
|
+
}
|
70
|
+
|
71
|
+
#ifndef _WIN32
|
72
|
+
fd = open(pathname, oflags, mode);
|
73
|
+
|
74
|
+
if (fd == -1) {
|
75
|
+
return -1;
|
76
|
+
}
|
77
|
+
|
78
|
+
if ((oflags & O_CREAT) && fchmod(fd, mode)) {
|
79
|
+
return -1;
|
80
|
+
}
|
81
|
+
|
82
|
+
gzf = gzdopen(fd, gzoflags);
|
83
|
+
#else
|
84
|
+
gzf = gzopen(pathname, gzoflags);
|
85
|
+
#endif
|
86
|
+
if (!gzf) {
|
87
|
+
errno = ENOMEM;
|
88
|
+
return -1;
|
89
|
+
}
|
90
|
+
|
91
|
+
return (int) gzf;
|
92
|
+
}
|
93
|
+
|
94
|
+
static tartype_t gztype = {
|
95
|
+
(openfunc_t) gzopen_frontend,
|
96
|
+
(closefunc_t) gzclose,
|
97
|
+
(readfunc_t) gzread,
|
98
|
+
(writefunc_t) gzwrite
|
99
|
+
};
|
100
|
+
#endif
|
101
|
+
|
102
|
+
#ifdef HAVE_BZLIB_H
|
103
|
+
static int bzopen_frontend(char *pathname, int oflags, int mode) {
|
104
|
+
char *bzoflags;
|
105
|
+
BZFILE *bzf;
|
106
|
+
#ifndef _WIN32
|
107
|
+
int fd;
|
108
|
+
#endif
|
109
|
+
|
110
|
+
switch (oflags & O_ACCMODE) {
|
111
|
+
case O_WRONLY:
|
112
|
+
bzoflags = "wb";
|
113
|
+
break;
|
114
|
+
|
115
|
+
case O_RDONLY:
|
116
|
+
bzoflags = "rb";
|
117
|
+
break;
|
118
|
+
|
119
|
+
default:
|
120
|
+
case O_RDWR:
|
121
|
+
errno = EINVAL;
|
122
|
+
return -1;
|
123
|
+
}
|
124
|
+
|
125
|
+
#ifndef _WIN32
|
126
|
+
fd = open(pathname, oflags, mode);
|
127
|
+
|
128
|
+
if (fd == -1) {
|
129
|
+
return -1;
|
130
|
+
}
|
131
|
+
|
132
|
+
if ((oflags & O_CREAT) && fchmod(fd, mode)) {
|
133
|
+
return -1;
|
134
|
+
}
|
135
|
+
|
136
|
+
bzf = BZ2_bzdopen(fd, bzoflags);
|
137
|
+
#else
|
138
|
+
bzf = BZ2_bzopen(pathname, bzoflags);
|
139
|
+
#endif
|
140
|
+
if (!bzf) {
|
141
|
+
errno = ENOMEM;
|
142
|
+
return -1;
|
143
|
+
}
|
144
|
+
|
145
|
+
return (int) bzf;
|
146
|
+
}
|
147
|
+
|
148
|
+
static tartype_t bztype = {
|
149
|
+
(openfunc_t) bzopen_frontend,
|
150
|
+
(closefunc_t) BZ2_bzclose,
|
151
|
+
(readfunc_t) BZ2_bzread,
|
152
|
+
(writefunc_t) BZ2_bzwrite
|
153
|
+
};
|
154
|
+
#endif
|
155
|
+
|
156
|
+
static VALUE tarruby_tar_alloc(VALUE klass) {
|
157
|
+
struct tarruby_tar *p = ALLOC(struct tarruby_tar);
|
158
|
+
|
159
|
+
p->tar = NULL;
|
160
|
+
p->extracted = 1;
|
161
|
+
|
162
|
+
return Data_Wrap_Struct(klass, 0, -1, p);
|
163
|
+
}
|
164
|
+
|
165
|
+
/* */
|
166
|
+
static VALUE tarruby_close(VALUE self) {
|
167
|
+
struct tarruby_tar *p_tar;
|
168
|
+
|
169
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
170
|
+
|
171
|
+
if(tar_close(p_tar->tar) != 0) {
|
172
|
+
rb_raise(Error, "Close archive failed");
|
173
|
+
}
|
174
|
+
|
175
|
+
return Qnil;
|
176
|
+
}
|
177
|
+
|
178
|
+
static VALUE tarruby_s_open0(int argc, VALUE *argv, VALUE self, tartype_t *tartype) {
|
179
|
+
VALUE tar, pathname, oflags, mode, options;
|
180
|
+
struct tarruby_tar *p_tar;
|
181
|
+
char *s_pathname;
|
182
|
+
int i_oflags, i_mode = 0644, i_options = 0;
|
183
|
+
|
184
|
+
rb_scan_args(argc, argv, "22", &pathname, &oflags, &mode, &options);
|
185
|
+
Check_Type(pathname, T_STRING);
|
186
|
+
s_pathname = RSTRING_PTR(pathname);
|
187
|
+
i_oflags = NUM2INT(oflags);
|
188
|
+
if (!NIL_P(mode)) { i_mode = NUM2INT(mode); }
|
189
|
+
if (!NIL_P(options)) { i_options = NUM2INT(options); }
|
190
|
+
|
191
|
+
tar = rb_funcall(Tar, rb_intern("new"), 0);
|
192
|
+
Data_Get_Struct(tar, struct tarruby_tar, p_tar);
|
193
|
+
|
194
|
+
if (tar_open(&p_tar->tar, s_pathname, tartype, i_oflags, i_mode, i_options) == -1) {
|
195
|
+
rb_raise(Error, "Open archive failed");
|
196
|
+
}
|
197
|
+
|
198
|
+
if (rb_block_given_p()) {
|
199
|
+
VALUE retval;
|
200
|
+
int status;
|
201
|
+
|
202
|
+
retval = rb_protect(rb_yield, tar, &status);
|
203
|
+
tarruby_close(tar);
|
204
|
+
|
205
|
+
if (status != 0) {
|
206
|
+
rb_jump_tag(status);
|
207
|
+
}
|
208
|
+
|
209
|
+
return retval;
|
210
|
+
} else {
|
211
|
+
return tar;
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
/* */
|
216
|
+
static VALUE tarruby_s_open(int argc, VALUE *argv, VALUE self) {
|
217
|
+
return tarruby_s_open0(argc, argv, self, NULL);
|
218
|
+
}
|
219
|
+
|
220
|
+
#ifdef HAVE_ZLIB_H
|
221
|
+
/* */
|
222
|
+
static VALUE tarruby_s_gzopen(int argc, VALUE *argv, VALUE self) {
|
223
|
+
return tarruby_s_open0(argc, argv, self, &gztype);
|
224
|
+
}
|
225
|
+
#endif
|
226
|
+
|
227
|
+
#ifdef HAVE_BZLIB_H
|
228
|
+
/* */
|
229
|
+
static VALUE tarruby_s_bzopen(int argc, VALUE *argv, VALUE self) {
|
230
|
+
return tarruby_s_open0(argc, argv, self, &bztype);
|
231
|
+
}
|
232
|
+
#endif
|
233
|
+
|
234
|
+
/* */
|
235
|
+
static VALUE tarruby_append_file(int argc, VALUE *argv, VALUE self) {
|
236
|
+
VALUE realname, savename;
|
237
|
+
struct tarruby_tar *p_tar;
|
238
|
+
char *s_realname, *s_savename = NULL;
|
239
|
+
|
240
|
+
rb_scan_args(argc, argv, "11", &realname, &savename);
|
241
|
+
Check_Type(realname, T_STRING);
|
242
|
+
s_realname = RSTRING_PTR(realname);
|
243
|
+
|
244
|
+
if (!NIL_P(savename)) {
|
245
|
+
Check_Type(savename, T_STRING);
|
246
|
+
s_savename = RSTRING_PTR(savename);
|
247
|
+
}
|
248
|
+
|
249
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
250
|
+
|
251
|
+
if (tar_append_file(p_tar->tar, s_realname, s_savename) != 0) {
|
252
|
+
rb_raise(Error, "Append file failed");
|
253
|
+
}
|
254
|
+
|
255
|
+
return Qnil;
|
256
|
+
}
|
257
|
+
|
258
|
+
/* */
|
259
|
+
static VALUE tarruby_append_tree(int argc, VALUE *argv, VALUE self) {
|
260
|
+
VALUE realdir, savedir;
|
261
|
+
struct tarruby_tar *p_tar;
|
262
|
+
char *s_realdir, *s_savedir = NULL;
|
263
|
+
|
264
|
+
rb_scan_args(argc, argv, "11", &realdir, &savedir);
|
265
|
+
Check_Type(realdir, T_STRING);
|
266
|
+
s_realdir = RSTRING_PTR(realdir);
|
267
|
+
|
268
|
+
if (!NIL_P(savedir)) {
|
269
|
+
Check_Type(savedir, T_STRING);
|
270
|
+
s_savedir = RSTRING_PTR(savedir);
|
271
|
+
}
|
272
|
+
|
273
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
274
|
+
|
275
|
+
if (tar_append_tree(p_tar->tar, s_realdir, s_savedir) != 0) {
|
276
|
+
rb_raise(Error, "Append tree failed");
|
277
|
+
}
|
278
|
+
|
279
|
+
return Qnil;
|
280
|
+
}
|
281
|
+
|
282
|
+
/* */
|
283
|
+
static VALUE tarruby_extract_file(VALUE self, VALUE realname) {
|
284
|
+
struct tarruby_tar *p_tar;
|
285
|
+
char *s_realname;
|
286
|
+
|
287
|
+
Check_Type(realname, T_STRING);
|
288
|
+
s_realname = RSTRING_PTR(realname);
|
289
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
290
|
+
|
291
|
+
if (tar_extract_file(p_tar->tar, s_realname) != 0) {
|
292
|
+
rb_raise(Error, "Extract file failed");
|
293
|
+
}
|
294
|
+
|
295
|
+
p_tar->extracted = 1;
|
296
|
+
|
297
|
+
return Qnil;
|
298
|
+
}
|
299
|
+
|
300
|
+
static int tarruby_extract_buffer0(char *buf, int len, void *data) {
|
301
|
+
VALUE buffer = (VALUE) data;
|
302
|
+
rb_str_buf_cat(buffer, buf, len);
|
303
|
+
return 0;
|
304
|
+
}
|
305
|
+
|
306
|
+
/* */
|
307
|
+
static VALUE tarruby_extract_buffer(VALUE self) {
|
308
|
+
VALUE buffer;
|
309
|
+
struct tarruby_tar *p_tar;
|
310
|
+
int i;
|
311
|
+
|
312
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
313
|
+
buffer = rb_str_new("", 0);
|
314
|
+
|
315
|
+
if ((i = tar_extract_function(p_tar->tar, (void *) buffer, tarruby_extract_buffer0)) == -1) {
|
316
|
+
rb_raise(Error, "Extract buffer failed");
|
317
|
+
}
|
318
|
+
|
319
|
+
p_tar->extracted = 1;
|
320
|
+
|
321
|
+
return (i == 0) ? buffer : Qnil;
|
322
|
+
}
|
323
|
+
|
324
|
+
/* */
|
325
|
+
static VALUE tarruby_extract_glob(int argc, VALUE *argv, VALUE self) {
|
326
|
+
VALUE globname, prefix;
|
327
|
+
struct tarruby_tar *p_tar;
|
328
|
+
char *s_globname, *s_prefix = NULL;
|
329
|
+
|
330
|
+
rb_scan_args(argc, argv, "11", &globname, &prefix);
|
331
|
+
Check_Type(globname, T_STRING);
|
332
|
+
s_globname = RSTRING_PTR(globname);
|
333
|
+
|
334
|
+
if (!NIL_P(prefix)) {
|
335
|
+
Check_Type(prefix, T_STRING);
|
336
|
+
s_prefix = RSTRING_PTR(prefix);
|
337
|
+
}
|
338
|
+
|
339
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
340
|
+
|
341
|
+
if (tar_extract_glob(p_tar->tar, s_globname, s_prefix) != 0) {
|
342
|
+
rb_raise(Error, "Extract archive failed");
|
343
|
+
}
|
344
|
+
|
345
|
+
p_tar->extracted = 1;
|
346
|
+
|
347
|
+
return Qnil;
|
348
|
+
}
|
349
|
+
|
350
|
+
/* */
|
351
|
+
static VALUE tarruby_extract_all(int argc, VALUE *argv, VALUE self) {
|
352
|
+
VALUE prefix;
|
353
|
+
struct tarruby_tar *p_tar;
|
354
|
+
char *s_prefix = NULL;
|
355
|
+
|
356
|
+
rb_scan_args(argc, argv, "01", &prefix);
|
357
|
+
|
358
|
+
if (!NIL_P(prefix)) {
|
359
|
+
Check_Type(prefix, T_STRING);
|
360
|
+
s_prefix = RSTRING_PTR(prefix);
|
361
|
+
}
|
362
|
+
|
363
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
364
|
+
|
365
|
+
if (tar_extract_all(p_tar->tar, s_prefix) != 0) {
|
366
|
+
rb_raise(Error, "Extract archive failed");
|
367
|
+
}
|
368
|
+
|
369
|
+
p_tar->extracted = 1;
|
370
|
+
|
371
|
+
return Qnil;
|
372
|
+
}
|
373
|
+
|
374
|
+
static void tarruby_skip_regfile_if_not_extracted(struct tarruby_tar *p) {
|
375
|
+
if (!p->extracted) {
|
376
|
+
if (TH_ISREG(p->tar) && tar_skip_regfile(p->tar) != 0) {
|
377
|
+
rb_raise(Error, "Read archive failed");
|
378
|
+
}
|
379
|
+
|
380
|
+
p->extracted = 1;
|
381
|
+
}
|
382
|
+
}
|
383
|
+
|
384
|
+
/* */
|
385
|
+
static VALUE tarruby_read(VALUE self) {
|
386
|
+
struct tarruby_tar *p_tar;
|
387
|
+
int i;
|
388
|
+
|
389
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
390
|
+
tarruby_skip_regfile_if_not_extracted(p_tar);
|
391
|
+
|
392
|
+
if ((i = th_read(p_tar->tar)) == -1) {
|
393
|
+
rb_raise(Error, "Read archive failed");
|
394
|
+
}
|
395
|
+
|
396
|
+
p_tar->extracted = 0;
|
397
|
+
|
398
|
+
return (i == 0) ? Qtrue : Qfalse;
|
399
|
+
}
|
400
|
+
|
401
|
+
/* */
|
402
|
+
static VALUE tarruby_each(VALUE self) {
|
403
|
+
struct tarruby_tar *p_tar;
|
404
|
+
int i;
|
405
|
+
|
406
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
407
|
+
tarruby_skip_regfile_if_not_extracted(p_tar);
|
408
|
+
|
409
|
+
while ((i = th_read(p_tar->tar)) == 0) {
|
410
|
+
p_tar->extracted = 0;
|
411
|
+
rb_yield(self);
|
412
|
+
tarruby_skip_regfile_if_not_extracted(p_tar);
|
413
|
+
}
|
414
|
+
|
415
|
+
if (i == -1) {
|
416
|
+
rb_raise(Error, "Read archive failed");
|
417
|
+
}
|
418
|
+
|
419
|
+
return Qnil;
|
420
|
+
}
|
421
|
+
|
422
|
+
/* */
|
423
|
+
static VALUE tarruby_crc(VALUE self) {
|
424
|
+
struct tarruby_tar *p_tar;
|
425
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
426
|
+
return INT2NUM(th_get_crc(p_tar->tar));
|
427
|
+
}
|
428
|
+
|
429
|
+
/* */
|
430
|
+
static VALUE tarruby_size(VALUE self) {
|
431
|
+
struct tarruby_tar *p_tar;
|
432
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
433
|
+
return INT2NUM(th_get_size(p_tar->tar));
|
434
|
+
}
|
435
|
+
|
436
|
+
/* */
|
437
|
+
static VALUE tarruby_mtime(VALUE self) {
|
438
|
+
struct tarruby_tar *p_tar;
|
439
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
440
|
+
return INT2TIME(th_get_mtime(p_tar->tar));
|
441
|
+
}
|
442
|
+
|
443
|
+
/* */
|
444
|
+
static VALUE tarruby_devmajor(VALUE self) {
|
445
|
+
struct tarruby_tar *p_tar;
|
446
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
447
|
+
return INT2NUM(th_get_devmajor(p_tar->tar));
|
448
|
+
}
|
449
|
+
|
450
|
+
/* */
|
451
|
+
static VALUE tarruby_devminor(VALUE self) {
|
452
|
+
struct tarruby_tar *p_tar;
|
453
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
454
|
+
return INT2NUM(th_get_devminor(p_tar->tar));
|
455
|
+
}
|
456
|
+
|
457
|
+
/* */
|
458
|
+
static VALUE tarruby_linkname(VALUE self) {
|
459
|
+
struct tarruby_tar *p_tar;
|
460
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
461
|
+
return rb_str_new2(th_get_linkname(p_tar->tar));
|
462
|
+
}
|
463
|
+
|
464
|
+
/* */
|
465
|
+
static VALUE tarruby_pathname(VALUE self) {
|
466
|
+
struct tarruby_tar *p_tar;
|
467
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
468
|
+
return rb_str_new2(th_get_pathname(p_tar->tar));
|
469
|
+
}
|
470
|
+
|
471
|
+
/* */
|
472
|
+
static VALUE tarruby_mode(VALUE self) {
|
473
|
+
struct tarruby_tar *p_tar;
|
474
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
475
|
+
return LONG2NUM(th_get_mode(p_tar->tar));
|
476
|
+
}
|
477
|
+
|
478
|
+
/* */
|
479
|
+
static VALUE tarruby_uid(VALUE self) {
|
480
|
+
struct tarruby_tar *p_tar;
|
481
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
482
|
+
return LONG2NUM(th_get_uid(p_tar->tar));
|
483
|
+
}
|
484
|
+
|
485
|
+
/* */
|
486
|
+
static VALUE tarruby_gid(VALUE self) {
|
487
|
+
struct tarruby_tar *p_tar;
|
488
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
489
|
+
return LONG2NUM(th_get_gid(p_tar->tar));
|
490
|
+
}
|
491
|
+
|
492
|
+
/* */
|
493
|
+
static VALUE tarruby_print(VALUE self) {
|
494
|
+
struct tarruby_tar *p_tar;
|
495
|
+
|
496
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
497
|
+
th_print(p_tar->tar);
|
498
|
+
|
499
|
+
return Qnil;
|
500
|
+
}
|
501
|
+
|
502
|
+
/* */
|
503
|
+
static VALUE tarruby_print_long_ls(VALUE self) {
|
504
|
+
struct tarruby_tar *p_tar;
|
505
|
+
|
506
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
507
|
+
th_print_long_ls(p_tar->tar);
|
508
|
+
|
509
|
+
return Qnil;
|
510
|
+
}
|
511
|
+
|
512
|
+
/* */
|
513
|
+
static VALUE tarruby_is_reg(VALUE self) {
|
514
|
+
struct tarruby_tar *p_tar;
|
515
|
+
|
516
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
517
|
+
|
518
|
+
return TH_ISREG(p_tar->tar) ? Qtrue : Qfalse;
|
519
|
+
}
|
520
|
+
|
521
|
+
/* */
|
522
|
+
static VALUE tarruby_is_lnk(VALUE self) {
|
523
|
+
struct tarruby_tar *p_tar;
|
524
|
+
|
525
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
526
|
+
|
527
|
+
return TH_ISLNK(p_tar->tar) ? Qtrue : Qfalse;
|
528
|
+
}
|
529
|
+
|
530
|
+
/* */
|
531
|
+
static VALUE tarruby_is_sym(VALUE self) {
|
532
|
+
struct tarruby_tar *p_tar;
|
533
|
+
|
534
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
535
|
+
|
536
|
+
return TH_ISSYM(p_tar->tar) ? Qtrue : Qfalse;
|
537
|
+
}
|
538
|
+
|
539
|
+
/* */
|
540
|
+
static VALUE tarruby_is_chr(VALUE self) {
|
541
|
+
struct tarruby_tar *p_tar;
|
542
|
+
|
543
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
544
|
+
|
545
|
+
return TH_ISCHR(p_tar->tar) ? Qtrue : Qfalse;
|
546
|
+
}
|
547
|
+
|
548
|
+
/* */
|
549
|
+
static VALUE tarruby_is_blk(VALUE self) {
|
550
|
+
struct tarruby_tar *p_tar;
|
551
|
+
|
552
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
553
|
+
|
554
|
+
return TH_ISBLK(p_tar->tar) ? Qtrue : Qfalse;
|
555
|
+
}
|
556
|
+
|
557
|
+
/* */
|
558
|
+
static VALUE tarruby_is_dir(VALUE self) {
|
559
|
+
struct tarruby_tar *p_tar;
|
560
|
+
|
561
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
562
|
+
|
563
|
+
return TH_ISDIR(p_tar->tar) ? Qtrue : Qfalse;
|
564
|
+
}
|
565
|
+
|
566
|
+
/* */
|
567
|
+
static VALUE tarruby_is_fifo(VALUE self) {
|
568
|
+
struct tarruby_tar *p_tar;
|
569
|
+
|
570
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
571
|
+
|
572
|
+
return TH_ISFIFO(p_tar->tar) ? Qtrue : Qfalse;
|
573
|
+
}
|
574
|
+
|
575
|
+
/* */
|
576
|
+
static VALUE tarruby_is_longname(VALUE self) {
|
577
|
+
struct tarruby_tar *p_tar;
|
578
|
+
|
579
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
580
|
+
|
581
|
+
return TH_ISLONGNAME(p_tar->tar) ? Qtrue : Qfalse;
|
582
|
+
}
|
583
|
+
|
584
|
+
/* */
|
585
|
+
static VALUE tarruby_is_longlink(VALUE self) {
|
586
|
+
struct tarruby_tar *p_tar;
|
587
|
+
|
588
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
589
|
+
|
590
|
+
return TH_ISLONGLINK(p_tar->tar) ? Qtrue : Qfalse;
|
591
|
+
}
|
592
|
+
|
593
|
+
void DLLEXPORT Init_tarruby() {
|
594
|
+
Tar = rb_define_class("Tar", rb_cObject);
|
595
|
+
rb_define_alloc_func(Tar, tarruby_tar_alloc);
|
596
|
+
rb_include_module(Tar, rb_mEnumerable);
|
597
|
+
rb_funcall(Tar, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")));
|
598
|
+
|
599
|
+
Error = rb_define_class_under(Tar, "Error", rb_eStandardError);
|
600
|
+
|
601
|
+
rb_define_const(Tar, "VERSION", rb_str_new2(VERSION));
|
602
|
+
|
603
|
+
rb_define_const(Tar, "GNU", INT2NUM(TAR_GNU)); /* use GNU extensions */
|
604
|
+
rb_define_const(Tar, "VERBOSE", INT2NUM(TAR_VERBOSE)); /* output file info to stdout */
|
605
|
+
rb_define_const(Tar, "NOOVERWRITE", INT2NUM(TAR_NOOVERWRITE)); /* don't overwrite existing files */
|
606
|
+
rb_define_const(Tar, "IGNORE_EOT", INT2NUM(TAR_IGNORE_EOT)); /* ignore double zero blocks as EOF */
|
607
|
+
rb_define_const(Tar, "CHECK_MAGIC", INT2NUM(TAR_CHECK_MAGIC)); /* check magic in file header */
|
608
|
+
rb_define_const(Tar, "CHECK_VERSION", INT2NUM(TAR_CHECK_VERSION)); /* check version in file header */
|
609
|
+
rb_define_const(Tar, "IGNORE_CRC", INT2NUM(TAR_IGNORE_CRC)); /* ignore CRC in file header */
|
610
|
+
|
611
|
+
rb_define_singleton_method(Tar, "open", tarruby_s_open, -1);
|
612
|
+
#ifdef HAVE_ZLIB_H
|
613
|
+
rb_define_singleton_method(Tar, "gzopen", tarruby_s_gzopen, -1);
|
614
|
+
#endif
|
615
|
+
#ifdef HAVE_BZLIB_H
|
616
|
+
rb_define_singleton_method(Tar, "bzopen", tarruby_s_bzopen, -1);
|
617
|
+
#endif
|
618
|
+
rb_define_method(Tar, "close", tarruby_close, 0);
|
619
|
+
rb_define_method(Tar, "append_file", tarruby_append_file, -1);
|
620
|
+
rb_define_method(Tar, "append_tree", tarruby_append_tree, -1);
|
621
|
+
rb_define_method(Tar, "extract_file", tarruby_extract_file, 1);
|
622
|
+
rb_define_method(Tar, "extract_buffer", tarruby_extract_buffer, 0);
|
623
|
+
rb_define_method(Tar, "extract_glob", tarruby_extract_glob, -1);
|
624
|
+
rb_define_method(Tar, "extract_all", tarruby_extract_all, -1);
|
625
|
+
rb_define_method(Tar, "read", tarruby_read, 0);
|
626
|
+
rb_define_method(Tar, "each", tarruby_each, 0);
|
627
|
+
rb_define_method(Tar, "crc", tarruby_crc, 0);
|
628
|
+
rb_define_method(Tar, "size", tarruby_size, 0);
|
629
|
+
rb_define_method(Tar, "mtime", tarruby_mtime, 0);
|
630
|
+
rb_define_method(Tar, "devmajor", tarruby_devmajor, 0);
|
631
|
+
rb_define_method(Tar, "devminor", tarruby_devminor, 0);
|
632
|
+
rb_define_method(Tar, "linkname", tarruby_linkname, 0);
|
633
|
+
rb_define_method(Tar, "pathname", tarruby_pathname, 0);
|
634
|
+
rb_define_method(Tar, "mode", tarruby_mode, 0);
|
635
|
+
rb_define_method(Tar, "uid", tarruby_uid, 0);
|
636
|
+
rb_define_method(Tar, "gid", tarruby_gid, 0);
|
637
|
+
rb_define_method(Tar, "print", tarruby_print, 0);
|
638
|
+
rb_define_method(Tar, "print_long_ls", tarruby_print_long_ls, 0);
|
639
|
+
rb_define_method(Tar, "reg?", tarruby_is_reg, 0);
|
640
|
+
rb_define_method(Tar, "lnk?", tarruby_is_lnk, 0);
|
641
|
+
rb_define_method(Tar, "sym?", tarruby_is_sym, 0);
|
642
|
+
rb_define_method(Tar, "chr?", tarruby_is_chr, 0);
|
643
|
+
rb_define_method(Tar, "blk?", tarruby_is_blk, 0);
|
644
|
+
rb_define_method(Tar, "dir?", tarruby_is_dir, 0);
|
645
|
+
rb_define_method(Tar, "fifo?", tarruby_is_fifo, 0);
|
646
|
+
rb_define_method(Tar, "longname?", tarruby_is_longname, 0);
|
647
|
+
rb_define_method(Tar, "longlink?", tarruby_is_longlink, 0);
|
648
|
+
}
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tarruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: mswin32
|
6
|
+
authors:
|
7
|
+
- winebarrel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-09-11 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: sgwr_dts@yahoo.co.jp
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.txt
|
24
|
+
- ext/tarruby.c
|
25
|
+
files:
|
26
|
+
- lib/i386-mswin32/tarruby.so
|
27
|
+
- README.txt
|
28
|
+
- ext/tarruby.c
|
29
|
+
has_rdoc: true
|
30
|
+
homepage: http://tarruby.rubyforge.org
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options:
|
33
|
+
- --title
|
34
|
+
- TAR/Ruby - Ruby bindings for libtar.
|
35
|
+
require_paths:
|
36
|
+
- lib/i386-mswin32
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
42
|
+
version:
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
rubyforge_project: tarruby
|
52
|
+
rubygems_version: 1.2.0
|
53
|
+
signing_key:
|
54
|
+
specification_version: 2
|
55
|
+
summary: Ruby bindings for libtar.
|
56
|
+
test_files: []
|
57
|
+
|