FreedomCoder-rubyzip 0.9.2 → 0.9.3

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/NEWS ADDED
@@ -0,0 +1,148 @@
1
+ = Version 0.9.2
2
+
3
+ Fixed: Renaming an entry failed if the entry's new name was a different length than its old name. (Diego Barros)
4
+
5
+ = Version 0.9.1
6
+
7
+ Added symlink support and support for unix file permissions. Reduced
8
+ memory usage during decompression.
9
+
10
+ New methods ZipFile::[follow_symlinks, restore_times, restore_permissions, restore_ownership].
11
+ New methods ZipEntry::unix_perms, ZipInputStream::eof?.
12
+ Added documentation and test for new ZipFile::extract.
13
+ Added some of the API suggestions from sf.net #1281314.
14
+ Applied patch for sf.net bug #1446926.
15
+ Applied patch for sf.net bug #1459902.
16
+ Rework ZipEntry and delegate classes.
17
+
18
+ = Version 0.5.12
19
+
20
+ Fixed problem with writing binary content to a ZipFile in MS Windows.
21
+
22
+ = Version 0.5.11
23
+
24
+ Fixed name clash file method copy_stream from fileutils.rb. Fixed
25
+ problem with references to constant CHUNK_SIZE.
26
+ ZipInputStream/AbstractInputStream read is now buffered like ruby IO's
27
+ read method, which means that read and gets etc can be mixed. The
28
+ unbuffered read method has been renamed to sysread.
29
+
30
+ = Version 0.5.10
31
+
32
+ Fixed method name resolution problem with FileUtils::copy_stream and
33
+ IOExtras::copy_stream.
34
+
35
+ = Version 0.5.9
36
+
37
+ Fixed serious memory consumption issue
38
+
39
+ = Version 0.5.8
40
+
41
+ Fixed install script.
42
+
43
+ = Version 0.5.7
44
+
45
+ install.rb no longer assumes it is being run from the toplevel source
46
+ dir. Directory structure changed to reflect common ruby library
47
+ project structure. Migrated from RubyUnit to Test::Unit format. Now
48
+ uses Rake to build source packages and gems and run unit tests.
49
+
50
+ = Version 0.5.6
51
+
52
+ Fix for FreeBSD 4.9 which returns Errno::EFBIG instead of
53
+ Errno::EINVAL for some invalid seeks. Fixed 'version needed to
54
+ extract'-field incorrect in local headers.
55
+
56
+ = Version 0.5.5
57
+
58
+ Fix for a problem with writing zip files that concerns only ruby 1.8.1.
59
+
60
+ = Version 0.5.4
61
+
62
+ Significantly reduced memory footprint when modifying zip files.
63
+
64
+ = Version 0.5.3
65
+
66
+ Added optimization to avoid decompressing and recompressing individual
67
+ entries when modifying a zip archive.
68
+
69
+ = Version 0.5.2
70
+
71
+ Fixed ZipFile corruption bug in ZipFile class. Added basic unix
72
+ extra-field support.
73
+
74
+ = Version 0.5.1
75
+
76
+ Fixed ZipFile.get_output_stream bug.
77
+
78
+ = Version 0.5.0
79
+
80
+ List of changes:
81
+ * Ruby 1.8.0 and ruby-zlib 0.6.0 compatibility
82
+ * Changed method names from camelCase to rubys underscore style.
83
+ * Installs to zip/ subdir instead of directly to site_ruby
84
+ * Added ZipFile.directory and ZipFile.file - each method return an
85
+ object that can be used like Dir and File only for the contents of the
86
+ zip file.
87
+ * Added sample application zipfind which works like Find.find, only
88
+ Zip::ZipFind.find traverses into zip archives too.
89
+
90
+ Bug fixes:
91
+ * AbstractInputStream.each_line with non-default separator
92
+
93
+
94
+ = Version 0.5.0a
95
+
96
+ Source reorganized. Added ziprequire, which can be used to load ruby
97
+ modules from a zip file, in a fashion similar to jar files in
98
+ Java. Added gtkRubyzip, another sample application. Implemented
99
+ ZipInputStream.lineno and ZipInputStream.rewind
100
+
101
+ Bug fixes:
102
+
103
+ * Read and write date and time information correctly for zip entries.
104
+ * Fixed read() using separate buffer, causing mix of gets/readline/read to
105
+ cause problems.
106
+
107
+ = Version 0.4.2
108
+
109
+ Performance optimizations. Test suite runs in half the time.
110
+
111
+ = Version 0.4.1
112
+
113
+ Windows compatibility fixes.
114
+
115
+ = Version 0.4.0
116
+
117
+ Zip::ZipFile is now mutable and provides a more convenient way of
118
+ modifying zip archives than Zip::ZipOutputStream. Operations for
119
+ adding, extracting, renaming, replacing and removing entries to zip
120
+ archives are now available.
121
+
122
+ Runs without warnings with -w switch.
123
+
124
+ Install script install.rb added.
125
+
126
+
127
+ = Version 0.3.1
128
+
129
+ Rudimentary support for writing zip archives.
130
+
131
+
132
+ = Version 0.2.2
133
+
134
+ Fixed and extended unit test suite. Updated to work with ruby/zlib
135
+ 0.5. It doesn't work with earlier versions of ruby/zlib.
136
+
137
+
138
+ = Version 0.2.0
139
+
140
+ Class ZipFile added. Where ZipInputStream is used to read the
141
+ individual entries in a zip file, ZipFile reads the central directory
142
+ in the zip archive, so you can get to any entry in the zip archive
143
+ without having to skipping through all the preceeding entries.
144
+
145
+
146
+ = Version 0.1.0
147
+
148
+ First working version of ZipInputStream.
@@ -0,0 +1,165 @@
1
+ module IOExtras #:nodoc:
2
+
3
+ CHUNK_SIZE = 131072
4
+
5
+ RANGE_ALL = 0..-1
6
+
7
+ def self.copy_stream(ostream, istream)
8
+ s = ''
9
+ ostream.write(istream.read(CHUNK_SIZE, s)) until istream.eof?
10
+ end
11
+
12
+ def self.copy_stream_n(ostream, istream, nbytes)
13
+ s = ''
14
+ toread = nbytes
15
+ while (toread > 0 && ! istream.eof?)
16
+ tr = toread > CHUNK_SIZE ? CHUNK_SIZE : toread
17
+ ostream.write(istream.read(tr, s))
18
+ toread -= tr
19
+ end
20
+ end
21
+
22
+
23
+ # Implements kind_of? in order to pretend to be an IO object
24
+ module FakeIO
25
+ def kind_of?(object)
26
+ object == IO || super
27
+ end
28
+ end
29
+
30
+ # Implements many of the convenience methods of IO
31
+ # such as gets, getc, readline and readlines
32
+ # depends on: input_finished?, produce_input and read
33
+ module AbstractInputStream
34
+ include Enumerable
35
+ include FakeIO
36
+
37
+ def initialize
38
+ super
39
+ @lineno = 0
40
+ @outputBuffer = ""
41
+ end
42
+
43
+ attr_accessor :lineno
44
+
45
+ def read(numberOfBytes = nil, buf = nil)
46
+ tbuf = nil
47
+
48
+ if @outputBuffer.length > 0
49
+ if numberOfBytes <= @outputBuffer.length
50
+ tbuf = @outputBuffer.slice!(0, numberOfBytes)
51
+ else
52
+ numberOfBytes -= @outputBuffer.length if (numberOfBytes)
53
+ rbuf = sysread(numberOfBytes, buf)
54
+ tbuf = @outputBuffer
55
+ tbuf << rbuf if (rbuf)
56
+ @outputBuffer = ""
57
+ end
58
+ else
59
+ tbuf = sysread(numberOfBytes, buf)
60
+ end
61
+
62
+ return nil unless (tbuf)
63
+
64
+ if buf
65
+ buf.replace(tbuf)
66
+ else
67
+ buf = tbuf
68
+ end
69
+
70
+ buf
71
+ end
72
+
73
+ def readlines(aSepString = $/)
74
+ retVal = []
75
+ each_line(aSepString) { |line| retVal << line }
76
+ return retVal
77
+ end
78
+
79
+ def gets(aSepString=$/)
80
+ @lineno = @lineno.next
81
+ return read if aSepString == nil
82
+ aSepString="#{$/}#{$/}" if aSepString == ""
83
+
84
+ bufferIndex=0
85
+ while ((matchIndex = @outputBuffer.index(aSepString, bufferIndex)) == nil)
86
+ bufferIndex=@outputBuffer.length
87
+ if input_finished?
88
+ return @outputBuffer.empty? ? nil : flush
89
+ end
90
+ @outputBuffer << produce_input
91
+ end
92
+ sepIndex=matchIndex + aSepString.length
93
+ return @outputBuffer.slice!(0...sepIndex)
94
+ end
95
+
96
+ def flush
97
+ retVal=@outputBuffer
98
+ @outputBuffer=""
99
+ return retVal
100
+ end
101
+
102
+ def readline(aSepString = $/)
103
+ retVal = gets(aSepString)
104
+ raise EOFError if retVal == nil
105
+ return retVal
106
+ end
107
+
108
+ def each_line(aSepString = $/)
109
+ while true
110
+ yield readline(aSepString)
111
+ end
112
+ rescue EOFError
113
+ end
114
+
115
+ alias_method :each, :each_line
116
+ end
117
+
118
+
119
+ # Implements many of the output convenience methods of IO.
120
+ # relies on <<
121
+ module AbstractOutputStream
122
+ include FakeIO
123
+
124
+ def write(data)
125
+ self << data
126
+ data.to_s.length
127
+ end
128
+
129
+
130
+ def print(*params)
131
+ self << params.to_s << $\.to_s
132
+ end
133
+
134
+ def printf(aFormatString, *params)
135
+ self << sprintf(aFormatString, *params)
136
+ end
137
+
138
+ def putc(anObject)
139
+ self << case anObject
140
+ when Fixnum then anObject.chr
141
+ when String then anObject
142
+ else raise TypeError, "putc: Only Fixnum and String supported"
143
+ end
144
+ anObject
145
+ end
146
+
147
+ def puts(*params)
148
+ params << "\n" if params.empty?
149
+ params.flatten.each {
150
+ |element|
151
+ val = element.to_s
152
+ self << val
153
+ self << "\n" unless val[-1,1] == "\n"
154
+ }
155
+ end
156
+
157
+ end
158
+
159
+ end # IOExtras namespace module
160
+
161
+
162
+
163
+ # Copyright (C) 2002-2004 Thomas Sondergaard
164
+ # rubyzip is free software; you can redistribute it and/or
165
+ # modify it under the terms of the ruby license.
@@ -0,0 +1,111 @@
1
+ unless Enumerable.method_defined?(:inject)
2
+ module Enumerable #:nodoc:all
3
+ def inject(n = 0)
4
+ each { |value| n = yield(n, value) }
5
+ n
6
+ end
7
+ end
8
+ end
9
+
10
+ module Enumerable #:nodoc:all
11
+ # returns a new array of all the return values not equal to nil
12
+ # This implementation could be faster
13
+ def select_map(&aProc)
14
+ map(&aProc).reject { |e| e.nil? }
15
+ end
16
+ end
17
+
18
+ unless Object.method_defined?(:object_id)
19
+ class Object #:nodoc:all
20
+ # Using object_id which is the new thing, so we need
21
+ # to make that work in versions prior to 1.8.0
22
+ alias object_id id
23
+ end
24
+ end
25
+
26
+ unless File.respond_to?(:read)
27
+ class File # :nodoc:all
28
+ # singleton method read does not exist in 1.6.x
29
+ def self.read(fileName)
30
+ open(fileName) { |f| f.read }
31
+ end
32
+ end
33
+ end
34
+
35
+ class String #:nodoc:all
36
+ def starts_with(aString)
37
+ rindex(aString, 0) == 0
38
+ end
39
+
40
+ def ends_with(aString)
41
+ index(aString, -aString.size)
42
+ end
43
+
44
+ def ensure_end(aString)
45
+ ends_with(aString) ? self : self + aString
46
+ end
47
+
48
+ def lchop
49
+ slice(1, length)
50
+ end
51
+ end
52
+
53
+ class Time #:nodoc:all
54
+
55
+ #MS-DOS File Date and Time format as used in Interrupt 21H Function 57H:
56
+ #
57
+ # Register CX, the Time:
58
+ # Bits 0-4 2 second increments (0-29)
59
+ # Bits 5-10 minutes (0-59)
60
+ # bits 11-15 hours (0-24)
61
+ #
62
+ # Register DX, the Date:
63
+ # Bits 0-4 day (1-31)
64
+ # bits 5-8 month (1-12)
65
+ # bits 9-15 year (four digit year minus 1980)
66
+
67
+
68
+ def to_binary_dos_time
69
+ (sec/2) +
70
+ (min << 5) +
71
+ (hour << 11)
72
+ end
73
+
74
+ def to_binary_dos_date
75
+ (day) +
76
+ (month << 5) +
77
+ ((year - 1980) << 9)
78
+ end
79
+
80
+ # Dos time is only stored with two seconds accuracy
81
+ def dos_equals(other)
82
+ to_i/2 == other.to_i/2
83
+ end
84
+
85
+ def self.parse_binary_dos_format(binaryDosDate, binaryDosTime)
86
+ second = 2 * ( 0b11111 & binaryDosTime)
87
+ minute = ( 0b11111100000 & binaryDosTime) >> 5
88
+ hour = (0b1111100000000000 & binaryDosTime) >> 11
89
+ day = ( 0b11111 & binaryDosDate)
90
+ month = ( 0b111100000 & binaryDosDate) >> 5
91
+ year = ((0b1111111000000000 & binaryDosDate) >> 9) + 1980
92
+ begin
93
+ return Time.local(year, month, day, hour, minute, second)
94
+ end
95
+ end
96
+ end
97
+
98
+ class Module #:nodoc:all
99
+ def forward_message(forwarder, *messagesToForward)
100
+ methodDefs = messagesToForward.map {
101
+ |msg|
102
+ "def #{msg}; #{forwarder}(:#{msg}); end"
103
+ }
104
+ module_eval(methodDefs.join("\n"))
105
+ end
106
+ end
107
+
108
+
109
+ # Copyright (C) 2002, 2003 Thomas Sondergaard
110
+ # rubyzip is free software; you can redistribute it and/or
111
+ # modify it under the terms of the ruby license.
@@ -0,0 +1,195 @@
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