hotplate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +1 -0
  4. data/bin/toast +2 -0
  5. data/hotplate.gemspec +30 -0
  6. data/lib/hotplate/cli/build.rb +51 -0
  7. data/lib/hotplate/cli/init.rb +64 -0
  8. data/lib/hotplate/cli/main.rb +39 -0
  9. data/lib/hotplate/gems/rubyzip-1.1.7/README.md +271 -0
  10. data/lib/hotplate/gems/rubyzip-1.1.7/Rakefile +19 -0
  11. data/lib/hotplate/gems/rubyzip-1.1.7/TODO +15 -0
  12. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/central_directory.rb +208 -0
  13. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/compressor.rb +10 -0
  14. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/constants.rb +63 -0
  15. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/encryption.rb +11 -0
  16. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/null_encryption.rb +45 -0
  17. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/traditional_encryption.rb +99 -0
  18. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/decompressor.rb +13 -0
  19. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/deflater.rb +32 -0
  20. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/dos_time.rb +49 -0
  21. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/entry.rb +696 -0
  22. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/entry_set.rb +86 -0
  23. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/errors.rb +16 -0
  24. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/generic.rb +43 -0
  25. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/ntfs.rb +92 -0
  26. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/old_unix.rb +45 -0
  27. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/universal_time.rb +47 -0
  28. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/unix.rb +38 -0
  29. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/zip64.rb +67 -0
  30. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/zip64_placeholder.rb +16 -0
  31. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field.rb +101 -0
  32. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/file.rb +436 -0
  33. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb +626 -0
  34. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/inflater.rb +66 -0
  35. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/input_stream.rb +164 -0
  36. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras/abstract_input_stream.rb +115 -0
  37. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras/abstract_output_stream.rb +45 -0
  38. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras.rb +38 -0
  39. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_compressor.rb +15 -0
  40. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_decompressor.rb +27 -0
  41. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_input_stream.rb +10 -0
  42. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/output_stream.rb +190 -0
  43. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/pass_thru_compressor.rb +23 -0
  44. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/pass_thru_decompressor.rb +41 -0
  45. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/streamable_directory.rb +15 -0
  46. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/streamable_stream.rb +56 -0
  47. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/version.rb +3 -0
  48. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip.rb +63 -0
  49. data/lib/hotplate/gems/rubyzip-1.1.7/samples/example.rb +91 -0
  50. data/lib/hotplate/gems/rubyzip-1.1.7/samples/example_filesystem.rb +33 -0
  51. data/lib/hotplate/gems/rubyzip-1.1.7/samples/example_recursive.rb +48 -0
  52. data/lib/hotplate/gems/rubyzip-1.1.7/samples/gtkRubyzip.rb +86 -0
  53. data/lib/hotplate/gems/rubyzip-1.1.7/samples/qtzip.rb +101 -0
  54. data/lib/hotplate/gems/rubyzip-1.1.7/samples/write_simple.rb +13 -0
  55. data/lib/hotplate/gems/rubyzip-1.1.7/samples/zipfind.rb +74 -0
  56. data/lib/hotplate/gems/rubyzip-1.1.7/test/basic_zip_file_test.rb +64 -0
  57. data/lib/hotplate/gems/rubyzip-1.1.7/test/central_directory_entry_test.rb +73 -0
  58. data/lib/hotplate/gems/rubyzip-1.1.7/test/central_directory_test.rb +104 -0
  59. data/lib/hotplate/gems/rubyzip-1.1.7/test/crypto/null_encryption_test.rb +53 -0
  60. data/lib/hotplate/gems/rubyzip-1.1.7/test/crypto/traditional_encryption_test.rb +80 -0
  61. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/WarnInvalidDate.zip +0 -0
  62. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file1.txt +46 -0
  63. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file1.txt.deflatedData +0 -0
  64. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file2.txt +1504 -0
  65. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/foo/bar/baz/foo.txt +0 -0
  66. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/foo.txt +0 -0
  67. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/food.txt +0 -0
  68. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest.zip +0 -0
  69. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/mimetype +1 -0
  70. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/notzippedruby.rb +7 -0
  71. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/ntfs.zip +0 -0
  72. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/rubycode.zip +0 -0
  73. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/rubycode2.zip +0 -0
  74. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/testDirectory.bin +0 -0
  75. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zip64-sample.zip +0 -0
  76. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zipWithDirs.zip +0 -0
  77. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zipWithEncryption.zip +0 -0
  78. data/lib/hotplate/gems/rubyzip-1.1.7/test/deflater_test.rb +67 -0
  79. data/lib/hotplate/gems/rubyzip-1.1.7/test/encryption_test.rb +42 -0
  80. data/lib/hotplate/gems/rubyzip-1.1.7/test/entry_set_test.rb +138 -0
  81. data/lib/hotplate/gems/rubyzip-1.1.7/test/entry_test.rb +165 -0
  82. data/lib/hotplate/gems/rubyzip-1.1.7/test/errors_test.rb +36 -0
  83. data/lib/hotplate/gems/rubyzip-1.1.7/test/extra_field_test.rb +78 -0
  84. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_extract_directory_test.rb +56 -0
  85. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_extract_test.rb +90 -0
  86. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_split_test.rb +60 -0
  87. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_test.rb +559 -0
  88. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/dir_iterator_test.rb +62 -0
  89. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/directory_test.rb +131 -0
  90. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_mutating_test.rb +100 -0
  91. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_nonmutating_test.rb +514 -0
  92. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_stat_test.rb +66 -0
  93. data/lib/hotplate/gems/rubyzip-1.1.7/test/gentestfiles.rb +134 -0
  94. data/lib/hotplate/gems/rubyzip-1.1.7/test/inflater_test.rb +14 -0
  95. data/lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb +170 -0
  96. data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/abstract_input_stream_test.rb +103 -0
  97. data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/abstract_output_stream_test.rb +106 -0
  98. data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/fake_io_test.rb +18 -0
  99. data/lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb +156 -0
  100. data/lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb +129 -0
  101. data/lib/hotplate/gems/rubyzip-1.1.7/test/pass_thru_compressor_test.rb +31 -0
  102. data/lib/hotplate/gems/rubyzip-1.1.7/test/pass_thru_decompressor_test.rb +15 -0
  103. data/lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb +92 -0
  104. data/lib/hotplate/gems/rubyzip-1.1.7/test/test_helper.rb +228 -0
  105. data/lib/hotplate/gems/rubyzip-1.1.7/test/unicode_file_names_and_comments_test.rb +52 -0
  106. data/lib/hotplate/gems/rubyzip-1.1.7/test/zip64_full_test.rb +53 -0
  107. data/lib/hotplate/gems/rubyzip-1.1.7/test/zip64_support_test.rb +15 -0
  108. data/lib/hotplate/java/build.gradle +38 -0
  109. data/lib/hotplate/java/gradle/wrapper/gradle-wrapper.jar +0 -0
  110. data/lib/hotplate/java/gradle/wrapper/gradle-wrapper.properties +6 -0
  111. data/lib/hotplate/java/gradlew +164 -0
  112. data/lib/hotplate/java/gradlew.bat +90 -0
  113. data/lib/hotplate/java/template.java +25 -0
  114. data/lib/hotplate/version.rb +3 -0
  115. data/lib/hotplate.rb +2 -0
  116. metadata +186 -0
@@ -0,0 +1,626 @@
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.
@@ -0,0 +1,66 @@
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.