rubyzip2 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.txt +1081 -0
- data/NEWS.txt +144 -0
- data/README +72 -0
- data/Rakefile +62 -0
- data/TODO.txt +16 -0
- data/lib/zip.rb +1 -0
- data/lib/zip/ioextras.rb +155 -0
- data/lib/zip/stdrubyext.rb +111 -0
- data/lib/zip/tempfile_bugfixed.rb +195 -0
- data/lib/zip/version.rb +3 -0
- data/lib/zip/zip.rb +1846 -0
- data/lib/zip/zipfilesystem.rb +609 -0
- data/lib/zip/ziprequire.rb +90 -0
- data/samples/example.rb +69 -0
- data/samples/example_filesystem.rb +34 -0
- data/samples/gtk_zip.rb +86 -0
- data/samples/write_simple.rb +13 -0
- data/samples/zipfind.rb +74 -0
- data/test/alltests.rb +9 -0
- data/test/data/file1.txt +46 -0
- data/test/data/file1.txt.deflatedData +0 -0
- data/test/data/file2.txt +1504 -0
- data/test/data/notzippedruby.rb +7 -0
- 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 +157 -0
- data/test/ioextrastest.rb +208 -0
- data/test/stdrubyexttest.rb +52 -0
- data/test/zipfilesystemtest.rb +831 -0
- data/test/ziprequiretest.rb +43 -0
- data/test/ziptest.rb +1599 -0
- metadata +96 -0
data/NEWS.txt
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
= Version 0.9.1
|
2
|
+
|
3
|
+
Added symlink support and support for unix file permissions. Reduced
|
4
|
+
memory usage during decompression.
|
5
|
+
|
6
|
+
New methods ZipFile::[follow_symlinks, restore_times, restore_permissions, restore_ownership].
|
7
|
+
New methods ZipEntry::unix_perms, ZipInputStream::eof?.
|
8
|
+
Added documentation and test for new ZipFile::extract.
|
9
|
+
Added some of the API suggestions from sf.net #1281314.
|
10
|
+
Applied patch for sf.net bug #1446926.
|
11
|
+
Applied patch for sf.net bug #1459902.
|
12
|
+
Rework ZipEntry and delegate classes.
|
13
|
+
|
14
|
+
= Version 0.5.12
|
15
|
+
|
16
|
+
Fixed problem with writing binary content to a ZipFile in MS Windows.
|
17
|
+
|
18
|
+
= Version 0.5.11
|
19
|
+
|
20
|
+
Fixed name clash file method copy_stream from fileutils.rb. Fixed
|
21
|
+
problem with references to constant CHUNK_SIZE.
|
22
|
+
ZipInputStream/AbstractInputStream read is now buffered like ruby IO's
|
23
|
+
read method, which means that read and gets etc can be mixed. The
|
24
|
+
unbuffered read method has been renamed to sysread.
|
25
|
+
|
26
|
+
= Version 0.5.10
|
27
|
+
|
28
|
+
Fixed method name resolution problem with FileUtils::copy_stream and
|
29
|
+
IOExtras::copy_stream.
|
30
|
+
|
31
|
+
= Version 0.5.9
|
32
|
+
|
33
|
+
Fixed serious memory consumption issue
|
34
|
+
|
35
|
+
= Version 0.5.8
|
36
|
+
|
37
|
+
Fixed install script.
|
38
|
+
|
39
|
+
= Version 0.5.7
|
40
|
+
|
41
|
+
install.rb no longer assumes it is being run from the toplevel source
|
42
|
+
dir. Directory structure changed to reflect common ruby library
|
43
|
+
project structure. Migrated from RubyUnit to Test::Unit format. Now
|
44
|
+
uses Rake to build source packages and gems and run unit tests.
|
45
|
+
|
46
|
+
= Version 0.5.6
|
47
|
+
|
48
|
+
Fix for FreeBSD 4.9 which returns Errno::EFBIG instead of
|
49
|
+
Errno::EINVAL for some invalid seeks. Fixed 'version needed to
|
50
|
+
extract'-field incorrect in local headers.
|
51
|
+
|
52
|
+
= Version 0.5.5
|
53
|
+
|
54
|
+
Fix for a problem with writing zip files that concerns only ruby 1.8.1.
|
55
|
+
|
56
|
+
= Version 0.5.4
|
57
|
+
|
58
|
+
Significantly reduced memory footprint when modifying zip files.
|
59
|
+
|
60
|
+
= Version 0.5.3
|
61
|
+
|
62
|
+
Added optimization to avoid decompressing and recompressing individual
|
63
|
+
entries when modifying a zip archive.
|
64
|
+
|
65
|
+
= Version 0.5.2
|
66
|
+
|
67
|
+
Fixed ZipFile corruption bug in ZipFile class. Added basic unix
|
68
|
+
extra-field support.
|
69
|
+
|
70
|
+
= Version 0.5.1
|
71
|
+
|
72
|
+
Fixed ZipFile.get_output_stream bug.
|
73
|
+
|
74
|
+
= Version 0.5.0
|
75
|
+
|
76
|
+
List of changes:
|
77
|
+
* Ruby 1.8.0 and ruby-zlib 0.6.0 compatibility
|
78
|
+
* Changed method names from camelCase to rubys underscore style.
|
79
|
+
* Installs to zip/ subdir instead of directly to site_ruby
|
80
|
+
* Added ZipFile.directory and ZipFile.file - each method return an
|
81
|
+
object that can be used like Dir and File only for the contents of the
|
82
|
+
zip file.
|
83
|
+
* Added sample application zipfind which works like Find.find, only
|
84
|
+
Zip::ZipFind.find traverses into zip archives too.
|
85
|
+
|
86
|
+
Bug fixes:
|
87
|
+
* AbstractInputStream.each_line with non-default separator
|
88
|
+
|
89
|
+
|
90
|
+
= Version 0.5.0a
|
91
|
+
|
92
|
+
Source reorganized. Added ziprequire, which can be used to load ruby
|
93
|
+
modules from a zip file, in a fashion similar to jar files in
|
94
|
+
Java. Added gtkRubyzip, another sample application. Implemented
|
95
|
+
ZipInputStream.lineno and ZipInputStream.rewind
|
96
|
+
|
97
|
+
Bug fixes:
|
98
|
+
|
99
|
+
* Read and write date and time information correctly for zip entries.
|
100
|
+
* Fixed read() using separate buffer, causing mix of gets/readline/read to
|
101
|
+
cause problems.
|
102
|
+
|
103
|
+
= Version 0.4.2
|
104
|
+
|
105
|
+
Performance optimizations. Test suite runs in half the time.
|
106
|
+
|
107
|
+
= Version 0.4.1
|
108
|
+
|
109
|
+
Windows compatibility fixes.
|
110
|
+
|
111
|
+
= Version 0.4.0
|
112
|
+
|
113
|
+
Zip::ZipFile is now mutable and provides a more convenient way of
|
114
|
+
modifying zip archives than Zip::ZipOutputStream. Operations for
|
115
|
+
adding, extracting, renaming, replacing and removing entries to zip
|
116
|
+
archives are now available.
|
117
|
+
|
118
|
+
Runs without warnings with -w switch.
|
119
|
+
|
120
|
+
Install script install.rb added.
|
121
|
+
|
122
|
+
|
123
|
+
= Version 0.3.1
|
124
|
+
|
125
|
+
Rudimentary support for writing zip archives.
|
126
|
+
|
127
|
+
|
128
|
+
= Version 0.2.2
|
129
|
+
|
130
|
+
Fixed and extended unit test suite. Updated to work with ruby/zlib
|
131
|
+
0.5. It doesn't work with earlier versions of ruby/zlib.
|
132
|
+
|
133
|
+
|
134
|
+
= Version 0.2.0
|
135
|
+
|
136
|
+
Class ZipFile added. Where ZipInputStream is used to read the
|
137
|
+
individual entries in a zip file, ZipFile reads the central directory
|
138
|
+
in the zip archive, so you can get to any entry in the zip archive
|
139
|
+
without having to skipping through all the preceeding entries.
|
140
|
+
|
141
|
+
|
142
|
+
= Version 0.1.0
|
143
|
+
|
144
|
+
First working version of ZipInputStream.
|
data/README
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
= rubyzip
|
2
|
+
|
3
|
+
rubyzip is a ruby library for reading and writing zip files.
|
4
|
+
|
5
|
+
= Install
|
6
|
+
|
7
|
+
If you have rubygems you can install rubyzip directly from the gem
|
8
|
+
repository
|
9
|
+
|
10
|
+
gem install rubyzip
|
11
|
+
|
12
|
+
Otherwise obtain the source (see below) and run
|
13
|
+
|
14
|
+
ruby install.rb
|
15
|
+
|
16
|
+
To run the unit tests you need to have test::unit installed
|
17
|
+
|
18
|
+
rake test
|
19
|
+
|
20
|
+
|
21
|
+
= Documentation
|
22
|
+
|
23
|
+
There is more than one way to access or create a zip archive with
|
24
|
+
rubyzip. The basic API is modeled after the classes in
|
25
|
+
java.util.zip from the Java SDK. This means there are classes such
|
26
|
+
as Zip::ZipInputStream, Zip::ZipOutputStream and
|
27
|
+
Zip::ZipFile. Zip::ZipInputStream provides a basic interface for
|
28
|
+
iterating through the entries in a zip archive and reading from the
|
29
|
+
entries in the same way as from a regular File or IO
|
30
|
+
object. ZipOutputStream is the corresponding basic output
|
31
|
+
facility. Zip::ZipFile provides a mean for accessing the archives
|
32
|
+
central directory and provides means for accessing any entry without
|
33
|
+
having to iterate through the archive. Unlike Java's
|
34
|
+
java.util.zip.ZipFile rubyzip's Zip::ZipFile is mutable, which means
|
35
|
+
it can be used to change zip files as well.
|
36
|
+
|
37
|
+
Another way to access a zip archive with rubyzip is to use rubyzip's
|
38
|
+
Zip::ZipFileSystem API. Using this API files can be read from and
|
39
|
+
written to the archive in much the same manner as ruby's builtin
|
40
|
+
classes allows files to be read from and written to the file system.
|
41
|
+
|
42
|
+
rubyzip also features the
|
43
|
+
zip/ziprequire.rb[link:files/lib/zip/ziprequire_rb.html] module which
|
44
|
+
allows ruby to load ruby modules from zip archives.
|
45
|
+
|
46
|
+
For details about the specific behaviour of classes and methods refer
|
47
|
+
to the test suite. Finally you can generate the rdoc documentation or
|
48
|
+
visit http://rubyzip.sourceforge.net.
|
49
|
+
|
50
|
+
= License
|
51
|
+
|
52
|
+
rubyzip is distributed under the same license as ruby. See
|
53
|
+
http://www.ruby-lang.org/en/LICENSE.txt
|
54
|
+
|
55
|
+
|
56
|
+
= Website and Project Home
|
57
|
+
|
58
|
+
http://rubyzip.sourceforge.net
|
59
|
+
|
60
|
+
http://sourceforge.net/projects/rubyzip
|
61
|
+
|
62
|
+
== Download (tarballs and gems)
|
63
|
+
|
64
|
+
http://sourceforge.net/project/showfiles.php?group_id=43107&package_id=35377
|
65
|
+
|
66
|
+
= Authors
|
67
|
+
|
68
|
+
Thomas Sondergaard (thomas at sondergaard.cc)
|
69
|
+
|
70
|
+
Technorama Ltd. (oss-ruby-zip at technorama.net)
|
71
|
+
|
72
|
+
extra-field support contributed by Tatsuki Sugiura (sugi at nemui.org)
|
data/Rakefile
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Rakefile for RubyGems -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
require './lib/zip/version.rb'
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'jeweler'
|
10
|
+
Jeweler::Tasks.new do |gem|
|
11
|
+
gem.name = 'rubyzip2'
|
12
|
+
gem.version = Zip::VERSION
|
13
|
+
gem.summary = 'rubyzip2 is a Ruby library for reading and writing Zip files'
|
14
|
+
gem.description = 'rubyzip2 is a Ruby library for reading and writing Zip files. Unlike the official rubyzip, rubyzip2 is compatible with Ruby 1.9.1.'
|
15
|
+
gem.email = 'postmodern.mod3@gmail.com'
|
16
|
+
gem.homepage = 'http://github.com/postmodern/rubyzip2'
|
17
|
+
gem.authors = ['Postmodern', 'Thomas Sondergaard']
|
18
|
+
gem.files = FileList[
|
19
|
+
'README.txt',
|
20
|
+
'NEWS.txt',
|
21
|
+
'TODO.txt',
|
22
|
+
'ChangeLog.txt',
|
23
|
+
'Rakefile',
|
24
|
+
'lib/zip.rb',
|
25
|
+
'lib/zip/ioextras.rb',
|
26
|
+
'lib/zip/stdrubyext.rb',
|
27
|
+
'lib/zip/tempfile_bugfixed.rb',
|
28
|
+
'lib/zip/zip.rb',
|
29
|
+
'lib/zip/zipfilesystem.rb',
|
30
|
+
'lib/zip/ziprequire.rb',
|
31
|
+
'lib/zip/version.rb',
|
32
|
+
'samples/example.rb',
|
33
|
+
'samples/example_filesystem.rb',
|
34
|
+
'samples/gtk_zip.rb',
|
35
|
+
'samples/qt_zip.rb',
|
36
|
+
'samples/write_simple.rb',
|
37
|
+
'samples/zipfind.rb',
|
38
|
+
'test/alltests.rb',
|
39
|
+
'test/data/file1.txt',
|
40
|
+
'test/data/file1.txt.deflatedData',
|
41
|
+
'test/data/file2.txt',
|
42
|
+
'test/data/notzippedruby.rb',
|
43
|
+
'test/data/rubycode.zip',
|
44
|
+
'test/data/rubycode2.zip',
|
45
|
+
'test/data/testDirectory.bin',
|
46
|
+
'test/data/zipWithDirs.zip',
|
47
|
+
]
|
48
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
49
|
+
end
|
50
|
+
rescue LoadError
|
51
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
52
|
+
end
|
53
|
+
|
54
|
+
require 'rake/testtask'
|
55
|
+
|
56
|
+
Rake::TestTask.new(:test) do |test|
|
57
|
+
test.libs << 'lib' << 'test'
|
58
|
+
test.pattern = 'test/**/test_*.rb'
|
59
|
+
test.verbose = true
|
60
|
+
end
|
61
|
+
|
62
|
+
task :test => :check_dependencies
|
data/TODO.txt
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
|
data/lib/zip.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'zip/zip'
|
data/lib/zip/ioextras.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
module IOExtras #:nodoc:
|
2
|
+
|
3
|
+
CHUNK_SIZE = 32768
|
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
|
+
|
13
|
+
# Implements kind_of? in order to pretend to be an IO object
|
14
|
+
module FakeIO
|
15
|
+
def kind_of?(object)
|
16
|
+
object == IO || super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Implements many of the convenience methods of IO
|
21
|
+
# such as gets, getc, readline and readlines
|
22
|
+
# depends on: input_finished?, produce_input and read
|
23
|
+
module AbstractInputStream
|
24
|
+
include Enumerable
|
25
|
+
include FakeIO
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
super
|
29
|
+
@lineno = 0
|
30
|
+
@outputBuffer = ""
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_accessor :lineno
|
34
|
+
|
35
|
+
def read(numberOfBytes = nil, buf = nil)
|
36
|
+
tbuf = nil
|
37
|
+
|
38
|
+
if @outputBuffer.length > 0
|
39
|
+
if numberOfBytes <= @outputBuffer.length
|
40
|
+
tbuf = @outputBuffer.slice!(0, numberOfBytes)
|
41
|
+
else
|
42
|
+
numberOfBytes -= @outputBuffer.length if (numberOfBytes)
|
43
|
+
rbuf = sysread(numberOfBytes, buf)
|
44
|
+
tbuf = @outputBuffer
|
45
|
+
tbuf << rbuf if (rbuf)
|
46
|
+
@outputBuffer = ""
|
47
|
+
end
|
48
|
+
else
|
49
|
+
tbuf = sysread(numberOfBytes, buf)
|
50
|
+
end
|
51
|
+
|
52
|
+
return nil unless (tbuf)
|
53
|
+
|
54
|
+
if buf
|
55
|
+
buf.replace(tbuf)
|
56
|
+
else
|
57
|
+
buf = tbuf
|
58
|
+
end
|
59
|
+
|
60
|
+
buf
|
61
|
+
end
|
62
|
+
|
63
|
+
def readlines(aSepString = $/)
|
64
|
+
retVal = []
|
65
|
+
each_line(aSepString) { |line| retVal << line }
|
66
|
+
return retVal
|
67
|
+
end
|
68
|
+
|
69
|
+
def gets(aSepString=$/)
|
70
|
+
@lineno = @lineno.next
|
71
|
+
return read if aSepString == nil
|
72
|
+
aSepString="#{$/}#{$/}" if aSepString == ""
|
73
|
+
|
74
|
+
bufferIndex=0
|
75
|
+
while ((matchIndex = @outputBuffer.index(aSepString, bufferIndex)) == nil)
|
76
|
+
bufferIndex=@outputBuffer.length
|
77
|
+
if input_finished?
|
78
|
+
return @outputBuffer.empty? ? nil : flush
|
79
|
+
end
|
80
|
+
@outputBuffer << produce_input
|
81
|
+
end
|
82
|
+
sepIndex=matchIndex + aSepString.length
|
83
|
+
return @outputBuffer.slice!(0...sepIndex)
|
84
|
+
end
|
85
|
+
|
86
|
+
def flush
|
87
|
+
retVal=@outputBuffer
|
88
|
+
@outputBuffer=""
|
89
|
+
return retVal
|
90
|
+
end
|
91
|
+
|
92
|
+
def readline(aSepString = $/)
|
93
|
+
retVal = gets(aSepString)
|
94
|
+
raise EOFError if retVal == nil
|
95
|
+
return retVal
|
96
|
+
end
|
97
|
+
|
98
|
+
def each_line(aSepString = $/)
|
99
|
+
while true
|
100
|
+
yield readline(aSepString)
|
101
|
+
end
|
102
|
+
rescue EOFError
|
103
|
+
end
|
104
|
+
|
105
|
+
alias_method :each, :each_line
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
# Implements many of the output convenience methods of IO.
|
110
|
+
# relies on <<
|
111
|
+
module AbstractOutputStream
|
112
|
+
include FakeIO
|
113
|
+
|
114
|
+
def write(data)
|
115
|
+
self << data
|
116
|
+
data.to_s.length
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def print(*params)
|
121
|
+
self << params.join << $\.to_s
|
122
|
+
end
|
123
|
+
|
124
|
+
def printf(aFormatString, *params)
|
125
|
+
self << sprintf(aFormatString, *params)
|
126
|
+
end
|
127
|
+
|
128
|
+
def putc(anObject)
|
129
|
+
self << case anObject
|
130
|
+
when Fixnum then anObject.chr
|
131
|
+
when String then anObject
|
132
|
+
else raise TypeError, "putc: Only Fixnum and String supported"
|
133
|
+
end
|
134
|
+
anObject
|
135
|
+
end
|
136
|
+
|
137
|
+
def puts(*params)
|
138
|
+
params << "\n" if params.empty?
|
139
|
+
params.flatten.each {
|
140
|
+
|element|
|
141
|
+
val = element.to_s
|
142
|
+
self << val
|
143
|
+
self << "\n" unless val[-1,1] == "\n"
|
144
|
+
}
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end # IOExtras namespace module
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
# Copyright (C) 2002-2004 Thomas Sondergaard
|
154
|
+
# rubyzip is free software; you can redistribute it and/or
|
155
|
+
# modify it under the terms of the ruby license.
|