libarchive-ruby-swig 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/libarchive-ruby-swig/writer.cpp +65 -30
- data/ext/libarchive-ruby-swig/writer.h +7 -0
- data/lib/libarchive_rs.rb +18 -0
- metadata +4 -4
@@ -41,6 +41,31 @@ void Writer::close()
|
|
41
41
|
}
|
42
42
|
|
43
43
|
|
44
|
+
Writer *Writer::write_open_filename(const char *filename,
|
45
|
+
const char *cmd, int format)
|
46
|
+
|
47
|
+
{
|
48
|
+
std::string error_msg;
|
49
|
+
struct archive *ar = archive_write_new();
|
50
|
+
|
51
|
+
archive_write_set_compression_program(ar, cmd);
|
52
|
+
try {
|
53
|
+
set_format_helper(ar, format);
|
54
|
+
|
55
|
+
if(archive_write_open_filename(ar, filename) != ARCHIVE_OK) {
|
56
|
+
error_msg = archive_error_string(ar);
|
57
|
+
throw Error(error_msg);
|
58
|
+
}
|
59
|
+
|
60
|
+
} catch(...) {
|
61
|
+
archive_write_finish(ar);
|
62
|
+
throw;
|
63
|
+
}
|
64
|
+
|
65
|
+
return new Writer(ar);
|
66
|
+
}
|
67
|
+
|
68
|
+
|
44
69
|
Writer *Writer::write_open_filename(const char *filename,
|
45
70
|
int compression, int format)
|
46
71
|
{
|
@@ -73,36 +98,7 @@ Writer *Writer::write_open_filename(const char *filename,
|
|
73
98
|
throw Error(error_msg);
|
74
99
|
}
|
75
100
|
|
76
|
-
|
77
|
-
case Archive::FORMAT_AR_BSD:
|
78
|
-
archive_write_set_format_ar_bsd(ar);
|
79
|
-
break;
|
80
|
-
case Archive::FORMAT_AR_SVR4:
|
81
|
-
archive_write_set_format_ar_svr4(ar);
|
82
|
-
break;
|
83
|
-
case Archive::FORMAT_CPIO:
|
84
|
-
archive_write_set_format_cpio(ar);
|
85
|
-
break;
|
86
|
-
case Archive::FORMAT_CPIO_NEWC:
|
87
|
-
archive_write_set_format_cpio_newc(ar);
|
88
|
-
break;
|
89
|
-
case Archive::FORMAT_MTREE:
|
90
|
-
archive_write_set_format_mtree(ar);
|
91
|
-
break;
|
92
|
-
case Archive::FORMAT_TAR:
|
93
|
-
case Archive::FORMAT_TAR_PAX_RESTRICTED:
|
94
|
-
archive_write_set_format_pax_restricted(ar);
|
95
|
-
break;
|
96
|
-
case Archive::FORMAT_TAR_PAX_INTERCHANGE:
|
97
|
-
archive_write_set_format_pax(ar);
|
98
|
-
break;
|
99
|
-
case Archive::FORMAT_TAR_USTAR:
|
100
|
-
archive_write_set_format_ustar(ar);
|
101
|
-
break;
|
102
|
-
default:
|
103
|
-
error_msg = "unknown or unsupported archive format";
|
104
|
-
throw Error(error_msg);
|
105
|
-
}
|
101
|
+
set_format_helper(ar, format);
|
106
102
|
|
107
103
|
if(archive_write_open_filename(ar, filename) != ARCHIVE_OK) {
|
108
104
|
error_msg = archive_error_string(ar);
|
@@ -123,6 +119,7 @@ Entry *Writer::new_entry_helper()
|
|
123
119
|
return new Entry(archive_entry_new());
|
124
120
|
}
|
125
121
|
|
122
|
+
|
126
123
|
void Writer::write_header(Entry *entry)
|
127
124
|
{
|
128
125
|
if(archive_write_header(_ar, entry->_entry) != ARCHIVE_OK) {
|
@@ -131,6 +128,7 @@ void Writer::write_header(Entry *entry)
|
|
131
128
|
}
|
132
129
|
}
|
133
130
|
|
131
|
+
|
134
132
|
void Writer::write_data_helper(const char *string, int length)
|
135
133
|
{
|
136
134
|
if(archive_write_data(_ar, (void*) string, length) == -1) {
|
@@ -139,3 +137,40 @@ void Writer::write_data_helper(const char *string, int length)
|
|
139
137
|
}
|
140
138
|
}
|
141
139
|
|
140
|
+
|
141
|
+
void Writer::set_format_helper(struct archive *ar, int format)
|
142
|
+
{
|
143
|
+
std::string error_msg;
|
144
|
+
|
145
|
+
switch(format) {
|
146
|
+
case Archive::FORMAT_AR_BSD:
|
147
|
+
archive_write_set_format_ar_bsd(ar);
|
148
|
+
break;
|
149
|
+
case Archive::FORMAT_AR_SVR4:
|
150
|
+
archive_write_set_format_ar_svr4(ar);
|
151
|
+
break;
|
152
|
+
case Archive::FORMAT_CPIO:
|
153
|
+
archive_write_set_format_cpio(ar);
|
154
|
+
break;
|
155
|
+
case Archive::FORMAT_CPIO_NEWC:
|
156
|
+
archive_write_set_format_cpio_newc(ar);
|
157
|
+
break;
|
158
|
+
case Archive::FORMAT_MTREE:
|
159
|
+
archive_write_set_format_mtree(ar);
|
160
|
+
break;
|
161
|
+
case Archive::FORMAT_TAR:
|
162
|
+
case Archive::FORMAT_TAR_PAX_RESTRICTED:
|
163
|
+
archive_write_set_format_pax_restricted(ar);
|
164
|
+
break;
|
165
|
+
case Archive::FORMAT_TAR_PAX_INTERCHANGE:
|
166
|
+
archive_write_set_format_pax(ar);
|
167
|
+
break;
|
168
|
+
case Archive::FORMAT_TAR_USTAR:
|
169
|
+
archive_write_set_format_ustar(ar);
|
170
|
+
break;
|
171
|
+
default:
|
172
|
+
error_msg = "unknown or unsupported archive format";
|
173
|
+
throw Error(error_msg);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
@@ -68,10 +68,15 @@ class Writer
|
|
68
68
|
#endif
|
69
69
|
|
70
70
|
#ifdef SWIG
|
71
|
+
%newobject write_open_filename(const char *filename,
|
72
|
+
const char *cmd, int format);
|
71
73
|
%newobject write_open_filename(const char *filename,
|
72
74
|
int compression, int format);
|
73
75
|
#endif
|
74
76
|
|
77
|
+
static Writer *write_open_filename(const char *filename,
|
78
|
+
const char *cmd, int format);
|
79
|
+
|
75
80
|
static Writer *write_open_filename(const char *filename,
|
76
81
|
int compression, int format);
|
77
82
|
|
@@ -94,6 +99,8 @@ class Writer
|
|
94
99
|
Entry *new_entry_helper();
|
95
100
|
|
96
101
|
private:
|
102
|
+
static void set_format_helper(struct archive *ar, int format);
|
103
|
+
|
97
104
|
struct archive *_ar;
|
98
105
|
char *_buf;
|
99
106
|
int _buf_size;
|
data/lib/libarchive_rs.rb
CHANGED
@@ -12,6 +12,9 @@ require 'archive'
|
|
12
12
|
|
13
13
|
module Archive
|
14
14
|
|
15
|
+
class Error < StandardError
|
16
|
+
end
|
17
|
+
|
15
18
|
class Entry
|
16
19
|
alias :file? :is_file
|
17
20
|
alias :directory? :is_directory
|
@@ -100,6 +103,21 @@ module Archive
|
|
100
103
|
end
|
101
104
|
|
102
105
|
def self.write_open_filename(filename, compression, format)
|
106
|
+
if compression.is_a? String
|
107
|
+
if compression.index('/').nil?
|
108
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
109
|
+
if File.executable?(path + '/' + compression)
|
110
|
+
compression = path + '/' + compression
|
111
|
+
break
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
unless File.executable? compression
|
117
|
+
raise Error, "executable '#{compression}' not found."
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
103
121
|
ar = Writer.write_open_filename(filename, compression, format)
|
104
122
|
|
105
123
|
if block_given?
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libarchive-ruby-swig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tobias Koch
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-02-05 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|