File: README.md

package info (click to toggle)
ruby-archive-zip 0.11.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 772 kB
  • sloc: ruby: 5,052; makefile: 3
file content (252 lines) | stat: -rw-r--r-- 7,774 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# Archive::Zip - ZIP Archival Made Easy

Simple, extensible, pure Ruby ZIP archive support.

Basic archive creation and extraction can be handled using only a few methods.
More complex operations involving the manipulation of existing archives in place
(adding, removing, and modifying entries) are also possible with a little more
work.  Even adding advanced features such as new compression codecs are
supported with a moderate amount of effort.

## LINKS

* Homepage :: http://github.com/javanthropus/archive-zip
* Documentation :: http://rdoc.info/gems/archive-zip/frames
* Source :: http://github.com/javanthropus/archive-zip

## DESCRIPTION

Archive::Zip provides a simple Ruby-esque interface to creating, extracting, and
updating ZIP archives.  This implementation is 100% Ruby and loosely modeled on
the archive creation and extraction capabilities of InfoZip's zip and unzip
tools.

## FEATURES

* 100% native Ruby.  (Well, almost... depends on zlib.)
* Archive creation and extraction is supported with only a few lines of code.
* Archives can be updated "in place" or dumped out to other files or pipes.
* Files, symlinks, and directories are supported within archives.
* Unix permission/mode bits are supported.
* Unix user and group ownerships are supported.
* Unix last accessed and last modified times are supported.
* Entry extension (AKA extra field) implementations can be added on the fly.
* Unknown entry extension types are preserved during archive processing.
* The Deflate and Store compression codecs are supported out of the box.
* More compression codecs can be added on the fly.
* Traditional (weak) encryption is supported out of the box.

## KNOWN BUGS/LIMITATIONS

* More testcases are needed.
* All file entries are archived and extracted in binary mode.  No attempt is
  made to normalize text files to the line ending convention of any target
  system.
* Hard links and device files are not currently supported within archives.
* Reading archives from non-seekable IO, such as pipes and sockets, is not
  supported.
* MSDOS permission attributes are not supported.
* Strong encryption is not supported.
* Zip64 is not supported.
* Digital signatures are not supported.

## SYNOPSIS

More examples can be found in the `examples` directory of the source
distribution.

Create a few archives:

```ruby
require 'archive/zip'

# Add a_directory and its contents to example1.zip.
Archive::Zip.archive('example1.zip', 'a_directory')

# Add the contents of a_directory to example2.zip.
Archive::Zip.archive('example2.zip', 'a_directory/.')

# Add a_file and a_directory and its contents to example3.zip.
Archive::Zip.archive('example3.zip', ['a_directory', 'a_file'])

# Add only the files and symlinks contained in a_directory under the path
# a/b/c/a_directory in example4.zip.
Archive::Zip.archive(
  'example4.zip',
  'a_directory',
  :directories => false,
  :path_prefix => 'a/b/c'
)

# Add the contents of a_directory to example5.zip and encrypt Ruby source
# files.
require 'archive/zip/codec/null_encryption'
require 'archive/zip/codec/traditional_encryption'
Archive::Zip.archive(
  'example5.zip',
  'a_directory/.',
  :encryption_codec => lambda do |entry|
    if entry.file? and entry.zip_path =~ /\.rb$/ then
      Archive::Zip::Codec::TraditionalEncryption
    else
      Archive::Zip::Codec::NullEncryption
    end
  end,
  :password => 'seakrit'
)

# Create a new archive which will be written to a pipe.
# Assume $stdout is the write end a pipe.
# (ruby example.rb | cat >example.zip)
Archive::Zip.open($stdout, :w) do |z|
  z.archive('a_directory')
end
```

Now extract those archives:

```ruby
require 'archive/zip'

# Extract example1.zip to a_destination.
Archive::Zip.extract('example1.zip', 'a_destination')

# Extract example2.zip to a_destination, skipping directory entries.
Archive::Zip.extract(
  'example2.zip',
  'a_destination',
  :directories => false
)

# Extract example3.zip to a_destination, skipping symlinks.
Archive::Zip.extract(
  'example3.zip',
  'a_destination',
  :symlinks => false
)

# Extract example4.zip to a_destination, skipping entries for which files
# already exist but are newer or for which files do not exist at all.
Archive::Zip.extract(
  'example4.zip',
  'a_destination',
  :create => false,
  :overwrite => :older
)

# Extract example5.zip to a_destination, decrypting the contents.
Archive::Zip.extract(
  'example5.zip',
  'a_destination',
  :password => 'seakrit'
)
```

## FUTURE WORK ITEMS (in no particular order):

* Add test cases for all classes.
* Add support for using non-seekable IO objects as archive sources.
* Add support for 0x5855 and 0x7855 extra fields.

## REQUIREMENTS

* io-like

## INSTALL

Download the GEM file and install it with:

    $ gem install archive-zip-VERSION.gem

or directly with:

    $ gem install archive-zip

Removal is the same in either case:

    $ gem uninstall archive-zip

## DEVELOPERS

After checking out the source, run:

    $ bundle install
    $ bundle exec rake test yard

This will install all dependencies, run the tests/specs, and generate the
documentation.

## AUTHORS and CONTRIBUTORS

Thanks to all contributors.  Without your help this project would not exist.

* Jeremy Bopp :: jeremy@bopp.net
* Akira Matsuda :: ronnie@dio.jp
* Tatsuya Sato :: tatsuya.b.sato@rakuten.com

## CONTRIBUTING

Contributions for bug fixes, documentation, extensions, tests, etc. are
encouraged.

1. Clone the repository.
2. Fix a bug or add a feature.
3. Add tests for the fix or feature.
4. Make a pull request.

### CODING STYLE

The following points are not necessarily set in stone but should rather be used
as a good guideline.  Consistency is the goal of coding style, and changes will
be more easily accepted if they are consistent with the rest of the code.

* **File Encoding**
  * UTF-8
* **Indentation**
  * Two spaces; no tabs
* **Line length**
  * Limit lines to a maximum of 80 characters
* **Comments**
  * Document classes, attributes, methods, and code
* **Method Calls with Arguments**
  * Use `a_method(arg, arg, etc)`; **not** `a_method( arg, arg, etc )`,
    `a_method arg, arg, etc`, or any other variation
* **Method Calls without Arguments**
  * Use `a_method`; avoid parenthesis
* **String Literals**
  * Use single quotes by default
  * Use double quotes when interpolation is necessary
  * Use `%{...}` and similar when embedding the quoting character is cumbersome
* **Blocks**
  * `do ... end` for multi-line blocks and `{ ... }` for single-line blocks
* **Boolean Operators**
  * Use `&&` and `||` for boolean tests; avoid `and` and `or`
* **In General**
  * Try to follow the flow and style of the rest of the code

## LICENSE

```
(The MIT License)

Copyright (c) 2018 Jeremy Bopp

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```