Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed ZipOutputStream.put_next_entry to make it possible to specifi…

…y comments, extra field and compression method.
  • Loading branch information...
commit d0faedc82b05e2f9ecd9916696cf7a4bf25c2f7c 1 parent 14198a4
thomas authored
Showing with 40 additions and 8 deletions.
  1. +5 −0 NEWS
  2. +18 −8 lib/zip/zip.rb
  3. +17 −0 test/ziptest.rb
View
5 NEWS
@@ -1,3 +1,8 @@
+= Version 0.9.4
+
+Changed ZipOutputStream.put_next_entry signature (API CHANGE!). Now
+allows comment, extra field and compression method to be specified.
+
= Version 0.9.3
Fixed: Added ZipEntry::name_encoding which retrieves the character
View
26 lib/zip/zip.rb
@@ -21,7 +21,7 @@ module Zlib #:nodoc:all
module Zip
- VERSION = '0.9.3'
+ VERSION = '0.9.4'
RUBY_MINOR_VERSION = RUBY_VERSION.split(".")[1].to_i
@@ -385,9 +385,14 @@ def initialize(zipfile = "", name = "", comment = "", extra = "",
else
@fstype = FSTYPE_UNIX
end
- @zipfile, @comment, @compressed_size, @crc, @extra, @compression_method,
- @name, @size = zipfile, comment, compressed_size, crc,
- extra, compression_method, name, size
+ @zipfile = zipfile
+ @comment = comment
+ @compressed_size = compressed_size
+ @crc = crc
+ @extra = extra
+ @compression_method = compression_method
+ @name = name
+ @size = size
@time = time
@follow_symlinks = false
@@ -972,11 +977,16 @@ def close
# Closes the current entry and opens a new for writing.
# +entry+ can be a ZipEntry object or a string.
- def put_next_entry(entry, level = Zlib::DEFAULT_COMPRESSION)
+ def put_next_entry(entryname, comment = nil, extra = nil, compression_method = ZipEntry::DEFLATED, level = Zlib::DEFAULT_COMPRESSION)
raise ZipError, "zip stream is closed" if @closed
- newEntry = entry.kind_of?(ZipEntry) ? entry : ZipEntry.new(@fileName, entry.to_s)
- init_next_entry(newEntry, level)
- @currentEntry=newEntry
+ new_entry = ZipEntry.new(@fileName, entryname.to_s)
+ new_entry.comment = comment if !comment.nil?
+ if (!extra.nil?)
+ new_entry.extra = ZipExtraField === extra ? extra : ZipExtraField.new(extra.to_s)
+ end
+ new_entry.compression_method = compression_method
+ init_next_entry(new_entry, level)
+ @currentEntry = new_entry
end
def copy_raw_entry(entry)
View
17 test/ziptest.rb
@@ -632,6 +632,23 @@ def test_cannotOpenFile
end
end
+ def test_put_next_entry
+ stored_text = "hello world in stored text"
+ entry_name = "file1"
+ comment = "my comment"
+ ZipOutputStream.open(TEST_ZIP.zip_name) do
+ |zos|
+ zos.put_next_entry(entry_name, comment, nil, ZipEntry::STORED)
+ zos << stored_text
+ end
+
+ assert(File.read(TEST_ZIP.zip_name).grep(stored_text))
+ ZipFile.open(TEST_ZIP.zip_name) do
+ |zf|
+ assert_equal(stored_text, zf.read(entry_name))
+ end
+ end
+
def assert_i_o_error_in_closed_stream
assert_raise(IOError) {
zos = ZipOutputStream.new("test_putOnClosedStream.zip")

0 comments on commit d0faedc

Please sign in to comment.
Something went wrong with that request. Please try again.