From 055abed0e28681387377671bc16d40d075e3aaf7 Mon Sep 17 00:00:00 2001
From: Paul Duncan Reading from a zip file: # create output MemoryIO
-mem_io = MemoryIO.new # read from "foo.zip"
-Zip.read("foo.zip") do |zip|
-# read contents of "bar.txt" in "foo.zip" into mem_io
-zip["bar.txt"].read(mem_io)
-end Writing to a zip file: # write to "foo.zip"
-Zip.write("foo.zip") do |zip|
-# create "bar.txt" with contents "hello!"
-zip.add("bar.txt", "hello!")
-end# create output MemoryIO
+mem_io = MemoryIO.new
-
@@ -254,14 +254,14 @@ end# write to "foo.zip"
+Zip.write("foo.zip") do |zip|
+ # create "bar.txt" with contents "hello!"
+ zip.add("bar.txt", "hello!")
+end
Example:
-# create memory io for contents of "bar.txt" -io = MemoryIO.new
+# create memory io for contents of "bar.txt"
+io = MemoryIO.new
-# extract "bar.txt" from zip archive in Slice some_slice and
-# save it to MemoryIO
-Zip.read(some_slice) do |zip|
-zip["bar.txt"].read(io)
-end
+# extract "bar.txt" from zip archive in Slice some_slice and
+# save it to MemoryIO
+Zip.read(some_slice) do |zip|
+ zip["bar.txt"].read(io)
+end
Example:
-# create memory io for contents of "bar.txt" -io = MemoryIO.new
+# create memory io for contents of "bar.txt"
+io = MemoryIO.new
-# extract "bar.txt" from "./foo.zip" and save it to MemoryIO
-Zip.read("./foo.zip") do |zip|
-zip["bar.txt"].read(io)
-end
+# extract "bar.txt" from "foo.zip" and save it to MemoryIO
+Zip.read("foo.zip") do |zip|
+ zip["bar.txt"].read(io)
+end
Example:
-# create memory io for contents of "bar.txt" -io = MemoryIO.new
+# create memory io for contents of "bar.txt"
+io = MemoryIO.new
-# read "bar.txt" from "./foo.zip"
-Zip.read(File.open("./foo.zip", "rb")) do |zip|
-zip["bar.txt"].read(io)
-end
Example:
-# create output IO -File.open("foo.zip", "wb") do |io| -Zip.write(io) do |zip| -# add "bar.txt" with contents "hello!" -zip.add("bar.txt", "hello!") -end -end
# create output IO
+File.open("foo.zip", "wb") do |io|
+ Zip.write(io) do |zip|
+ # add "bar.txt" with contents "hello!"
+ zip.add("bar.txt", "hello!")
+ end
+end
Example:
-# create "foo.zip" -Zip.write("foo.zip") do |zip| -# add "bar.txt" with contents "hello!" -zip.add("bar.txt", "hello!") -end
# create "foo.zip"
+Zip.write("foo.zip") do |zip|
+ # add "bar.txt" with contents "hello!"
+ zip.add("bar.txt", "hello!")
+end