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
Example:
-# get bar.txt and read it into memory io -io = MemoryIO.new -zip["bar.txt"].read(io)
# get bar.txt and read it into memory io
+io = MemoryIO.new
+zip["bar.txt"].read(io)
Example:
-# read third entry from archive into memory io -io = MemoryIO.new -zip[2].read(io)
+# read third entry from archive into memory io
+io = MemoryIO.new
+zip[2].read(io)
Example:
-# read third entry from archive into memory io -if e = zip[2] -io = MemoryIO.new -e.read(io) -end
+# read third entry from archive into memory io
+if e = zip[2]?
+ io = MemoryIO.new
+ e.read(io)
+end
Example:
-# read bar.txt into memory io if it exists -if e = zip["bar.txt"]? -io = MemoryIO.new -e.read(io) -end
+# read bar.txt into memory io if it exists
+if e = zip["bar.txt"]?
+ io = MemoryIO.new
+ e.read(io)
+end
Example:
-# create MemoryIO -io = MemoryIO.new
+# create MemoryIO
+io = MemoryIO.new
-# open "foo.zip"
-Zip.read("foo.zip") do |zip|
-# get "bar.txt" entry from "foo.zip"
-e = zip["bar.txt"]
+# open "foo.zip"
+Zip.read("foo.zip") do |zip|
+ # get "bar.txt" entry from "foo.zip"
+ e = zip["bar.txt"]
-# read contents of "bar.txt" into io
-e.read(io)
-
-end
+ # read contents of "bar.txt" into io
+ e.read(io)
+end
@@ -463,11 +462,11 @@ file's entry in the Central Directory, and this method returns the
Example:
-# open "./foo.zip" -Zip.read("./foo.zip") do |zip| -# get array of local extra attributes from "bar.txt" -extras = zip["bar.txt"].local_extras -end
# open "./foo.zip"
+Zip.read("./foo.zip") do |zip|
+ # get array of local extra attributes from "bar.txt"
+ extras = zip["bar.txt"].local_extras
+end
Example:
-# open "output-bar.txt" for writing -File.open("output-bar.txt", "wb") do |io| -# open archive "./foo.zip" -Zip.read("foo.zip") do |zip| -# write contents of "bar.txt" to "output-bar.txt" -zip["foo.txt"].read(io) -end -end
# open "output-bar.txt" for writing
+File.open("output-bar.txt", "wb") do |io|
+ # open archive "./foo.zip"
+ Zip.read("foo.zip") do |zip|
+ # write contents of "bar.txt" to "output-bar.txt"
+ zip["foo.txt"].read(io)
+ end
+end
Example:
-Zip.read("foo.zip") do |zip| -size = zip["bar.txt"].size -puts "bar.txt is #{size} bytes." -end
+Zip.read("foo.zip") do |zip|
+ size = zip["bar.txt"].size
+ puts "bar.txt is #{size} bytes."
+end
Wrapper class for exceptions.
+You shouldn't need to instantiate this class directly; it is raised +by other classes on error.
+ diff --git a/Zip/Extra.html b/Zip/Extra.html index cb489df..3ea15f3 100644 --- a/Zip/Extra.html +++ b/Zip/Extra.html @@ -121,11 +121,11 @@Example:
-# open "foo.zip" -Zip.read("foo.zip") do |zip| -# get extra data associated with "bar.txt" -extras = zip["bar.txt"].extras -end
+# open "foo.zip"
+Zip.read("foo.zip") do |zip|
+ # get extra data associated with "bar.txt"
+ extras = zip["bar.txt"].extras
+end
diff --git a/Zip/Writer.html b/Zip/Writer.html
index c28c13e..894055d 100644
--- a/Zip/Writer.html
+++ b/Zip/Writer.html
@@ -255,14 +255,14 @@ return the number of bytes written.
Example:
-# create IO from "/path/to/bar.txt" -File.open("/path/to/bar.txt, "rb") do |io| -# write to "foo.zip" -Zip.write("foo.zip") do |zip| -# add "bar.txt" with contents of given IO -zip.add("bar.txt", io) -end -end
# create IO from "/path/to/bar.txt"
+File.open("/path/to/bar.txt, "rb") do |io|
+ # write to "foo.zip"
+ Zip.write("foo.zip") do |zip|
+ # add "bar.txt" with contents of given IO
+ zip.add("bar.txt", io)
+ end
+end
Example:
-# write to "foo.zip" -Zip.write("foo.zip") do |zip| -# add "bar.txt" with contents "hello!" -zip.add("bar.txt", "hello!") -end
# write to "foo.zip"
+Zip.write("foo.zip") do |zip|
+ # add "bar.txt" with contents "hello!"
+ zip.add("bar.txt", "hello!")
+end
Example:
-# write to "foo.zip" -Zip.write("foo.zip") do |zip| -# add local file "/path/to/bar.txt" as "bar.txt" -zip.add_file("bar.txt", "/path/to/bar.txt") -end
# write to "foo.zip"
+Zip.write("foo.zip") do |zip|
+ # add local file "/path/to/bar.txt" as "bar.txt"
+ zip.add_file("bar.txt", "/path/to/bar.txt")
+end
Example:
-Zip.write("foo.zip") do |zip| -# add "bar.txt" -zip.add_file("bar.txt", "/path/to/bar.txt")
+Zip.write("foo.zip") do |zip|
+ # add "bar.txt"
+ zip.add_file("bar.txt", "/path/to/bar.txt")
-# print number of bytes written so far
-puts "bytes written so far: #{zip.bytes_written}"
-
-end
+ # print number of bytes written so far
+ puts "bytes written so far: #{zip.bytes_written}"
+end