hotplate 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/hotplate.gemspec +1 -0
  3. data/lib/hotplate/cli/main.rb +1 -7
  4. data/lib/hotplate/version.rb +1 -1
  5. metadata +16 -101
  6. data/lib/hotplate/gems/rubyzip-1.1.7/README.md +0 -271
  7. data/lib/hotplate/gems/rubyzip-1.1.7/Rakefile +0 -19
  8. data/lib/hotplate/gems/rubyzip-1.1.7/TODO +0 -15
  9. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/central_directory.rb +0 -208
  10. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/compressor.rb +0 -10
  11. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/constants.rb +0 -63
  12. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/encryption.rb +0 -11
  13. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/null_encryption.rb +0 -45
  14. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/traditional_encryption.rb +0 -99
  15. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/decompressor.rb +0 -13
  16. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/deflater.rb +0 -32
  17. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/dos_time.rb +0 -49
  18. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/entry.rb +0 -696
  19. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/entry_set.rb +0 -86
  20. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/errors.rb +0 -16
  21. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/generic.rb +0 -43
  22. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/ntfs.rb +0 -92
  23. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/old_unix.rb +0 -45
  24. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/universal_time.rb +0 -47
  25. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/unix.rb +0 -38
  26. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/zip64.rb +0 -67
  27. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/zip64_placeholder.rb +0 -16
  28. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field.rb +0 -101
  29. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/file.rb +0 -436
  30. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb +0 -626
  31. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/inflater.rb +0 -66
  32. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/input_stream.rb +0 -164
  33. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras/abstract_input_stream.rb +0 -115
  34. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras/abstract_output_stream.rb +0 -45
  35. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras.rb +0 -38
  36. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_compressor.rb +0 -15
  37. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_decompressor.rb +0 -27
  38. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_input_stream.rb +0 -10
  39. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/output_stream.rb +0 -190
  40. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/pass_thru_compressor.rb +0 -23
  41. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/pass_thru_decompressor.rb +0 -41
  42. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/streamable_directory.rb +0 -15
  43. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/streamable_stream.rb +0 -56
  44. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/version.rb +0 -3
  45. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip.rb +0 -63
  46. data/lib/hotplate/gems/rubyzip-1.1.7/samples/example.rb +0 -91
  47. data/lib/hotplate/gems/rubyzip-1.1.7/samples/example_filesystem.rb +0 -33
  48. data/lib/hotplate/gems/rubyzip-1.1.7/samples/example_recursive.rb +0 -48
  49. data/lib/hotplate/gems/rubyzip-1.1.7/samples/gtkRubyzip.rb +0 -86
  50. data/lib/hotplate/gems/rubyzip-1.1.7/samples/qtzip.rb +0 -101
  51. data/lib/hotplate/gems/rubyzip-1.1.7/samples/write_simple.rb +0 -13
  52. data/lib/hotplate/gems/rubyzip-1.1.7/samples/zipfind.rb +0 -74
  53. data/lib/hotplate/gems/rubyzip-1.1.7/test/basic_zip_file_test.rb +0 -64
  54. data/lib/hotplate/gems/rubyzip-1.1.7/test/central_directory_entry_test.rb +0 -73
  55. data/lib/hotplate/gems/rubyzip-1.1.7/test/central_directory_test.rb +0 -104
  56. data/lib/hotplate/gems/rubyzip-1.1.7/test/crypto/null_encryption_test.rb +0 -53
  57. data/lib/hotplate/gems/rubyzip-1.1.7/test/crypto/traditional_encryption_test.rb +0 -80
  58. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/WarnInvalidDate.zip +0 -0
  59. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file1.txt +0 -46
  60. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file1.txt.deflatedData +0 -0
  61. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file2.txt +0 -1504
  62. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/foo/bar/baz/foo.txt +0 -0
  63. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/foo.txt +0 -0
  64. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/food.txt +0 -0
  65. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest.zip +0 -0
  66. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/mimetype +0 -1
  67. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/notzippedruby.rb +0 -7
  68. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/ntfs.zip +0 -0
  69. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/rubycode.zip +0 -0
  70. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/rubycode2.zip +0 -0
  71. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/testDirectory.bin +0 -0
  72. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zip64-sample.zip +0 -0
  73. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zipWithDirs.zip +0 -0
  74. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zipWithEncryption.zip +0 -0
  75. data/lib/hotplate/gems/rubyzip-1.1.7/test/deflater_test.rb +0 -67
  76. data/lib/hotplate/gems/rubyzip-1.1.7/test/encryption_test.rb +0 -42
  77. data/lib/hotplate/gems/rubyzip-1.1.7/test/entry_set_test.rb +0 -138
  78. data/lib/hotplate/gems/rubyzip-1.1.7/test/entry_test.rb +0 -165
  79. data/lib/hotplate/gems/rubyzip-1.1.7/test/errors_test.rb +0 -36
  80. data/lib/hotplate/gems/rubyzip-1.1.7/test/extra_field_test.rb +0 -78
  81. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_extract_directory_test.rb +0 -56
  82. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_extract_test.rb +0 -90
  83. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_split_test.rb +0 -60
  84. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_test.rb +0 -559
  85. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/dir_iterator_test.rb +0 -62
  86. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/directory_test.rb +0 -131
  87. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_mutating_test.rb +0 -100
  88. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_nonmutating_test.rb +0 -514
  89. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_stat_test.rb +0 -66
  90. data/lib/hotplate/gems/rubyzip-1.1.7/test/gentestfiles.rb +0 -134
  91. data/lib/hotplate/gems/rubyzip-1.1.7/test/inflater_test.rb +0 -14
  92. data/lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb +0 -170
  93. data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/abstract_input_stream_test.rb +0 -103
  94. data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/abstract_output_stream_test.rb +0 -106
  95. data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/fake_io_test.rb +0 -18
  96. data/lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb +0 -156
  97. data/lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb +0 -129
  98. data/lib/hotplate/gems/rubyzip-1.1.7/test/pass_thru_compressor_test.rb +0 -31
  99. data/lib/hotplate/gems/rubyzip-1.1.7/test/pass_thru_decompressor_test.rb +0 -15
  100. data/lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb +0 -92
  101. data/lib/hotplate/gems/rubyzip-1.1.7/test/test_helper.rb +0 -228
  102. data/lib/hotplate/gems/rubyzip-1.1.7/test/unicode_file_names_and_comments_test.rb +0 -52
  103. data/lib/hotplate/gems/rubyzip-1.1.7/test/zip64_full_test.rb +0 -53
  104. data/lib/hotplate/gems/rubyzip-1.1.7/test/zip64_support_test.rb +0 -15
