mezza-rubyzip 0.9.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/NEWS ADDED
@@ -0,0 +1,162 @@
1
+ = Version 0.9.4
2
+
3
+ Changed ZipOutputStream.put_next_entry signature (API CHANGE!). Now
4
+ allows comment, extra field and compression method to be specified.
5
+
6
+ = Version 0.9.3
7
+
8
+ Fixed: Added ZipEntry::name_encoding which retrieves the character
9
+ encoding of the name and comment of the entry. Also added convenience
10
+ methods ZipEntry::name_in(enc) and ZipEntry::comment_in(enc) for
11
+ getting zip entry names and comments in a specified character
12
+ encoding.
13
+
14
+ = Version 0.9.2
15
+
16
+ Fixed: Renaming an entry failed if the entry's new name was a
17
+ different length than its old name. (Diego Barros)
18
+
19
+ = Version 0.9.1
20
+
21
+ Added symlink support and support for unix file permissions. Reduced
22
+ memory usage during decompression.
23
+
24
+ New methods ZipFile::[follow_symlinks, restore_times, restore_permissions, restore_ownership].
25
+ New methods ZipEntry::unix_perms, ZipInputStream::eof?.
26
+ Added documentation and test for new ZipFile::extract.
27
+ Added some of the API suggestions from sf.net #1281314.
28
+ Applied patch for sf.net bug #1446926.
29
+ Applied patch for sf.net bug #1459902.
30
+ Rework ZipEntry and delegate classes.
31
+
32
+ = Version 0.5.12
33
+
34
+ Fixed problem with writing binary content to a ZipFile in MS Windows.
35
+
36
+ = Version 0.5.11
37
+
38
+ Fixed name clash file method copy_stream from fileutils.rb. Fixed
39
+ problem with references to constant CHUNK_SIZE.
40
+ ZipInputStream/AbstractInputStream read is now buffered like ruby IO's
41
+ read method, which means that read and gets etc can be mixed. The
42
+ unbuffered read method has been renamed to sysread.
43
+
44
+ = Version 0.5.10
45
+
46
+ Fixed method name resolution problem with FileUtils::copy_stream and
47
+ IOExtras::copy_stream.
48
+
49
+ = Version 0.5.9
50
+
51
+ Fixed serious memory consumption issue
52
+
53
+ = Version 0.5.8
54
+
55
+ Fixed install script.
56
+
57
+ = Version 0.5.7
58
+
59
+ install.rb no longer assumes it is being run from the toplevel source
60
+ dir. Directory structure changed to reflect common ruby library
61
+ project structure. Migrated from RubyUnit to Test::Unit format. Now
62
+ uses Rake to build source packages and gems and run unit tests.
63
+
64
+ = Version 0.5.6
65
+
66
+ Fix for FreeBSD 4.9 which returns Errno::EFBIG instead of
67
+ Errno::EINVAL for some invalid seeks. Fixed 'version needed to
68
+ extract'-field incorrect in local headers.
69
+
70
+ = Version 0.5.5
71
+
72
+ Fix for a problem with writing zip files that concerns only ruby 1.8.1.
73
+
74
+ = Version 0.5.4
75
+
76
+ Significantly reduced memory footprint when modifying zip files.
77
+
78
+ = Version 0.5.3
79
+
80
+ Added optimization to avoid decompressing and recompressing individual
81
+ entries when modifying a zip archive.
82
+
83
+ = Version 0.5.2
84
+
85
+ Fixed ZipFile corruption bug in ZipFile class. Added basic unix
86
+ extra-field support.
87
+
88
+ = Version 0.5.1
89
+
90
+ Fixed ZipFile.get_output_stream bug.
91
+
92
+ = Version 0.5.0
93
+
94
+ List of changes:
95
+ * Ruby 1.8.0 and ruby-zlib 0.6.0 compatibility
96
+ * Changed method names from camelCase to rubys underscore style.
97
+ * Installs to zip/ subdir instead of directly to site_ruby
98
+ * Added ZipFile.directory and ZipFile.file - each method return an
99
+ object that can be used like Dir and File only for the contents of the
100
+ zip file.
101
+ * Added sample application zipfind which works like Find.find, only
102
+ Zip::ZipFind.find traverses into zip archives too.
103
+
104
+ Bug fixes:
105
+ * AbstractInputStream.each_line with non-default separator
106
+
107
+
108
+ = Version 0.5.0a
109
+
110
+ Source reorganized. Added ziprequire, which can be used to load ruby
111
+ modules from a zip file, in a fashion similar to jar files in
112
+ Java. Added gtkRubyzip, another sample application. Implemented
113
+ ZipInputStream.lineno and ZipInputStream.rewind
114
+
115
+ Bug fixes:
116
+
117
+ * Read and write date and time information correctly for zip entries.
118
+ * Fixed read() using separate buffer, causing mix of gets/readline/read to
119
+ cause problems.
120
+
121
+ = Version 0.4.2
122
+
123
+ Performance optimizations. Test suite runs in half the time.
124
+
125
+ = Version 0.4.1
126
+
127
+ Windows compatibility fixes.
128
+
129
+ = Version 0.4.0
130
+
131
+ Zip::ZipFile is now mutable and provides a more convenient way of
132
+ modifying zip archives than Zip::ZipOutputStream. Operations for
133
+ adding, extracting, renaming, replacing and removing entries to zip
134
+ archives are now available.
135
+
136
+ Runs without warnings with -w switch.
137
+
138
+ Install script install.rb added.
139
+
140
+
141
+ = Version 0.3.1
142
+
143
+ Rudimentary support for writing zip archives.
144
+
145
+
146
+ = Version 0.2.2
147
+
148
+ Fixed and extended unit test suite. Updated to work with ruby/zlib
149
+ 0.5. It doesn't work with earlier versions of ruby/zlib.
150
+
151
+
152
+ = Version 0.2.0
153
+
154
+ Class ZipFile added. Where ZipInputStream is used to read the
155
+ individual entries in a zip file, ZipFile reads the central directory
156
+ in the zip archive, so you can get to any entry in the zip archive
157
+ without having to skipping through all the preceeding entries.
158
+
159
+
160
+ = Version 0.1.0
161
+
162
+ First working version of ZipInputStream.
data/README ADDED
@@ -0,0 +1,68 @@
1
+ = rubyzip
2
+
3
+ rubyzip is a ruby library for reading and writing zip files.
4
+
5
+ = Install
6
+
7
+ gem install rubyzip
8
+
9
+
10
+ To run the unit tests you need to have test::unit installed
11
+
12
+ rake test
13
+
14
+
15
+ = Documentation
16
+
17
+ There is more than one way to access or create a zip archive with
18
+ rubyzip. The basic API is modeled after the classes in
19
+ java.util.zip from the Java SDK. This means there are classes such
20
+ as Zip::ZipInputStream, Zip::ZipOutputStream and
21
+ Zip::ZipFile. Zip::ZipInputStream provides a basic interface for
22
+ iterating through the entries in a zip archive and reading from the
23
+ entries in the same way as from a regular File or IO
24
+ object. ZipOutputStream is the corresponding basic output
25
+ facility. Zip::ZipFile provides a mean for accessing the archives
26
+ central directory and provides means for accessing any entry without
27
+ having to iterate through the archive. Unlike Java's
28
+ java.util.zip.ZipFile rubyzip's Zip::ZipFile is mutable, which means
29
+ it can be used to change zip files as well.
30
+
31
+ Another way to access a zip archive with rubyzip is to use rubyzip's
32
+ Zip::ZipFileSystem API. Using this API files can be read from and
33
+ written to the archive in much the same manner as ruby's builtin
34
+ classes allows files to be read from and written to the file system.
35
+
36
+ rubyzip also features the
37
+ zip/ziprequire.rb[link:files/lib/zip/ziprequire_rb.html] module which
38
+ allows ruby to load ruby modules from zip archives.
39
+
40
+ For details about the specific behaviour of classes and methods refer
41
+ to the test suite. Finally you can generate the rdoc documentation or
42
+ visit http://rubyzip.sourceforge.net.
43
+
44
+ = License
45
+
46
+ rubyzip is distributed under the same license as ruby. See
47
+ http://www.ruby-lang.org/en/LICENSE.txt
48
+
49
+
50
+ = Website and Project Home
51
+
52
+ http://github.com/aussiegeek/dotfiles
53
+
54
+ http://rdoc.info/github/aussiegeek/rubyzip/master/frames
55
+
56
+ == Download (tarballs and gems)
57
+
58
+
59
+
60
+ = Authors
61
+
62
+ Alan Harper ( alan at aussiegeek.net)
63
+
64
+ Thomas Sondergaard (thomas at sondergaard.cc)
65
+
66
+ Technorama Ltd. (oss-ruby-zip at technorama.net)
67
+
68
+ extra-field support contributed by Tatsuki Sugiura (sugi at nemui.org)
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rake/testtask'
3
+
4
+ task :default => [:test]
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << File.join(File.dirname(__FILE__), 'lib')
8
+ test.libs << File.join(File.dirname(__FILE__), 'test')
9
+ test.pattern = File.join(File.dirname(__FILE__), 'test/**/*.rb')
10
+ test.verbose = true
11
+ Dir.chdir File.join(File.dirname(__FILE__), 'test')
12
+ end
13
+
data/TODO ADDED
@@ -0,0 +1,16 @@
1
+
2
+ * ZipInputStream: Support zip-files with trailing data descriptors
3
+ * Adjust rdoc stylesheet to advertise inherited methods if possible
4
+ * Suggestion: Add ZipFile/ZipInputStream example that demonstrates extracting all entries.
5
+ * Suggestion: ZipFile#extract destination should default to "."
6
+ * Suggestion: ZipEntry should have extract(), get_input_stream() methods etc
7
+ * SUggestion: ZipInputStream/ZipOutputStream should accept an IO object in addition to a filename.
8
+ * (is buffering used anywhere with write?)
9
+ * Inflater.sysread should pass the buffer to produce_input.
10
+ * Implement ZipFsDir.glob
11
+ * ZipFile.checkIntegrity method
12
+ * non-MSDOS permission attributes
13
+ ** See mail from Ned Konz to ruby-talk subj. "Re: SV: [ANN] Archive 0.2"
14
+ * Packager version, required unpacker version in zip headers
15
+ ** See mail from Ned Konz to ruby-talk subj. "Re: SV: [ANN] Archive 0.2"
16
+ * implement storing attributes and ownership information
@@ -0,0 +1,23 @@
1
+ module Zip
2
+
3
+ VERSION = '0.9.4'
4
+
5
+ RUBY_MINOR_VERSION = RUBY_VERSION.split(".")[1].to_i
6
+
7
+ RUNNING_ON_WINDOWS = Config::CONFIG['host_os'] =~ /^win|mswin/i
8
+
9
+ # Ruby 1.7.x compatibility
10
+ # In ruby 1.6.x and 1.8.0 reading from an empty stream returns
11
+ # an empty string the first time and then nil.
12
+ # not so in 1.7.x
13
+ EMPTY_FILE_RETURNS_EMPTY_STRING_FIRST = RUBY_MINOR_VERSION != 7
14
+
15
+ class Compressor #:nodoc:all
16
+ def finish
17
+ end
18
+ end
19
+ end
20
+
21
+ # Copyright (C) 2002, 2003 Thomas Sondergaard
22
+ # rubyzip is free software; you can redistribute it and/or
23
+ # modify it under the terms of the ruby license.
@@ -0,0 +1,13 @@
1
+ module Zip
2
+ class Decompressor #:nodoc:all
3
+ CHUNK_SIZE=32768
4
+ def initialize(inputStream)
5
+ super()
6
+ @inputStream=inputStream
7
+ end
8
+ end
9
+ end
10
+
11
+ # Copyright (C) 2002, 2003 Thomas Sondergaard
12
+ # rubyzip is free software; you can redistribute it and/or
13
+ # modify it under the terms of the ruby license.
@@ -0,0 +1,30 @@
1
+ module Zip
2
+ class Deflater < Compressor #:nodoc:all
3
+ def initialize(outputStream, level = Zlib::DEFAULT_COMPRESSION)
4
+ super()
5
+ @outputStream = outputStream
6
+ @zlibDeflater = Zlib::Deflate.new(level, -Zlib::MAX_WBITS)
7
+ @size = 0
8
+ @crc = Zlib::crc32
9
+ end
10
+
11
+ def << (data)
12
+ val = data.to_s
13
+ @crc = Zlib::crc32(val, @crc)
14
+ @size += val.size
15
+ @outputStream << @zlibDeflater.deflate(data)
16
+ end
17
+
18
+ def finish
19
+ until @zlibDeflater.finished?
20
+ @outputStream << @zlibDeflater.finish
21
+ end
22
+ end
23
+
24
+ attr_reader :size, :crc
25
+ end
26
+ end
27
+
28
+ # Copyright (C) 2002, 2003 Thomas Sondergaard
29
+ # rubyzip is free software; you can redistribute it and/or
30
+ # modify it under the terms of the ruby license.
@@ -0,0 +1,65 @@
1
+ module Zip
2
+ class Inflater < Decompressor #:nodoc:all
3
+ def initialize(inputStream)
4
+ super
5
+ @zlibInflater = Zlib::Inflate.new(-Zlib::MAX_WBITS)
6
+ @outputBuffer=""
7
+ @hasReturnedEmptyString = ! EMPTY_FILE_RETURNS_EMPTY_STRING_FIRST
8
+ end
9
+
10
+ def sysread(numberOfBytes = nil, buf = nil)
11
+ readEverything = (numberOfBytes == nil)
12
+ while (readEverything || @outputBuffer.length < numberOfBytes)
13
+ break if internal_input_finished?
14
+ @outputBuffer << internal_produce_input(buf)
15
+ end
16
+ return value_when_finished if @outputBuffer.length==0 && input_finished?
17
+ endIndex= numberOfBytes==nil ? @outputBuffer.length : numberOfBytes
18
+ return @outputBuffer.slice!(0...endIndex)
19
+ end
20
+
21
+ def produce_input
22
+ if (@outputBuffer.empty?)
23
+ return internal_produce_input
24
+ else
25
+ return @outputBuffer.slice!(0...(@outputBuffer.length))
26
+ end
27
+ end
28
+
29
+ # to be used with produce_input, not read (as read may still have more data cached)
30
+ # is data cached anywhere other than @outputBuffer? the comment above may be wrong
31
+ def input_finished?
32
+ @outputBuffer.empty? && internal_input_finished?
33
+ end
34
+ alias :eof :input_finished?
35
+ alias :eof? :input_finished?
36
+
37
+ private
38
+
39
+ def internal_produce_input(buf = nil)
40
+ retried = 0
41
+ begin
42
+ @zlibInflater.inflate(@inputStream.read(Decompressor::CHUNK_SIZE, buf))
43
+ rescue Zlib::BufError
44
+ raise if (retried >= 5) # how many times should we retry?
45
+ retried += 1
46
+ retry
47
+ end
48
+ end
49
+
50
+ def internal_input_finished?
51
+ @zlibInflater.finished?
52
+ end
53
+
54
+ # TODO: Specialize to handle different behaviour in ruby > 1.7.0 ?
55
+ def value_when_finished # mimic behaviour of ruby File object.
56
+ return nil if @hasReturnedEmptyString
57
+ @hasReturnedEmptyString=true
58
+ return ""
59
+ end
60
+ end
61
+ end
62
+
63
+ # Copyright (C) 2002, 2003 Thomas Sondergaard
64
+ # rubyzip is free software; you can redistribute it and/or
65
+ # modify it under the terms of the ruby license.
@@ -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.join($,) << $\.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.