Use named params for `InputStream`.
This commit is contained in:
parent
f75eb61578
commit
aa646ef827
|
@ -577,7 +577,7 @@ module Zip
|
||||||
raise "unknown @file_type #{@ftype}"
|
raise "unknown @file_type #{@ftype}"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
zis = ::Zip::InputStream.new(@zipfile, local_header_offset)
|
zis = ::Zip::InputStream.new(@zipfile, offset: local_header_offset)
|
||||||
zis.instance_variable_set(:@complete_entry, self)
|
zis.instance_variable_set(:@complete_entry, self)
|
||||||
zis.get_next_entry
|
zis.get_next_entry
|
||||||
if block
|
if block
|
||||||
|
|
|
@ -51,7 +51,7 @@ module Zip
|
||||||
#
|
#
|
||||||
# @param context [String||IO||StringIO] file path or IO/StringIO object
|
# @param context [String||IO||StringIO] file path or IO/StringIO object
|
||||||
# @param offset [Integer] offset in the IO/StringIO
|
# @param offset [Integer] offset in the IO/StringIO
|
||||||
def initialize(context, offset = 0, decrypter = nil)
|
def initialize(context, offset: 0, decrypter: nil)
|
||||||
super()
|
super()
|
||||||
@archive_io = get_io(context, offset)
|
@archive_io = get_io(context, offset)
|
||||||
@decompressor = ::Zip::NullDecompressor
|
@decompressor = ::Zip::NullDecompressor
|
||||||
|
@ -99,8 +99,8 @@ module Zip
|
||||||
# Same as #initialize but if a block is passed the opened
|
# Same as #initialize but if a block is passed the opened
|
||||||
# stream is passed to the block and closed when the block
|
# stream is passed to the block and closed when the block
|
||||||
# returns.
|
# returns.
|
||||||
def open(filename_or_io, offset = 0, decrypter = nil)
|
def open(filename_or_io, offset: 0, decrypter: nil)
|
||||||
zio = new(filename_or_io, offset, decrypter)
|
zio = new(filename_or_io, offset: offset, decrypter: decrypter)
|
||||||
return zio unless block_given?
|
return zio unless block_given?
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -110,9 +110,9 @@ module Zip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def open_buffer(filename_or_io, offset = 0)
|
def open_buffer(filename_or_io, offset: 0)
|
||||||
warn 'open_buffer is deprecated!!! Use open instead!'
|
warn 'open_buffer is deprecated!!! Use open instead!'
|
||||||
::Zip::InputStream.open(filename_or_io, offset)
|
::Zip::InputStream.open(filename_or_io, offset: offset)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,9 @@ class EncryptionTest < MiniTest::Test
|
||||||
out.write content
|
out.write content
|
||||||
end
|
end
|
||||||
|
|
||||||
Zip::InputStream.open(encrypted_zip, 0, Zip::TraditionalDecrypter.new(password)) do |zis|
|
Zip::InputStream.open(
|
||||||
|
encrypted_zip, decrypter: Zip::TraditionalDecrypter.new(password)
|
||||||
|
) do |zis|
|
||||||
entry = zis.get_next_entry
|
entry = zis.get_next_entry
|
||||||
assert_equal test_filename, entry.name
|
assert_equal test_filename, entry.name
|
||||||
assert_equal 1327, entry.size
|
assert_equal 1327, entry.size
|
||||||
|
@ -36,7 +38,10 @@ class EncryptionTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_raises(Zip::DecompressionError) do
|
assert_raises(Zip::DecompressionError) do
|
||||||
Zip::InputStream.open(encrypted_zip, 0, Zip::TraditionalDecrypter.new("#{password}wrong")) do |zis|
|
Zip::InputStream.open(
|
||||||
|
encrypted_zip,
|
||||||
|
decrypter: Zip::TraditionalDecrypter.new("#{password}wrong")
|
||||||
|
) do |zis|
|
||||||
zis.get_next_entry
|
zis.get_next_entry
|
||||||
assert_equal content, zis.read
|
assert_equal content, zis.read
|
||||||
end
|
end
|
||||||
|
@ -44,7 +49,10 @@ class EncryptionTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_decrypt
|
def test_decrypt
|
||||||
Zip::InputStream.open(ENCRYPT_ZIP_TEST_FILE, 0, Zip::TraditionalDecrypter.new('password')) do |zis|
|
Zip::InputStream.open(
|
||||||
|
ENCRYPT_ZIP_TEST_FILE,
|
||||||
|
decrypter: Zip::TraditionalDecrypter.new('password')
|
||||||
|
) do |zis|
|
||||||
entry = zis.get_next_entry
|
entry = zis.get_next_entry
|
||||||
assert_equal 'file1.txt', entry.name
|
assert_equal 'file1.txt', entry.name
|
||||||
assert_equal 1327, entry.size
|
assert_equal 1327, entry.size
|
||||||
|
|
|
@ -22,7 +22,9 @@ class StoredSupportTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_encrypted_read
|
def test_encrypted_read
|
||||||
Zip::InputStream.open(ENCRYPTED_STORED_ZIP_TEST_FILE, 0, Zip::TraditionalDecrypter.new('password')) do |zis|
|
Zip::InputStream.open(
|
||||||
|
ENCRYPTED_STORED_ZIP_TEST_FILE, decrypter: Zip::TraditionalDecrypter.new('password')
|
||||||
|
) do |zis|
|
||||||
entry = zis.get_next_entry
|
entry = zis.get_next_entry
|
||||||
assert_equal 'file1.txt', entry.name
|
assert_equal 'file1.txt', entry.name
|
||||||
assert_equal 1_327, entry.size
|
assert_equal 1_327, entry.size
|
||||||
|
|
Loading…
Reference in New Issue