@@ -1,626 +0,0 @@
1
- require 'zip'
2
-
3
- module Zip
4
-
5
- # The ZipFileSystem API provides an API for accessing entries in
6
- # a zip archive that is similar to ruby's builtin File and Dir
7
- # classes.
8
- #
9
- # Requiring 'zip/filesystem' includes this module in Zip::File
10
- # making the methods in this module available on Zip::File objects.
11
- #
12
- # Using this API the following example creates a new zip file
13
- # <code>my.zip</code> containing a normal entry with the name
14
- # <code>first.txt</code>, a directory entry named <code>mydir</code>
15
- # and finally another normal entry named <code>second.txt</code>
16
- #
17
- # require 'zip/filesystem'
18
- #
19
- # Zip::File.open("my.zip", Zip::File::CREATE) {
20
- # |zipfile|
21
- # zipfile.file.open("first.txt", "w") { |f| f.puts "Hello world" }
22
- # zipfile.dir.mkdir("mydir")
23
- # zipfile.file.open("mydir/second.txt", "w") { |f| f.puts "Hello again" }
24
- # }
25
- #
26
- # Reading is as easy as writing, as the following example shows. The
27
- # example writes the contents of <code>first.txt</code> from zip archive
28
- # <code>my.zip</code> to standard out.
29
- #
30
- # require 'zip/filesystem'
31
- #
32
- # Zip::File.open("my.zip") {
33
- # |zipfile|
34
- # puts zipfile.file.read("first.txt")
35
- # }
36
-
37
- module FileSystem
38
-
39
- def initialize # :nodoc:
40
- mappedZip = ZipFileNameMapper.new(self)
41
- @zipFsDir = ZipFsDir.new(mappedZip)
42
- @zipFsFile = ZipFsFile.new(mappedZip)
43
- @zipFsDir.file = @zipFsFile
44
- @zipFsFile.dir = @zipFsDir
45
- end
46
-
47
- # Returns a ZipFsDir which is much like ruby's builtin Dir (class)
48
- # object, except it works on the Zip::File on which this method is
49
- # invoked
50
- def dir
51
- @zipFsDir
52
- end
53
-
54
- # Returns a ZipFsFile which is much like ruby's builtin File (class)
55
- # object, except it works on the Zip::File on which this method is
56
- # invoked
57
- def file
58
- @zipFsFile
59
- end
60
-
61
- # Instances of this class are normally accessed via the accessor
62
- # Zip::File::file. An instance of ZipFsFile behaves like ruby's
63
- # builtin File (class) object, except it works on Zip::File entries.
64
- #
65
- # The individual methods are not documented due to their
66
- # similarity with the methods in File
67
- class ZipFsFile
68
-
69
- attr_writer :dir
70
- # protected :dir
71
-
72
- class ZipFsStat
73
-
74
- class << self
75
-
76
- def delegate_to_fs_file(*methods)
77
- methods.each do |method|
78
- self.class_eval <<-end_eval, __FILE__, __LINE__ + 1
79
- def #{method} # def file?
80
- @zipFsFile.#{method}(@entryName) # @zipFsFile.file?(@entryName)
81
- end # end
82
- end_eval
83
- end
84
- end
85
-
86
- end
87
-
88
- def initialize(zipFsFile, entryName)
89
- @zipFsFile = zipFsFile
90
- @entryName = entryName
91
- end
92
-
93
- def kind_of?(t)
94
- super || t == ::File::Stat
95
- end
96
-
97
- delegate_to_fs_file :file?, :directory?, :pipe?, :chardev?, :symlink?,
98
- :socket?, :blockdev?, :readable?, :readable_real?, :writable?, :ctime,
99
- :writable_real?, :executable?, :executable_real?, :sticky?, :owned?,
100
- :grpowned?, :setuid?, :setgid?, :zero?, :size, :size?, :mtime, :atime
101
-
102
- def blocks; nil; end
103
-
104
- def get_entry
105
- @zipFsFile.__send__(:get_entry, @entryName)
106
- end
107
- private :get_entry
108
-
109
- def gid
110
- e = get_entry
111
- if e.extra.member? "IUnix"
112
- e.extra["IUnix"].gid || 0
113
- else
114
- 0
115
- end
116
- end
117
-
118
- def uid
119
- e = get_entry
120
- if e.extra.member? "IUnix"
121
- e.extra["IUnix"].uid || 0
122
- else
123
- 0
124
- end
125
- end
126
-
127
- def ino; 0; end
128
-
129
- def dev; 0; end
130
-
131
- def rdev; 0; end
132
-
133
- def rdev_major; 0; end
134
-
135
- def rdev_minor; 0; end
136
-
137
- def ftype
138
- if file?
139
- return "file"
140
- elsif directory?
141
- return "directory"
142
- else
143
- raise StandardError, "Unknown file type"
144
- end
145
- end
146
-
147
- def nlink; 1; end
148
-
149
- def blksize; nil; end
150
-
151
- def mode
152
- e = get_entry
153
- if e.fstype == 3
154
- e.external_file_attributes >> 16
155
- else
156
- 33206 # 33206 is equivalent to -rw-rw-rw-
157
- end
158
- end
159
- end
160
-
161
- def initialize(mappedZip)
162
- @mappedZip = mappedZip
163
- end
164
-
165
- def get_entry(fileName)
166
- if ! exists?(fileName)
167
- raise Errno::ENOENT, "No such file or directory - #{fileName}"
168
- end
169
- @mappedZip.find_entry(fileName)
170
- end
171
- private :get_entry
172
-
173
- def unix_mode_cmp(fileName, mode)
174
- begin
175
- e = get_entry(fileName)
176
- e.fstype == 3 && ((e.external_file_attributes >> 16) & mode ) != 0
177
- rescue Errno::ENOENT
178
- false
179
- end
180
- end
181
- private :unix_mode_cmp
182
-
183
- def exists?(fileName)
184
- expand_path(fileName) == "/" || @mappedZip.find_entry(fileName) != nil
185
- end
186
- alias :exist? :exists?
187
-
188
- # Permissions not implemented, so if the file exists it is accessible
189
- alias owned? exists?
190
- alias grpowned? exists?
191
-
192
- def readable?(fileName)
193
- unix_mode_cmp(fileName, 0444)
194
- end
195
- alias readable_real? readable?
196
-
197
- def writable?(fileName)
198
- unix_mode_cmp(fileName, 0222)
199
- end
200
- alias writable_real? writable?
201
-
202
- def executable?(fileName)
203
- unix_mode_cmp(fileName, 0111)
204
- end
205
- alias executable_real? executable?
206
-
207
- def setuid?(fileName)
208
- unix_mode_cmp(fileName, 04000)
209
- end
210
-
211
- def setgid?(fileName)
212
- unix_mode_cmp(fileName, 02000)
213
- end
214
-
215
- def sticky?(fileName)
216
- unix_mode_cmp(fileName, 01000)
217
- end
218
-
219
- def umask(*args)
220
- ::File.umask(*args)
221
- end
222
-
223
- def truncate(fileName, len)
224
- raise StandardError, "truncate not supported"
225
- end
226
-
227
- def directory?(fileName)
228
- entry = @mappedZip.find_entry(fileName)
229
- expand_path(fileName) == "/" || (entry != nil && entry.directory?)
230
- end
231
-
232
- def open(fileName, openMode = "r", permissionInt = 0644, &block)
233
- openMode.gsub!("b", "") # ignore b option
234
- case openMode
235
- when "r"
236
- @mappedZip.get_input_stream(fileName, &block)
237
- when "w"
238
- @mappedZip.get_output_stream(fileName, permissionInt, &block)
239
- else
240
- raise StandardError, "openmode '#{openMode} not supported" unless openMode == "r"
241
- end
242
- end
243
-
244
- def new(fileName, openMode = "r")
245
- open(fileName, openMode)
246
- end
247
-
248
- def size(fileName)
249
- @mappedZip.get_entry(fileName).size
250
- end
251
-
252
- # Returns nil for not found and nil for directories
253
- def size?(fileName)
254
- entry = @mappedZip.find_entry(fileName)
255
- return (entry == nil || entry.directory?) ? nil : entry.size
256
- end
257
-
258
- def chown(ownerInt, groupInt, *filenames)
259
- filenames.each { |fileName|
260
- e = get_entry(fileName)
261
- unless e.extra.member?("IUnix")
262
- e.extra.create("IUnix")
263
- end
264
- e.extra["IUnix"].uid = ownerInt
265
- e.extra["IUnix"].gid = groupInt
266
- }
267
- filenames.size
268
- end
269
-
270
- def chmod (modeInt, *filenames)
271
- filenames.each { |fileName|
272
- e = get_entry(fileName)
273
- e.fstype = 3 # force convertion filesystem type to unix
274
- e.unix_perms = modeInt
275
- e.external_file_attributes = modeInt << 16
276
- e.dirty = true
277
- }
278
- filenames.size
279
- end
280
-
281
- def zero?(fileName)
282
- sz = size(fileName)
283
- sz == nil || sz == 0
284
- rescue Errno::ENOENT
285
- false
286
- end
287
-
288
- def file?(fileName)
289
- entry = @mappedZip.find_entry(fileName)
290
- entry != nil && entry.file?
291
- end
292
-
293
- def dirname(fileName)
294
- ::File.dirname(fileName)
295
- end
296
-
297
- def basename(fileName)
298
- ::File.basename(fileName)
299
- end
300
-
301
- def split(fileName)
302
- ::File.split(fileName)
303
- end
304
-
305
- def join(*fragments)
306
- ::File.join(*fragments)
307
- end
308
-
309
- def utime(modifiedTime, *fileNames)
310
- fileNames.each { |fileName|
311
- get_entry(fileName).time = modifiedTime
312
- }
313
- end
314
-
315
- def mtime(fileName)
316
- @mappedZip.get_entry(fileName).mtime
317
- end
318
-
319
- def atime(fileName)
320
- e = get_entry(fileName)
321
- if e.extra.member? "UniversalTime"
322
- e.extra["UniversalTime"].atime
323
- elsif e.extra.member? "NTFS"
324
- e.extra["NTFS"].atime
325
- else
326
- nil
327
- end
328
- end
329
-
330
- def ctime(fileName)
331
- e = get_entry(fileName)
332
- if e.extra.member? "UniversalTime"
333
- e.extra["UniversalTime"].ctime
334
- elsif e.extra.member? "NTFS"
335
- e.extra["NTFS"].ctime
336
- else
337
- nil
338
- end
339
- end
340
-
341
- def pipe?(filename)
342
- false
343
- end
344
-
345
- def blockdev?(filename)
346
- false
347
- end
348
-
349
- def chardev?(filename)
350
- false
351
- end
352
-
353
- def symlink?(fileName)
354
- false
355
- end
356
-
357
- def socket?(fileName)
358
- false
359
- end
360
-
361
- def ftype(fileName)
362
- @mappedZip.get_entry(fileName).directory? ? "directory" : "file"
363
- end
364
-
365
- def readlink(fileName)
366
- raise NotImplementedError, "The readlink() function is not implemented"
367
- end
368
-
369
- def symlink(fileName, symlinkName)
370
- raise NotImplementedError, "The symlink() function is not implemented"
371
- end
372
-
373
- def link(fileName, symlinkName)
374
- raise NotImplementedError, "The link() function is not implemented"
375
- end
376
-
377
- def pipe
378
- raise NotImplementedError, "The pipe() function is not implemented"
379
- end
380
-
381
- def stat(fileName)
382
- if ! exists?(fileName)
383
- raise Errno::ENOENT, fileName
384
- end
385
- ZipFsStat.new(self, fileName)
386
- end
387
-
388
- alias lstat stat
389
-
390
- def readlines(fileName)
391
- open(fileName) { |is| is.readlines }
392
- end
393
-
394
- def read(fileName)
395
- @mappedZip.read(fileName)
396
- end
397
-
398
- def popen(*args, &aProc)
399
- ::File.popen(*args, &aProc)
400
- end
401
-
402
- def foreach(fileName, aSep = $/, &aProc)
403
- open(fileName) { |is| is.each_line(aSep, &aProc) }
404
- end
405
-
406
- def delete(*args)
407
- args.each {
408
- |fileName|
409
- if directory?(fileName)
410
- raise Errno::EISDIR, "Is a directory - \"#{fileName}\""
411
- end
412
- @mappedZip.remove(fileName)
413
- }
414
- end
415
-
416
- def rename(fileToRename, newName)
417
- @mappedZip.rename(fileToRename, newName) { true }
418
- end
419
-
420
- alias :unlink :delete
421
-
422
- def expand_path(aPath)
423
- @mappedZip.expand_path(aPath)
424
- end
425
- end
426
-
427
- # Instances of this class are normally accessed via the accessor
428
- # ZipFile::dir. An instance of ZipFsDir behaves like ruby's
429
- # builtin Dir (class) object, except it works on ZipFile entries.
430
- #
431
- # The individual methods are not documented due to their
432
- # similarity with the methods in Dir
433
- class ZipFsDir
434
-
435
- def initialize(mappedZip)
436
- @mappedZip = mappedZip
437
- end
438
-
439
- attr_writer :file
440
-
441
- def new(aDirectoryName)
442
- ZipFsDirIterator.new(entries(aDirectoryName))
443
- end
444
-
445
- def open(aDirectoryName)
446
- dirIt = new(aDirectoryName)
447
- if block_given?
448
- begin
449
- yield(dirIt)
450
- return nil
451
- ensure
452
- dirIt.close
453
- end
454
- end
455
- dirIt
456
- end
457
-
458
- def pwd; @mappedZip.pwd; end
459
- alias getwd pwd
460
-
461
- def chdir(aDirectoryName)
462
- unless @file.stat(aDirectoryName).directory?
463
- raise Errno::EINVAL, "Invalid argument - #{aDirectoryName}"
464
- end
465
- @mappedZip.pwd = @file.expand_path(aDirectoryName)
466
- end
467
-
468
- def entries(aDirectoryName)
469
- entries = []
470
- foreach(aDirectoryName) { |e| entries << e }
471
- entries
472
- end
473
-
474
- def glob(*args,&block)
475
- @mappedZip.glob(*args,&block)
476
- end
477
-
478
- def foreach(aDirectoryName)
479
- unless @file.stat(aDirectoryName).directory?
480
- raise Errno::ENOTDIR, aDirectoryName
481
- end
482
- path = @file.expand_path(aDirectoryName)
483
- path << '/' unless path.end_with?('/')
484
- path = Regexp.escape(path)
485
- subDirEntriesRegex = Regexp.new("^#{path}([^/]+)$")
486
- @mappedZip.each {
487
- |fileName|
488
- match = subDirEntriesRegex.match(fileName)
489
- yield(match[1]) unless match == nil
490
- }
491
- end
492
-
493
- def delete(entryName)
494
- unless @file.stat(entryName).directory?
495
- raise Errno::EINVAL, "Invalid argument - #{entryName}"
496
- end
497
- @mappedZip.remove(entryName)
498
- end
499
- alias rmdir delete
500
- alias unlink delete
501
-
502
- def mkdir(entryName, permissionInt = 0755)
503
- @mappedZip.mkdir(entryName, permissionInt)
504
- end
505
-
506
- def chroot(*args)
507
- raise NotImplementedError, "The chroot() function is not implemented"
508
- end
509
-
510
- end
511
-
512
- class ZipFsDirIterator # :nodoc:all
513
- include Enumerable
514
-
515
- def initialize(arrayOfFileNames)
516
- @fileNames = arrayOfFileNames
517
- @index = 0
518
- end
519
-
520
- def close
521
- @fileNames = nil
522
- end
523
-
524
- def each(&aProc)
525
- raise IOError, "closed directory" if @fileNames == nil
526
- @fileNames.each(&aProc)
527
- end
528
-
529
- def read
530
- raise IOError, "closed directory" if @fileNames == nil
531
- @fileNames[(@index+=1)-1]
532
- end
533
-
534
- def rewind
535
- raise IOError, "closed directory" if @fileNames == nil
536
- @index = 0
537
- end
538
-
539
- def seek(anIntegerPosition)
540
- raise IOError, "closed directory" if @fileNames == nil
541
- @index = anIntegerPosition
542
- end
543
-
544
- def tell
545
- raise IOError, "closed directory" if @fileNames == nil
546
- @index
547
- end
548
- end
549
-
550
- # All access to Zip::File from ZipFsFile and ZipFsDir goes through a
551
- # ZipFileNameMapper, which has one responsibility: ensure
552
- class ZipFileNameMapper # :nodoc:all
553
- include Enumerable
554
-
555
- def initialize(zipFile)
556
- @zipFile = zipFile
557
- @pwd = "/"
558
- end
559
-
560
- attr_accessor :pwd
561
-
562
- def find_entry(fileName)
563
- @zipFile.find_entry(expand_to_entry(fileName))
564
- end
565
-
566
- def get_entry(fileName)
567
- @zipFile.get_entry(expand_to_entry(fileName))
568
- end
569
-
570
- def get_input_stream(fileName, &aProc)
571
- @zipFile.get_input_stream(expand_to_entry(fileName), &aProc)
572
- end
573
-
574
- def get_output_stream(fileName, permissionInt = nil, &aProc)
575
- @zipFile.get_output_stream(expand_to_entry(fileName), permissionInt, &aProc)
576
- end
577
-
578
- def read(fileName)
579
- @zipFile.read(expand_to_entry(fileName))
580
- end
581
-
582
- def remove(fileName)
583
- @zipFile.remove(expand_to_entry(fileName))
584
- end
585
-
586
- def rename(fileName, newName, &continueOnExistsProc)
587
- @zipFile.rename(expand_to_entry(fileName), expand_to_entry(newName),
588
- &continueOnExistsProc)
589
- end
590
-
591
- def mkdir(fileName, permissionInt = 0755)
592
- @zipFile.mkdir(expand_to_entry(fileName), permissionInt)
593
- end
594
-
595
- # Turns entries into strings and adds leading /
596
- # and removes trailing slash on directories
597
- def each
598
- @zipFile.each {
599
- |e|
600
- yield("/"+e.to_s.chomp("/"))
601
- }
602
- end
603
-
604
- def expand_path(aPath)
605
- expanded = aPath.start_with?("/") ? aPath : ::File.join(@pwd, aPath)
606
- expanded.gsub!(/\/\.(\/|$)/, "")
607
- expanded.gsub!(/[^\/]+\/\.\.(\/|$)/, "")
608
- expanded.empty? ? "/" : expanded
609
- end
610
-
611
- private
612
-
613
- def expand_to_entry(aPath)
614
- expand_path(aPath)[1..-1]
615
- end
616
- end
617
- end
618
-
619
- class File
620
- include FileSystem
621
- end
622
- end
623
-
624
- # Copyright (C) 2002, 2003 Thomas Sondergaard
625
- # rubyzip is free software; you can redistribute it and/or
626
- # modify it under the terms of the ruby license.
@@ -1,66 +0,0 @@
1
- module Zip
2
- class Inflater < Decompressor #:nodoc:all
3
- def initialize(input_stream, decrypter = NullDecrypter.new)
4
- super(input_stream)
5
- @zlib_inflater = ::Zlib::Inflate.new(-Zlib::MAX_WBITS)
6
- @output_buffer = ''
7
- @has_returned_empty_string = false
8
- @decrypter = decrypter
9
- end
10
-
11
- def sysread(number_of_bytes = nil, buf = '')
12
- readEverything = number_of_bytes.nil?
13
- while readEverything || @output_buffer.bytesize < number_of_bytes
14
- break if internal_input_finished?
15
- @output_buffer << internal_produce_input(buf)
16
- end
17
- return value_when_finished if @output_buffer.bytesize == 0 && input_finished?
18
- end_index = number_of_bytes.nil? ? @output_buffer.bytesize : number_of_bytes
19
- @output_buffer.slice!(0...end_index)
20
- end
21
-
22
- def produce_input
23
- if (@output_buffer.empty?)
24
- internal_produce_input
25
- else
26
- @output_buffer.slice!(0...(@output_buffer.length))
27
- end
28
- end
29
-
30
- # to be used with produce_input, not read (as read may still have more data cached)
31
- # is data cached anywhere other than @outputBuffer? the comment above may be wrong
32
- def input_finished?
33
- @output_buffer.empty? && internal_input_finished?
34
- end
35
-
36
- alias :eof :input_finished?
37
- alias :eof? :input_finished?
38
-
39
- private
40
-
41
- def internal_produce_input(buf = '')
42
- retried = 0
43
- begin
44
- @zlib_inflater.inflate(@decrypter.decrypt(@input_stream.read(Decompressor::CHUNK_SIZE, buf)))
45
- rescue Zlib::BufError
46
- raise if retried >= 5 # how many times should we retry?
47
- retried += 1
48
- retry
49
- end
50
- end
51
-
52
- def internal_input_finished?
53
- @zlib_inflater.finished?
54
- end
55
-
56
- def value_when_finished # mimic behaviour of ruby File object.
57
- return if @has_returned_empty_string
58
- @has_returned_empty_string = true
59
- ''
60
- end
61
- end
62
- end
63
-
64
- # Copyright (C) 2002, 2003 Thomas Sondergaard
65
- # rubyzip is free software; you can redistribute it and/or
66
- # modify it under the terms of the ruby license.