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}"
|
||||
end
|
||||
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.get_next_entry
|
||||
if block
|
||||
|
|
|
@ -51,7 +51,7 @@ module Zip
|
|||
#
|
||||
# @param context [String||IO||StringIO] file path or IO/StringIO object
|
||||
# @param offset [Integer] offset in the IO/StringIO
|
||||
def initialize(context, offset = 0, decrypter = nil)
|
||||
def initialize(context, offset: 0, decrypter: nil)
|
||||
super()
|
||||
@archive_io = get_io(context, offset)
|
||||
@decompressor = ::Zip::NullDecompressor
|
||||
|
@ -99,8 +99,8 @@ module Zip
|
|||
# Same as #initialize but if a block is passed the opened
|
||||
# stream is passed to the block and closed when the block
|
||||
# returns.
|
||||
def open(filename_or_io, offset = 0, decrypter = nil)
|
||||
zio = new(filename_or_io, offset, decrypter)
|
||||
def open(filename_or_io, offset: 0, decrypter: nil)
|
||||
zio = new(filename_or_io, offset: offset, decrypter: decrypter)
|
||||
return zio unless block_given?
|
||||
|
||||
begin
|
||||
|
@ -110,9 +110,9 @@ module Zip
|
|||
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!'
|
||||
::Zip::InputStream.open(filename_or_io, offset)
|
||||
::Zip::InputStream.open(filename_or_io, offset: offset)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -28,7 +28,9 @@ class EncryptionTest < MiniTest::Test
|
|||
out.write content
|
||||
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
|
||||
assert_equal test_filename, entry.name
|
||||
assert_equal 1327, entry.size
|
||||
|
@ -36,7 +38,10 @@ class EncryptionTest < MiniTest::Test
|
|||
end
|
||||
|
||||
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
|
||||
assert_equal content, zis.read
|
||||
end
|
||||
|
@ -44,7 +49,10 @@ class EncryptionTest < MiniTest::Test
|
|||
end
|
||||
|
||||
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
|
||||
assert_equal 'file1.txt', entry.name
|
||||
assert_equal 1327, entry.size
|
||||
|
|
|
@ -22,7 +22,9 @@ class StoredSupportTest < MiniTest::Test
|
|||
end
|
||||
|
||||
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
|
||||
assert_equal 'file1.txt', entry.name
|
||||
assert_equal 1_327, entry.size
|
||||
|
|
Loading…
Reference in New Issue