libarchive-ruby-swig 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -47,13 +47,18 @@ void Reader::close()
47
47
  }
48
48
 
49
49
 
50
- Reader *Reader::read_open_filename(const char *filename)
50
+ Reader *Reader::read_open_filename(const char *filename, const char *cmd)
51
51
  {
52
52
  struct archive *ar = archive_read_new();
53
53
 
54
54
  try {
55
- if(archive_read_support_compression_all(ar) != ARCHIVE_OK)
56
- throw 0;
55
+ if(cmd) {
56
+ if(archive_read_support_compression_program(ar, cmd) != ARCHIVE_OK)
57
+ throw 0;
58
+ } else {
59
+ if(archive_read_support_compression_all(ar) != ARCHIVE_OK)
60
+ throw 0;
61
+ }
57
62
 
58
63
  if(archive_read_support_format_all(ar) != ARCHIVE_OK)
59
64
  throw 0;
@@ -71,31 +76,37 @@ Reader *Reader::read_open_filename(const char *filename)
71
76
  }
72
77
 
73
78
 
74
- Reader *Reader::read_open_memory(const char *string, int length)
79
+ Reader *Reader::read_open_memory(const char *string, int length,
80
+ const char *cmd)
75
81
  {
76
82
  struct archive *ar = archive_read_new();
77
- char *archive_content = (char*) malloc(length);
78
- memcpy((void*) archive_content, (void*) string, length);
83
+ char *content = (char*) malloc(length);
84
+ memcpy((void*) content, (void*) string, length);
79
85
 
80
86
  try {
81
- if(archive_read_support_compression_all(ar) != ARCHIVE_OK)
82
- throw 0;
87
+ if(cmd) {
88
+ if(archive_read_support_compression_program(ar, cmd) != ARCHIVE_OK)
89
+ throw 0;
90
+ } else {
91
+ if(archive_read_support_compression_all(ar) != ARCHIVE_OK)
92
+ throw 0;
93
+ }
83
94
 
84
95
  if(archive_read_support_format_all(ar) != ARCHIVE_OK)
85
96
  throw 0;
86
97
 
87
- if(archive_read_open_memory(ar, (void*) archive_content, length) != ARCHIVE_OK)
98
+ if(archive_read_open_memory(ar, (void*) content, length) != ARCHIVE_OK)
88
99
  throw 0;
89
100
 
90
101
  } catch(...) {
91
102
  std::string error_msg = archive_error_string(ar);
92
103
  archive_read_finish(ar);
93
- free(archive_content);
104
+ free(content);
94
105
  throw Error(error_msg);
95
106
  }
96
107
 
97
108
  Reader *reader_obj = new Reader(ar);
98
- reader_obj->_archive_content = archive_content;
109
+ reader_obj->_archive_content = content;
99
110
  return reader_obj;
100
111
  }
101
112
 
@@ -39,13 +39,15 @@ class Reader
39
39
  #endif
40
40
 
41
41
  #ifdef SWIG
42
- %newobject read_open_filename(const char *filename);
43
- %newobject read_open_memory(const char *string, int length);
42
+ %newobject read_open_filename(const char *filename, const char *cmd);
43
+ %newobject read_open_memory(const char *string, int length, const char *cmd);
44
44
  %newobject next_header();
45
45
  #endif
46
46
 
47
- static Reader *read_open_filename(const char *filename);
48
- static Reader *read_open_memory(const char *string, int length);
47
+ static Reader *read_open_filename(const char *filename,
48
+ const char *cmd = 0);
49
+ static Reader *read_open_memory(const char *string, int length,
50
+ const char *cmd = 0);
49
51
 
50
52
  Entry *next_header();
51
53
  VALUE read_data_helper(int len);
data/lib/libarchive_rs.rb CHANGED
@@ -91,8 +91,12 @@ module Archive
91
91
  private_class_method :new
92
92
  end
93
93
 
94
- def self.read_open_filename(filename)
95
- ar = Reader.read_open_filename(filename)
94
+ def self.read_open_filename(filename, cmd = nil)
95
+ unless cmd.nil?
96
+ cmd = locate_cmd(cmd)
97
+ end
98
+
99
+ ar = Reader.read_open_filename(filename, cmd)
96
100
 
97
101
  if block_given?
98
102
  yield ar
@@ -102,8 +106,12 @@ module Archive
102
106
  end
103
107
  end
104
108
 
105
- def self.read_open_memory(string)
106
- ar = Reader.read_open_memory(string)
109
+ def self.read_open_memory(string, cmd = nil)
110
+ unless cmd.nil?
111
+ cmd = locate_cmd(cmd)
112
+ end
113
+
114
+ ar = Reader.read_open_memory(string, cmd)
107
115
 
108
116
  if block_given?
109
117
  yield ar
@@ -115,18 +123,7 @@ module Archive
115
123
 
116
124
  def self.write_open_filename(filename, compression, format)
117
125
  if compression.is_a? String
118
- if compression.index('/').nil?
119
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
120
- if File.executable?(path + '/' + compression)
121
- compression = path + '/' + compression
122
- break
123
- end
124
- end
125
- end
126
-
127
- unless File.executable? compression
128
- raise Error, "executable '#{compression}' not found."
129
- end
126
+ compresion = locate_cmd(compression)
130
127
  end
131
128
 
132
129
  ar = Writer.write_open_filename(filename, compression, format)
@@ -139,5 +136,28 @@ module Archive
139
136
  end
140
137
  end
141
138
 
139
+ private
140
+
141
+ def self.locate_cmd(cmd)
142
+ unless cmd.is_a? String
143
+ raise Error, "exepected String but found #{cmd.class}"
144
+ end
145
+
146
+ if cmd.index('/').nil?
147
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
148
+ if File.executable?(path + '/' + cmd)
149
+ cmd = path + '/' + cmd
150
+ break
151
+ end
152
+ end
153
+ end
154
+
155
+ unless File.executable? cmd
156
+ raise Error, "executable '#{cmd}' not found"
157
+ end
158
+
159
+ return cmd
160
+ end
161
+
142
162
  end
143
163
 
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: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
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-02-05 00:00:00 +02:00
18
+ date: 2011-02-06 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21