zipruby1.8 0.3.4-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog ADDED
@@ -0,0 +1,18 @@
1
+ 2010-01-23 winebarrel
2
+
3
+ * fixes bug: [ruby-dev:40120] SEGV on zipruby with irb
4
+
5
+ 2009-06-11 winebarrel
6
+
7
+ * fixes bug: C macro mistake (reported by SHITAMORI Akira)
8
+
9
+ 2009-05-16 winebarrel
10
+
11
+ * improve Zip::Archive#add_io, replace_io, add, replace
12
+
13
+ * fixes bug: Zip::Archive#add_io, <<
14
+
15
+ * add method: Zip::Archive#add_dir
16
+
17
+ * zipruby/README.txt: fixes example code.
18
+
data/LICENSE.libzip ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner
2
+ The authors can be contacted at <libzip@nih.at>
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions
6
+ are met:
7
+ 1. Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in
11
+ the documentation and/or other materials provided with the
12
+ distribution.
13
+ 3. The names of the authors may not be used to endorse or promote
14
+ products derived from this software without specific prior
15
+ written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
18
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
21
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25
+ IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.txt ADDED
@@ -0,0 +1,288 @@
1
+ = Zip/Ruby
2
+
3
+ Copyright (c) 2008-2010 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
4
+
5
+ == Description
6
+
7
+ Ruby bindings for libzip.
8
+
9
+ libzip is a C library for reading, creating, and modifying zip archives.
10
+
11
+ == Project Page
12
+
13
+ http://rubyforge.org/projects/zipruby
14
+
15
+ == Install
16
+
17
+ gem install zipruby
18
+
19
+ == Download
20
+
21
+ https://rubyforge.org/frs/?group_id=6124
22
+
23
+ == Example
24
+ === reading zip archive
25
+
26
+ require 'zipruby'
27
+
28
+ Zip::Archive.open('filename.zip') do |ar|
29
+ n = ar.num_files # number of entries
30
+
31
+ n.times do |i|
32
+ entry_name = ar.get_name(i) # get entry name from archive
33
+
34
+ # open entry
35
+ ar.fopen(entry_name) do |f| # or ar.fopen(i) do |f|
36
+ name = f.name # name of the file
37
+ size = f.size # size of file (uncompressed)
38
+ comp_size = f.comp_size # size of file (compressed)
39
+
40
+ content = f.read # read entry content
41
+ end
42
+ end
43
+
44
+ # Zip::Archive includes Enumerable
45
+ entry_names = ar.map do |f|
46
+ f.name
47
+ end
48
+ end
49
+
50
+ # read huge entry
51
+ BUFSIZE = 8192
52
+
53
+ Zip::Archive.open('filename.zip') do |ar|
54
+ ar.each do |f|
55
+ buf = ''
56
+
57
+ while chunk = f.read(BUFSIZE)
58
+ buf << chunk
59
+ end
60
+ # or
61
+ # f.read do |chunk|
62
+ # buf << chunk
63
+ # end
64
+ end
65
+ end
66
+
67
+ === creating zip archive
68
+
69
+ require 'zipruby'
70
+
71
+ bar_txt = open('bar.txt')
72
+
73
+ Zip::Archive.open('filename.zip', Zip::CREATE) do |ar|
74
+ # if overwrite: ..., Zip::CREATE | Zip::TRUNC) do |ar|
75
+
76
+ ar.add_file('foo.txt') # add file to zip archive
77
+
78
+ # add file to zip archive from File object
79
+ ar << bar_txt # or ar.add_io(bar_txt)
80
+
81
+ # add file to zip archive from buffer
82
+ ar.add_buffer('zoo.txt', 'Hello, world!')
83
+ end
84
+
85
+ bar_txt.rewind
86
+
87
+ # include directory in zip archive
88
+ Zip::Archive.open('filename.zip') do |ar|
89
+ ar.add_dir('dirname')
90
+ ar.add_file('dirname/foo.txt', 'foo.txt')
91
+ # args: <entry name> , <source>
92
+
93
+ ar.add_io('dirname/bar.txt', bar_txt)
94
+ # args: <entry name> , <source>
95
+
96
+ ar.add_buffer('dirname/zoo.txt', 'Hello, world!')
97
+ # args: <entry name> , <source>
98
+ end
99
+
100
+ bar_txt.close # close file after archive closed
101
+
102
+ # add huge file
103
+ source = %w(London Bridge is falling down)
104
+
105
+ Zip::Archive.open('filename.zip') do |ar|
106
+ # lb.txt => 'LondonBridgeisfallingdown'
107
+ ar.add('lb.txt') do # add(<filename>, <mtime>)
108
+ source.shift # end of stream is nil
109
+ end
110
+ end
111
+
112
+ === modifying zip archive
113
+
114
+ require 'zipruby'
115
+
116
+ bar_txt = open('bar.txt')
117
+
118
+ Zip::Archive.open('filename.zip') do |ar|
119
+ # replace file in zip archive
120
+ ar.replace_file(0, 'foo.txt')
121
+
122
+ # replace file in zip archive with File object
123
+ ar.replace_io(1, bar_txt)
124
+
125
+ # if commit changes
126
+ # ar.commit
127
+
128
+ # replace file in zip archive with buffer
129
+ ar.replace_buffer(2, 'Hello, world!')
130
+ # or
131
+ # ar.replace_buffer('entry name', 'Hello, world!')
132
+ # if ignore case distinctions
133
+ # ar.replace_buffer('entry name', 'Hello, world!', Zip::FL_NOCASE)
134
+
135
+ # add or replace file in zip archive
136
+ ar.add_or_replace_file('zoo.txt', 'foo.txt')
137
+ end
138
+
139
+ # append comment
140
+ Zip::Archive.open('filename.zip') do |ar|
141
+ ar.comment = <<-EOS
142
+ jugem jugem gokou no surikere
143
+ kaijari suigyo no
144
+ suigyoumatsu unraimatsu furaimatsu
145
+ EOS
146
+ end
147
+
148
+ bar_txt.close # close file after archive closed
149
+
150
+ # ar1 import ar2 entries
151
+ Zip::Archive.open('ar1.zip') do |ar1|
152
+ Zip::Archive.open('ar2.zip') do |ar2|
153
+ ar1.update(ar2)
154
+ end
155
+ end
156
+
157
+ === encrypt/decrypt zip archive
158
+
159
+ require 'zipruby'
160
+
161
+ # encrypt
162
+ Zip::Archive.encrypt('filename.zip', 'password') # return true if encrypted
163
+ # or
164
+ # Zip::Archive.open('filename.zip') do |ar|
165
+ # ar.encrypt('password')
166
+ # end
167
+
168
+ # decrypt
169
+ Zip::Archive.decrypt('filename.zip', 'password') # return true if decrypted
170
+ # or
171
+ # Zip::Archive.open('filename.zip') do |ar|
172
+ # ar.decrypt('password')
173
+ # end
174
+
175
+ === modifying zip data in memory
176
+
177
+ require 'zipruby'
178
+
179
+ $stdout.binmode
180
+
181
+ buf = ''
182
+
183
+ Zip::Archive.open_buffer(buf, Zip::CREATE) do |ar|
184
+ ar.add_buffer('bar.txt', 'zoo');
185
+ end
186
+
187
+ Zip::Archive.open_buffer(buf) do |ar|
188
+ ar.each do |f|
189
+ puts f.name
190
+ end
191
+ end
192
+
193
+ # read from stream
194
+ zip_data = open('foo.zip') do |f|
195
+ f.binmode
196
+ f.read
197
+ end
198
+
199
+ stream = lambda { return zip_data.slice!(0, 256) }
200
+
201
+ Zip::Archive.open_buffer(stream) do |ar|
202
+ puts ar.num_files
203
+ end
204
+
205
+ # output huge zip data to stdout
206
+ Zip::Archive.open_buffer(zip_data) do |ar|
207
+ ar.read do |chunk|
208
+ print chunk
209
+ end
210
+ end
211
+
212
+ === adding directory recursively
213
+
214
+ require 'zipruby'
215
+
216
+ Zip::Archive.open('filename.zip', Zip::CREATE) do |ar|
217
+ ar.add_dir('dir')
218
+
219
+ Dir.glob('dir/**/*').each do |path|
220
+ if File.directory?(path)
221
+ ar.add_dir(path)
222
+ else
223
+ ar.add_file(path, path) # add_file(<entry name>, <source path>)
224
+ end
225
+ end
226
+ end
227
+
228
+ === extract all files
229
+
230
+ require 'zipruby'
231
+ require 'fileutils'
232
+
233
+ Zip::Archive.open('filename.zip') do |ar|
234
+ ar.each do |zf|
235
+ if zf.directory?
236
+ FileUtils.mkdir_p(zf.name)
237
+ else
238
+ dirname = File.dirname(zf.name)
239
+ FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
240
+
241
+ open(zf.name, 'wb') do |f|
242
+ f << zf.read
243
+ end
244
+ end
245
+ end
246
+ end
247
+
248
+ == License
249
+
250
+ Copyright (c) 2008-2010 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
251
+ All rights reserved.
252
+
253
+ Redistribution and use in source and binary forms, with or without modification,
254
+ are permitted provided that the following conditions are met:
255
+
256
+ * Redistributions of source code must retain the above copyright notice,
257
+ this list of conditions and the following disclaimer.
258
+ * Redistributions in binary form must reproduce the above copyright notice,
259
+ this list of conditions and the following disclaimer in the documentation
260
+ and/or other materials provided with the distribution.
261
+ * The names of its contributors may not be used to endorse or promote products
262
+ derived from this software without specific prior written permission.
263
+
264
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
265
+ ANY EXPRESS OR IMPLIED WARRANTIES,
266
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
267
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
268
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
269
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
270
+ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
271
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
272
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
273
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
274
+ DAMAGE.
275
+
276
+ === libzip
277
+
278
+ Zip/Ruby contains libzip.
279
+
280
+ libzip is a C library for reading, creating, and modifying zip archives.
281
+
282
+ * distribution site:
283
+ * http://www.nih.at/libzip/
284
+ * ftp.nih.at /pub/nih/libzip
285
+
286
+ * authors:
287
+ * Dieter Baron <dillo@giga.or.at>
288
+ * Thomas Klausner <tk@giga.or.at>
Binary file