rubyzip 0.9.1 → 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +354 -0
- data/Rakefile +15 -104
- data/TODO +0 -1
- data/lib/zip/central_directory.rb +212 -0
- data/lib/zip/compressor.rb +9 -0
- data/lib/zip/constants.rb +115 -0
- data/lib/zip/crypto/decrypted_io.rb +40 -0
- data/lib/zip/crypto/encryption.rb +11 -0
- data/lib/zip/crypto/null_encryption.rb +43 -0
- data/lib/zip/crypto/traditional_encryption.rb +99 -0
- data/lib/zip/decompressor.rb +31 -0
- data/lib/zip/deflater.rb +34 -0
- data/lib/zip/dos_time.rb +53 -0
- data/lib/zip/entry.rb +719 -0
- data/lib/zip/entry_set.rb +88 -0
- data/lib/zip/errors.rb +19 -0
- data/lib/zip/extra_field/generic.rb +44 -0
- data/lib/zip/extra_field/ntfs.rb +94 -0
- data/lib/zip/extra_field/old_unix.rb +46 -0
- data/lib/zip/extra_field/universal_time.rb +77 -0
- data/lib/zip/extra_field/unix.rb +39 -0
- data/lib/zip/extra_field/zip64.rb +70 -0
- data/lib/zip/extra_field/zip64_placeholder.rb +15 -0
- data/lib/zip/extra_field.rb +103 -0
- data/lib/zip/file.rb +468 -0
- data/lib/zip/filesystem.rb +643 -0
- data/lib/zip/inflater.rb +54 -0
- data/lib/zip/input_stream.rb +180 -0
- data/lib/zip/ioextras/abstract_input_stream.rb +122 -0
- data/lib/zip/ioextras/abstract_output_stream.rb +43 -0
- data/lib/zip/ioextras.rb +21 -140
- data/lib/zip/null_compressor.rb +15 -0
- data/lib/zip/null_decompressor.rb +19 -0
- data/lib/zip/null_input_stream.rb +10 -0
- data/lib/zip/output_stream.rb +198 -0
- data/lib/zip/pass_thru_compressor.rb +23 -0
- data/lib/zip/pass_thru_decompressor.rb +31 -0
- data/lib/zip/streamable_directory.rb +15 -0
- data/lib/zip/streamable_stream.rb +52 -0
- data/lib/zip/version.rb +3 -0
- data/lib/zip.rb +72 -0
- data/samples/example.rb +44 -32
- data/samples/example_filesystem.rb +16 -19
- data/samples/example_recursive.rb +54 -0
- data/samples/gtk_ruby_zip.rb +84 -0
- data/samples/qtzip.rb +25 -34
- data/samples/write_simple.rb +10 -13
- data/samples/zipfind.rb +38 -45
- metadata +182 -91
- data/ChangeLog +0 -1504
- data/NEWS +0 -144
- data/README +0 -72
- data/install.rb +0 -22
- data/lib/download_quizzes.rb +0 -119
- data/lib/quiz1/t/solutions/Bill Guindon/solitaire.rb +0 -205
- data/lib/quiz1/t/solutions/Carlos/solitaire.rb +0 -111
- data/lib/quiz1/t/solutions/Dennis Ranke/solitaire.rb +0 -111
- data/lib/quiz1/t/solutions/Florian Gross/solitaire.rb +0 -301
- data/lib/quiz1/t/solutions/Glen M. Lewis/solitaire.rb +0 -268
- data/lib/quiz1/t/solutions/James Edward Gray II/solitaire.rb +0 -132
- data/lib/quiz1/t/solutions/Jamis Buck/bin/main.rb +0 -13
- data/lib/quiz1/t/solutions/Jamis Buck/lib/cipher.rb +0 -230
- data/lib/quiz1/t/solutions/Jamis Buck/lib/cli.rb +0 -24
- data/lib/quiz1/t/solutions/Jamis Buck/test/tc_deck.rb +0 -30
- data/lib/quiz1/t/solutions/Jamis Buck/test/tc_key-stream.rb +0 -19
- data/lib/quiz1/t/solutions/Jamis Buck/test/tc_keying-algorithms.rb +0 -31
- data/lib/quiz1/t/solutions/Jamis Buck/test/tc_solitaire-cipher.rb +0 -66
- data/lib/quiz1/t/solutions/Jamis Buck/test/tc_unkeyed-algorithm.rb +0 -17
- data/lib/quiz1/t/solutions/Jamis Buck/test/tests.rb +0 -2
- data/lib/quiz1/t/solutions/Jim Menard/solitaire_cypher.rb +0 -204
- data/lib/quiz1/t/solutions/Jim Menard/test.rb +0 -47
- data/lib/quiz1/t/solutions/Moses Hohman/cipher.rb +0 -97
- data/lib/quiz1/t/solutions/Moses Hohman/deck.rb +0 -140
- data/lib/quiz1/t/solutions/Moses Hohman/solitaire.rb +0 -14
- data/lib/quiz1/t/solutions/Moses Hohman/test_cipher.rb +0 -68
- data/lib/quiz1/t/solutions/Moses Hohman/test_deck.rb +0 -146
- data/lib/quiz1/t/solutions/Moses Hohman/test_util.rb +0 -38
- data/lib/quiz1/t/solutions/Moses Hohman/testsuite.rb +0 -5
- data/lib/quiz1/t/solutions/Moses Hohman/util.rb +0 -27
- data/lib/quiz1/t/solutions/Niklas Frykholm/solitaire.rb +0 -151
- data/lib/quiz1/t/solutions/Thomas Leitner/solitaire.rb +0 -198
- data/lib/zip/stdrubyext.rb +0 -111
- data/lib/zip/tempfile_bugfixed.rb +0 -195
- data/lib/zip/zip.rb +0 -1847
- data/lib/zip/zipfilesystem.rb +0 -609
- data/lib/zip/ziprequire.rb +0 -90
- data/samples/gtkRubyzip.rb +0 -86
- data/test/alltests.rb +0 -9
- data/test/data/file1.txt +0 -46
- data/test/data/file1.txt.deflatedData +0 -0
- data/test/data/file2.txt +0 -1504
- data/test/data/notzippedruby.rb +0 -7
- data/test/data/rubycode.zip +0 -0
- data/test/data/rubycode2.zip +0 -0
- data/test/data/testDirectory.bin +0 -0
- data/test/data/zipWithDirs.zip +0 -0
- data/test/gentestfiles.rb +0 -157
- data/test/ioextrastest.rb +0 -208
- data/test/stdrubyexttest.rb +0 -52
- data/test/zipfilesystemtest.rb +0 -831
- data/test/ziprequiretest.rb +0 -43
- data/test/ziptest.rb +0 -1599
@@ -1,195 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# tempfile - manipulates temporary files
|
3
|
-
#
|
4
|
-
# $Id: tempfile_bugfixed.rb,v 1.2 2005/02/19 20:30:33 thomas Exp $
|
5
|
-
#
|
6
|
-
|
7
|
-
require 'delegate'
|
8
|
-
require 'tmpdir'
|
9
|
-
|
10
|
-
module BugFix #:nodoc:all
|
11
|
-
|
12
|
-
# A class for managing temporary files. This library is written to be
|
13
|
-
# thread safe.
|
14
|
-
class Tempfile < DelegateClass(File)
|
15
|
-
MAX_TRY = 10
|
16
|
-
@@cleanlist = []
|
17
|
-
|
18
|
-
# Creates a temporary file of mode 0600 in the temporary directory
|
19
|
-
# whose name is basename.pid.n and opens with mode "w+". A Tempfile
|
20
|
-
# object works just like a File object.
|
21
|
-
#
|
22
|
-
# If tmpdir is omitted, the temporary directory is determined by
|
23
|
-
# Dir::tmpdir provided by 'tmpdir.rb'.
|
24
|
-
# When $SAFE > 0 and the given tmpdir is tainted, it uses
|
25
|
-
# /tmp. (Note that ENV values are tainted by default)
|
26
|
-
def initialize(basename, tmpdir=Dir::tmpdir)
|
27
|
-
if $SAFE > 0 and tmpdir.tainted?
|
28
|
-
tmpdir = '/tmp'
|
29
|
-
end
|
30
|
-
|
31
|
-
lock = nil
|
32
|
-
n = failure = 0
|
33
|
-
|
34
|
-
begin
|
35
|
-
Thread.critical = true
|
36
|
-
|
37
|
-
begin
|
38
|
-
tmpname = sprintf('%s/%s%d.%d', tmpdir, basename, $$, n)
|
39
|
-
lock = tmpname + '.lock'
|
40
|
-
n += 1
|
41
|
-
end while @@cleanlist.include?(tmpname) or
|
42
|
-
File.exist?(lock) or File.exist?(tmpname)
|
43
|
-
|
44
|
-
Dir.mkdir(lock)
|
45
|
-
rescue
|
46
|
-
failure += 1
|
47
|
-
retry if failure < MAX_TRY
|
48
|
-
raise "cannot generate tempfile `%s'" % tmpname
|
49
|
-
ensure
|
50
|
-
Thread.critical = false
|
51
|
-
end
|
52
|
-
|
53
|
-
@data = [tmpname]
|
54
|
-
@clean_proc = Tempfile.callback(@data)
|
55
|
-
ObjectSpace.define_finalizer(self, @clean_proc)
|
56
|
-
|
57
|
-
@tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600)
|
58
|
-
@tmpname = tmpname
|
59
|
-
@@cleanlist << @tmpname
|
60
|
-
@data[1] = @tmpfile
|
61
|
-
@data[2] = @@cleanlist
|
62
|
-
|
63
|
-
super(@tmpfile)
|
64
|
-
|
65
|
-
# Now we have all the File/IO methods defined, you must not
|
66
|
-
# carelessly put bare puts(), etc. after this.
|
67
|
-
|
68
|
-
Dir.rmdir(lock)
|
69
|
-
end
|
70
|
-
|
71
|
-
# Opens or reopens the file with mode "r+".
|
72
|
-
def open
|
73
|
-
@tmpfile.close if @tmpfile
|
74
|
-
@tmpfile = File.open(@tmpname, 'r+')
|
75
|
-
@data[1] = @tmpfile
|
76
|
-
__setobj__(@tmpfile)
|
77
|
-
end
|
78
|
-
|
79
|
-
def _close # :nodoc:
|
80
|
-
@tmpfile.close if @tmpfile
|
81
|
-
@data[1] = @tmpfile = nil
|
82
|
-
end
|
83
|
-
protected :_close
|
84
|
-
|
85
|
-
# Closes the file. If the optional flag is true, unlinks the file
|
86
|
-
# after closing.
|
87
|
-
#
|
88
|
-
# If you don't explicitly unlink the temporary file, the removal
|
89
|
-
# will be delayed until the object is finalized.
|
90
|
-
def close(unlink_now=false)
|
91
|
-
if unlink_now
|
92
|
-
close!
|
93
|
-
else
|
94
|
-
_close
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# Closes and unlinks the file.
|
99
|
-
def close!
|
100
|
-
_close
|
101
|
-
@clean_proc.call
|
102
|
-
ObjectSpace.undefine_finalizer(self)
|
103
|
-
end
|
104
|
-
|
105
|
-
# Unlinks the file. On UNIX-like systems, it is often a good idea
|
106
|
-
# to unlink a temporary file immediately after creating and opening
|
107
|
-
# it, because it leaves other programs zero chance to access the
|
108
|
-
# file.
|
109
|
-
def unlink
|
110
|
-
# keep this order for thread safeness
|
111
|
-
File.unlink(@tmpname) if File.exist?(@tmpname)
|
112
|
-
@@cleanlist.delete(@tmpname) if @@cleanlist
|
113
|
-
end
|
114
|
-
alias delete unlink
|
115
|
-
|
116
|
-
if RUBY_VERSION > '1.8.0'
|
117
|
-
def __setobj__(obj)
|
118
|
-
@_dc_obj = obj
|
119
|
-
end
|
120
|
-
else
|
121
|
-
def __setobj__(obj)
|
122
|
-
@obj = obj
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
# Returns the full path name of the temporary file.
|
127
|
-
def path
|
128
|
-
@tmpname
|
129
|
-
end
|
130
|
-
|
131
|
-
# Returns the size of the temporary file. As a side effect, the IO
|
132
|
-
# buffer is flushed before determining the size.
|
133
|
-
def size
|
134
|
-
if @tmpfile
|
135
|
-
@tmpfile.flush
|
136
|
-
@tmpfile.stat.size
|
137
|
-
else
|
138
|
-
0
|
139
|
-
end
|
140
|
-
end
|
141
|
-
alias length size
|
142
|
-
|
143
|
-
class << self
|
144
|
-
def callback(data) # :nodoc:
|
145
|
-
pid = $$
|
146
|
-
lambda{
|
147
|
-
if pid == $$
|
148
|
-
path, tmpfile, cleanlist = *data
|
149
|
-
|
150
|
-
print "removing ", path, "..." if $DEBUG
|
151
|
-
|
152
|
-
tmpfile.close if tmpfile
|
153
|
-
|
154
|
-
# keep this order for thread safeness
|
155
|
-
File.unlink(path) if File.exist?(path)
|
156
|
-
cleanlist.delete(path) if cleanlist
|
157
|
-
|
158
|
-
print "done\n" if $DEBUG
|
159
|
-
end
|
160
|
-
}
|
161
|
-
end
|
162
|
-
|
163
|
-
# If no block is given, this is a synonym for new().
|
164
|
-
#
|
165
|
-
# If a block is given, it will be passed tempfile as an argument,
|
166
|
-
# and the tempfile will automatically be closed when the block
|
167
|
-
# terminates. In this case, open() returns nil.
|
168
|
-
def open(*args)
|
169
|
-
tempfile = new(*args)
|
170
|
-
|
171
|
-
if block_given?
|
172
|
-
begin
|
173
|
-
yield(tempfile)
|
174
|
-
ensure
|
175
|
-
tempfile.close
|
176
|
-
end
|
177
|
-
|
178
|
-
nil
|
179
|
-
else
|
180
|
-
tempfile
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
end # module BugFix
|
187
|
-
if __FILE__ == $0
|
188
|
-
# $DEBUG = true
|
189
|
-
f = Tempfile.new("foo")
|
190
|
-
f.print("foo\n")
|
191
|
-
f.close
|
192
|
-
f.open
|
193
|
-
p f.gets # => "foo\n"
|
194
|
-
f.close!
|
195
|
-
end
|