8000 Update ZipCrypto instructions for 2.x versions. · rubyzip/rubyzip@fd0cf54 · GitHub
[go: up one dir, main page]

Skip to content

Commit fd0cf54

Browse files
committed
Update ZipCrypto instructions for 2.x versions.
Suggested by @KamilDzierbicki in #568.
1 parent e3c173b commit fd0cf54

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,27 @@ Any attempt to move about in a zip file opened with `Zip::InputStream` could res
205205

206206
Rubyzip supports reading/writing zip files with traditional zip encryption (a.k.a. "ZipCrypto"). AES encryption is not yet supported. It can be used with buffer streams, e.g.:
207207

208+
#### Version 2.x
209+
210+
```ruby
211+
# Writing.
212+
enc = Zip::TraditionalEncrypter.new('password')
213+
buffer = Zip::OutputStream.write_buffer(::StringIO.new(''), enc) do |output|
214+
output.put_next_entry("my_file.txt")
215+
output.write my_data
216+
end
217+
218+
# Reading.
219+
dec = Zip::TraditionalDecrypter.new('password')
220+
Zip::InputStream.open(buffer, 0, dec) do |input|
221+
entry = input.get_next_entry
222+
puts "Contents of '#{entry.name}':"
223+
puts input.read
224+
end
225+
```
226+
227+
#### Version 3.x
228+
208229
```ruby
209230
# Writing.
210231
enc = Zip::TraditionalEncrypter.new('password')

0 commit comments

Comments
 (0)
0