superp-rubyzip 0.1.0
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.
- checksums.yaml +15 -0
- data/NEWS +176 -0
- data/README.md +175 -0
- data/Rakefile +13 -0
- data/TODO +16 -0
- data/lib/zip.rb +52 -0
- data/lib/zip/central_directory.rb +135 -0
- data/lib/zip/compressor.rb +10 -0
- data/lib/zip/constants.rb +61 -0
- data/lib/zip/decompressor.rb +13 -0
- data/lib/zip/deflater.rb +29 -0
- data/lib/zip/dos_time.rb +49 -0
- data/lib/zip/entry.rb +609 -0
- data/lib/zip/entry_set.rb +86 -0
- data/lib/zip/errors.rb +8 -0
- data/lib/zip/extra_field.rb +90 -0
- data/lib/zip/extra_field/generic.rb +43 -0
- data/lib/zip/extra_field/universal_time.rb +47 -0
- data/lib/zip/extra_field/unix.rb +39 -0
- data/lib/zip/file.rb +419 -0
- data/lib/zip/filesystem.rb +622 -0
- data/lib/zip/inflater.rb +65 -0
- data/lib/zip/input_stream.rb +145 -0
- data/lib/zip/ioextras.rb +186 -0
- data/lib/zip/null_compressor.rb +15 -0
- data/lib/zip/null_decompressor.rb +27 -0
- data/lib/zip/null_input_stream.rb +9 -0
- data/lib/zip/output_stream.rb +175 -0
- data/lib/zip/pass_thru_compressor.rb +23 -0
- data/lib/zip/pass_thru_decompressor.rb +41 -0
- data/lib/zip/streamable_directory.rb +15 -0
- data/lib/zip/streamable_stream.rb +47 -0
- data/lib/zip/version.rb +3 -0
- data/samples/example.rb +91 -0
- data/samples/example_filesystem.rb +33 -0
- data/samples/example_recursive.rb +49 -0
- data/samples/gtkRubyzip.rb +86 -0
- data/samples/qtzip.rb +101 -0
- data/samples/write_simple.rb +13 -0
- data/samples/zipfind.rb +74 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTM1OWI1MWE3MTk4MWVkNWM3ZTBmOGNiNmNlYzExMjY1YWRjOGFmNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MWIzOGRkZjVjNzc2NTE2NDQ0ODExNzZhMGFiMDZkNDg5NGQ2MTY3Mg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MWU4ZGFiNzE1ZTNhYzcyNzI5ODdkMzg3YTg4NmZmNGQxYjhmNDJjNTQ5MmZk
|
10
|
+
MzU0NGQ1YzViZTk2MzFjZTgwZmEyZGE0ZDMyZGEzYmYxNDk4MGY1MjViOTY3
|
11
|
+
MDMyY2RkOWMzZjZjNjAyMjM3YjBiYmNmMDc4OTUwYWIwNTAzNjI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTliZWVlMjQyYmE5MDY3YWE0NmU3Mjk3YjYzZWNjMTM3ZGVhYjVkZjI4NTcy
|
14
|
+
Nzc2NzhmMjgyOTI1YjI2N2EwOTQ4NGQ2NTk2MWQxN2U5NjJlYjg1MTZkYzc5
|
15
|
+
NjY2YjJmZjhmOTA0MjdiODUzZmEzZDM0ODA4NWQ3NjdhOWRkN2E=
|
data/NEWS
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
= Version 0.9.9
|
2
|
+
|
3
|
+
Added support for backslashes in zip files (generated by the default Windows
|
4
|
+
zip packer for example) and comment sections with the comment length set to zero
|
5
|
+
even though there is actually a comment.
|
6
|
+
|
7
|
+
= Version 0.9.8
|
8
|
+
|
9
|
+
Fixed: "Unitialized constant NullInputStream" error
|
10
|
+
|
11
|
+
= Version 0.9.5
|
12
|
+
|
13
|
+
Removed support for loading ruby in zip files (ziprequire.rb).
|
14
|
+
|
15
|
+
= Version 0.9.4
|
16
|
+
|
17
|
+
Changed ZipOutputStream.put_next_entry signature (API CHANGE!). Now
|
18
|
+
allows comment, extra field and compression method to be specified.
|
19
|
+
|
20
|
+
= Version 0.9.3
|
21
|
+
|
22
|
+
Fixed: Added ZipEntry::name_encoding which retrieves the character
|
23
|
+
encoding of the name and comment of the entry. Also added convenience
|
24
|
+
methods ZipEntry::name_in(enc) and ZipEntry::comment_in(enc) for
|
25
|
+
getting zip entry names and comments in a specified character
|
26
|
+
encoding.
|
27
|
+
|
28
|
+
= Version 0.9.2
|
29
|
+
|
30
|
+
Fixed: Renaming an entry failed if the entry's new name was a
|
31
|
+
different length than its old name. (Diego Barros)
|
32
|
+
|
33
|
+
= Version 0.9.1
|
34
|
+
|
35
|
+
Added symlink support and support for unix file permissions. Reduced
|
36
|
+
memory usage during decompression.
|
37
|
+
|
38
|
+
New methods ZipFile::[follow_symlinks, restore_times, restore_permissions, restore_ownership].
|
39
|
+
New methods ZipEntry::unix_perms, ZipInputStream::eof?.
|
40
|
+
Added documentation and test for new ZipFile::extract.
|
41
|
+
Added some of the API suggestions from sf.net #1281314.
|
42
|
+
Applied patch for sf.net bug #1446926.
|
43
|
+
Applied patch for sf.net bug #1459902.
|
44
|
+
Rework ZipEntry and delegate classes.
|
45
|
+
|
46
|
+
= Version 0.5.12
|
47
|
+
|
48
|
+
Fixed problem with writing binary content to a ZipFile in MS Windows.
|
49
|
+
|
50
|
+
= Version 0.5.11
|
51
|
+
|
52
|
+
Fixed name clash file method copy_stream from fileutils.rb. Fixed
|
53
|
+
problem with references to constant CHUNK_SIZE.
|
54
|
+
ZipInputStream/AbstractInputStream read is now buffered like ruby IO's
|
55
|
+
read method, which means that read and gets etc can be mixed. The
|
56
|
+
unbuffered read method has been renamed to sysread.
|
57
|
+
|
58
|
+
= Version 0.5.10
|
59
|
+
|
60
|
+
Fixed method name resolution problem with FileUtils::copy_stream and
|
61
|
+
IOExtras::copy_stream.
|
62
|
+
|
63
|
+
= Version 0.5.9
|
64
|
+
|
65
|
+
Fixed serious memory consumption issue
|
66
|
+
|
67
|
+
= Version 0.5.8
|
68
|
+
|
69
|
+
Fixed install script.
|
70
|
+
|
71
|
+
= Version 0.5.7
|
72
|
+
|
73
|
+
install.rb no longer assumes it is being run from the toplevel source
|
74
|
+
dir. Directory structure changed to reflect common ruby library
|
75
|
+
project structure. Migrated from RubyUnit to Test::Unit format. Now
|
76
|
+
uses Rake to build source packages and gems and run unit tests.
|
77
|
+
|
78
|
+
= Version 0.5.6
|
79
|
+
|
80
|
+
Fix for FreeBSD 4.9 which returns Errno::EFBIG instead of
|
81
|
+
Errno::EINVAL for some invalid seeks. Fixed 'version needed to
|
82
|
+
extract'-field incorrect in local headers.
|
83
|
+
|
84
|
+
= Version 0.5.5
|
85
|
+
|
86
|
+
Fix for a problem with writing zip files that concerns only ruby 1.8.1.
|
87
|
+
|
88
|
+
= Version 0.5.4
|
89
|
+
|
90
|
+
Significantly reduced memory footprint when modifying zip files.
|
91
|
+
|
92
|
+
= Version 0.5.3
|
93
|
+
|
94
|
+
Added optimization to avoid decompressing and recompressing individual
|
95
|
+
entries when modifying a zip archive.
|
96
|
+
|
97
|
+
= Version 0.5.2
|
98
|
+
|
99
|
+
Fixed ZipFile corruption bug in ZipFile class. Added basic unix
|
100
|
+
extra-field support.
|
101
|
+
|
102
|
+
= Version 0.5.1
|
103
|
+
|
104
|
+
Fixed ZipFile.get_output_stream bug.
|
105
|
+
|
106
|
+
= Version 0.5.0
|
107
|
+
|
108
|
+
List of changes:
|
109
|
+
* Ruby 1.8.0 and ruby-zlib 0.6.0 compatibility
|
110
|
+
* Changed method names from camelCase to rubys underscore style.
|
111
|
+
* Installs to zip/ subdir instead of directly to site_ruby
|
112
|
+
* Added ZipFile.directory and ZipFile.file - each method return an
|
113
|
+
object that can be used like Dir and File only for the contents of the
|
114
|
+
zip file.
|
115
|
+
* Added sample application zipfind which works like Find.find, only
|
116
|
+
Zip::ZipFind.find traverses into zip archives too.
|
117
|
+
|
118
|
+
Bug fixes:
|
119
|
+
* AbstractInputStream.each_line with non-default separator
|
120
|
+
|
121
|
+
|
122
|
+
= Version 0.5.0a
|
123
|
+
|
124
|
+
Source reorganized. Added ziprequire, which can be used to load ruby
|
125
|
+
modules from a zip file, in a fashion similar to jar files in
|
126
|
+
Java. Added gtkRubyzip, another sample application. Implemented
|
127
|
+
ZipInputStream.lineno and ZipInputStream.rewind
|
128
|
+
|
129
|
+
Bug fixes:
|
130
|
+
|
131
|
+
* Read and write date and time information correctly for zip entries.
|
132
|
+
* Fixed read() using separate buffer, causing mix of gets/readline/read to
|
133
|
+
cause problems.
|
134
|
+
|
135
|
+
= Version 0.4.2
|
136
|
+
|
137
|
+
Performance optimizations. Test suite runs in half the time.
|
138
|
+
|
139
|
+
= Version 0.4.1
|
140
|
+
|
141
|
+
Windows compatibility fixes.
|
142
|
+
|
143
|
+
= Version 0.4.0
|
144
|
+
|
145
|
+
Zip::ZipFile is now mutable and provides a more convenient way of
|
146
|
+
modifying zip archives than Zip::ZipOutputStream. Operations for
|
147
|
+
adding, extracting, renaming, replacing and removing entries to zip
|
148
|
+
archives are now available.
|
149
|
+
|
150
|
+
Runs without warnings with -w switch.
|
151
|
+
|
152
|
+
Install script install.rb added.
|
153
|
+
|
154
|
+
|
155
|
+
= Version 0.3.1
|
156
|
+
|
157
|
+
Rudimentary support for writing zip archives.
|
158
|
+
|
159
|
+
|
160
|
+
= Version 0.2.2
|
161
|
+
|
162
|
+
Fixed and extended unit test suite. Updated to work with ruby/zlib
|
163
|
+
0.5. It doesn't work with earlier versions of ruby/zlib.
|
164
|
+
|
165
|
+
|
166
|
+
= Version 0.2.0
|
167
|
+
|
168
|
+
Class ZipFile added. Where ZipInputStream is used to read the
|
169
|
+
individual entries in a zip file, ZipFile reads the central directory
|
170
|
+
in the zip archive, so you can get to any entry in the zip archive
|
171
|
+
without having to skipping through all the preceeding entries.
|
172
|
+
|
173
|
+
|
174
|
+
= Version 0.1.0
|
175
|
+
|
176
|
+
First working version of ZipInputStream.
|
data/README.md
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
# rubyzip [](http://travis-ci.org/aussiegeek/rubyzip)[](https://codeclimate.com/github/aussiegeek/rubyzip)
|
2
|
+
|
3
|
+
rubyzip is a ruby library for reading and writing zip files.
|
4
|
+
|
5
|
+
## Important note
|
6
|
+
|
7
|
+
This brucnh for next version of rubyzip. Do not use it on production.
|
8
|
+
Rubyzip interface will be changed!!!
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
rubyzip is available on RubyGems, so:
|
12
|
+
|
13
|
+
```
|
14
|
+
gem install rubyzip
|
15
|
+
```
|
16
|
+
|
17
|
+
Or in your Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'rubyzip'
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Basic zip archive creation
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'rubygems'
|
29
|
+
require 'zip'
|
30
|
+
|
31
|
+
folder = "Users/me/Desktop/stuff_to_zip"
|
32
|
+
input_filenames = ['image.jpg', 'description.txt', 'stats.csv']
|
33
|
+
|
34
|
+
zipfile_name = "/Users/me/Desktop/archive.zip"
|
35
|
+
|
36
|
+
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
|
37
|
+
input_filenames.each do |filename|
|
38
|
+
# Two arguments:
|
39
|
+
# - The name of the file as it will appear in the archive
|
40
|
+
# - The original file, including the path to find it
|
41
|
+
zipfile.add(filename, folder + '/' + filename)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
### Zipping a directory recursively
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require 'rubygems'
|
50
|
+
require 'zip'
|
51
|
+
|
52
|
+
directory = '/Users/me/Desktop/directory_to_zip/'
|
53
|
+
zipfile_name = '/Users/me/Desktop/recursive_directory.zip'
|
54
|
+
|
55
|
+
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
|
56
|
+
Dir[File.join(directory, '**', '**')].each do |file|
|
57
|
+
zipfile.add(file.sub(directory, ''), file)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
## Known issues
|
63
|
+
|
64
|
+
### Modify docx file with rubyzip
|
65
|
+
|
66
|
+
Use `write_buffer` instead `open`. Thanks to @jondruse
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
buffer = Zip::OutputStream.write_buffer do |out|
|
70
|
+
@zip_file.entries.each do |e|
|
71
|
+
unless [DOCUMENT_FILE_PATH, RELS_FILE_PATH].include?(e.name)
|
72
|
+
out.put_next_entry(e.name)
|
73
|
+
out.write e.get_input_stream.read
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
out.put_next_entry(DOCUMENT_FILE_PATH)
|
78
|
+
out.write xml_doc.to_xml(:indent => 0).gsub("\n","")
|
79
|
+
|
80
|
+
out.put_next_entry(RELS_FILE_PATH)
|
81
|
+
out.write rels.to_xml(:indent => 0).gsub("\n","")
|
82
|
+
end
|
83
|
+
|
84
|
+
File.open(new_path, "w") {|f| f.write(buffer.string) }
|
85
|
+
```
|
86
|
+
|
87
|
+
## Further Documentation
|
88
|
+
|
89
|
+
There is more than one way to access or create a zip archive with
|
90
|
+
rubyzip. The basic API is modeled after the classes in
|
91
|
+
java.util.zip from the Java SDK. This means there are classes such
|
92
|
+
as Zip::InputStream, Zip::OutputStream and
|
93
|
+
Zip::File. Zip::InputStream provides a basic interface for
|
94
|
+
iterating through the entries in a zip archive and reading from the
|
95
|
+
entries in the same way as from a regular File or IO
|
96
|
+
object. OutputStream is the corresponding basic output
|
97
|
+
facility. Zip::File provides a mean for accessing the archives
|
98
|
+
central directory and provides means for accessing any entry without
|
99
|
+
having to iterate through the archive. Unlike Java's
|
100
|
+
java.util.zip.ZipFile rubyzip's Zip::File is mutable, which means
|
101
|
+
it can be used to change zip files as well.
|
102
|
+
|
103
|
+
Another way to access a zip archive with rubyzip is to use rubyzip's
|
104
|
+
Zip::FileSystem API. Using this API files can be read from and
|
105
|
+
written to the archive in much the same manner as ruby's builtin
|
106
|
+
classes allows files to be read from and written to the file system.
|
107
|
+
|
108
|
+
For details about the specific behaviour of classes and methods refer
|
109
|
+
to the test suite. Finally you can generate the rdoc documentation or
|
110
|
+
visit http://rubyzip.sourceforge.net.
|
111
|
+
|
112
|
+
|
113
|
+
## Configuration
|
114
|
+
|
115
|
+
By default, rubyzip will not overwrite files if they already exist inside of the extracted path. To change this behavior, you may specify a configuration option like so:
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
Zip.on_exists_proc = true
|
119
|
+
```
|
120
|
+
|
121
|
+
If you're using rubyzip with rails, consider placing this snippet of code in an initializer file such as `config/initializers/rubyzip.rb`
|
122
|
+
|
123
|
+
Additionally, if you want to configure rubyzip to overwrite existing files while creating a .zip file, you can do so with the following:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
Zip.continue_on_exists_proc = true
|
127
|
+
```
|
128
|
+
|
129
|
+
If you want to store non english names and want to open properly file on Windows(pre 7) you need to set next option:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
Zip.unicode_names = true
|
133
|
+
```
|
134
|
+
|
135
|
+
All settings in same time
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
Zip.setup do |c|
|
139
|
+
c.on_exists_proc = true
|
140
|
+
c.continue_on_exists_proc = true
|
141
|
+
c.unicode_names = true
|
142
|
+
end
|
143
|
+
```
|
144
|
+
|
145
|
+
## Developing
|
146
|
+
|
147
|
+
To run tests you need run next commands:
|
148
|
+
|
149
|
+
```
|
150
|
+
bundle install
|
151
|
+
rake
|
152
|
+
```
|
153
|
+
|
154
|
+
## Website and Project Home
|
155
|
+
|
156
|
+
http://github.com/rubyzip/rubyzip
|
157
|
+
|
158
|
+
http://rdoc.info/github/rubyzip/rubyzip/master/frames
|
159
|
+
|
160
|
+
## Authors
|
161
|
+
|
162
|
+
Alexander Simonov ( alex at simonov.me)
|
163
|
+
|
164
|
+
Alan Harper ( alan at aussiegeek.net)
|
165
|
+
|
166
|
+
Thomas Sondergaard (thomas at sondergaard.cc)
|
167
|
+
|
168
|
+
Technorama Ltd. (oss-ruby-zip at technorama.net)
|
169
|
+
|
170
|
+
extra-field support contributed by Tatsuki Sugiura (sugi at nemui.org)
|
171
|
+
|
172
|
+
## License
|
173
|
+
|
174
|
+
rubyzip is distributed under the same license as ruby. See
|
175
|
+
http://www.ruby-lang.org/en/LICENSE.txt
|
data/Rakefile
ADDED
@@ -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/alltests.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
|
data/lib/zip.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require 'singleton'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'stringio'
|
6
|
+
require 'zlib'
|
7
|
+
require 'zip/dos_time'
|
8
|
+
require 'zip/ioextras'
|
9
|
+
require 'rbconfig'
|
10
|
+
require 'zip/entry'
|
11
|
+
require 'zip/extra_field'
|
12
|
+
require 'zip/entry_set'
|
13
|
+
require 'zip/central_directory'
|
14
|
+
require 'zip/file'
|
15
|
+
require 'zip/input_stream'
|
16
|
+
require 'zip/output_stream'
|
17
|
+
require 'zip/decompressor'
|
18
|
+
require 'zip/compressor'
|
19
|
+
require 'zip/null_decompressor'
|
20
|
+
require 'zip/null_compressor'
|
21
|
+
require 'zip/null_input_stream'
|
22
|
+
require 'zip/pass_thru_compressor'
|
23
|
+
require 'zip/pass_thru_decompressor'
|
24
|
+
require 'zip/inflater'
|
25
|
+
require 'zip/deflater'
|
26
|
+
require 'zip/streamable_stream'
|
27
|
+
require 'zip/streamable_directory'
|
28
|
+
require 'zip/constants'
|
29
|
+
require 'zip/errors'
|
30
|
+
|
31
|
+
module Zip
|
32
|
+
extend self
|
33
|
+
attr_accessor :unicode_names, :on_exists_proc, :continue_on_exists_proc
|
34
|
+
|
35
|
+
def reset!
|
36
|
+
@_ran_once = false
|
37
|
+
@unicode_names = false
|
38
|
+
@on_exists_proc = false
|
39
|
+
@continue_on_exists_proc = false
|
40
|
+
end
|
41
|
+
|
42
|
+
def setup
|
43
|
+
yield self unless @_ran_once
|
44
|
+
@_ran_once = true
|
45
|
+
end
|
46
|
+
|
47
|
+
reset!
|
48
|
+
end
|
49
|
+
|
50
|
+
# Copyright (C) 2002, 2003 Thomas Sondergaard
|
51
|
+
# rubyzip is free software; you can redistribute it and/or
|
52
|
+
# modify it under the terms of the ruby license.
|