Adjust Layout/LineLength cop to 100 characters.
We'll get the line length down in stages...
This commit is contained in:
parent
de6ec15610
commit
193507b15a
|
@ -22,7 +22,7 @@ Layout/HashAlignment:
|
|||
# Set a workable line length, given the current state of the code,
|
||||
# and turn off for the tests.
|
||||
Layout/LineLength:
|
||||
Max: 135
|
||||
Max: 100
|
||||
Exclude:
|
||||
- 'test/**/*.rb'
|
||||
|
||||
|
|
|
@ -30,7 +30,8 @@ module Zip
|
|||
eocd_offset = io.tell
|
||||
cdir_size = eocd_offset - cdir_offset
|
||||
if ::Zip.write_zip64_support
|
||||
need_zip64_eocd = cdir_offset > 0xFFFFFFFF || cdir_size > 0xFFFFFFFF || @entry_set.size > 0xFFFF
|
||||
need_zip64_eocd = cdir_offset > 0xFFFFFFFF || cdir_size > 0xFFFFFFFF \
|
||||
|| @entry_set.size > 0xFFFF
|
||||
need_zip64_eocd ||= @entry_set.any? { |entry| entry.extra['Zip64'] }
|
||||
if need_zip64_eocd
|
||||
write_64_e_o_c_d(io, cdir_offset, cdir_size)
|
||||
|
|
|
@ -195,7 +195,10 @@ module Zip
|
|||
return if @local_header_size.nil?
|
||||
|
||||
new_size = calculate_local_header_size
|
||||
raise Error, "local header size changed (#{@local_header_size} -> #{new_size})" if @local_header_size != new_size
|
||||
return unless @local_header_size != new_size
|
||||
|
||||
raise Error,
|
||||
"Local header size changed (#{@local_header_size} -> #{new_size})"
|
||||
end
|
||||
|
||||
def cdir_header_size #:nodoc:all
|
||||
|
@ -363,8 +366,9 @@ module Zip
|
|||
when ::Zip::FILE_TYPE_SYMLINK
|
||||
:symlink
|
||||
else
|
||||
# best case guess for whether it is a file or not
|
||||
# Otherwise this would be set to unknown and that entry would never be able to extracted
|
||||
# Best case guess for whether it is a file or not.
|
||||
# Otherwise this would be set to unknown and that
|
||||
# entry would never be able to be extracted.
|
||||
if name_is_directory?
|
||||
:directory
|
||||
else
|
||||
|
@ -444,13 +448,18 @@ module Zip
|
|||
@unix_perms = stat.mode & 0o7777
|
||||
end
|
||||
|
||||
# rubocop:disable Style/GuardClause
|
||||
def set_unix_attributes_on_path(dest_path)
|
||||
# ignore setuid/setgid bits by default. honor if @restore_ownership
|
||||
unix_perms_mask = 0o1777
|
||||
unix_perms_mask = 0o7777 if @restore_ownership
|
||||
::FileUtils.chmod(@unix_perms & unix_perms_mask, dest_path) if @restore_permissions && @unix_perms
|
||||
::FileUtils.chown(@unix_uid, @unix_gid, dest_path) if @restore_ownership && @unix_uid && @unix_gid && ::Process.egid == 0
|
||||
# Ignore setuid/setgid bits by default. Honour if @restore_ownership.
|
||||
unix_perms_mask = (@restore_ownership ? 0o7777 : 0o1777)
|
||||
if @restore_permissions && @unix_perms
|
||||
::FileUtils.chmod(@unix_perms & unix_perms_mask, dest_path)
|
||||
end
|
||||
if @restore_ownership && @unix_uid && @unix_gid && ::Process.egid == 0
|
||||
::FileUtils.chown(@unix_uid, @unix_gid, dest_path)
|
||||
end
|
||||
end
|
||||
# rubocop:enable Style/GuardClause
|
||||
|
||||
def set_extra_attributes_on_path(dest_path) # :nodoc:
|
||||
return unless file? || directory?
|
||||
|
@ -693,7 +702,9 @@ module Zip
|
|||
if for_local_header
|
||||
@size, @compressed_size = @extra['Zip64'].parse(@size, @compressed_size)
|
||||
else
|
||||
@size, @compressed_size, @local_header_offset = @extra['Zip64'].parse(@size, @compressed_size, @local_header_offset)
|
||||
@size, @compressed_size, @local_header_offset = @extra['Zip64'].parse(
|
||||
@size, @compressed_size, @local_header_offset
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -40,7 +40,9 @@ module Zip
|
|||
def parse(original_size, compressed_size, relative_header_offset = nil, disk_start_number = nil)
|
||||
@original_size = extract(8, 'Q<') if original_size == 0xFFFFFFFF
|
||||
@compressed_size = extract(8, 'Q<') if compressed_size == 0xFFFFFFFF
|
||||
@relative_header_offset = extract(8, 'Q<') if relative_header_offset && relative_header_offset == 0xFFFFFFFF
|
||||
if relative_header_offset && relative_header_offset == 0xFFFFFFFF
|
||||
@relative_header_offset = extract(8, 'Q<')
|
||||
end
|
||||
@disk_start_number = extract(4, 'V') if disk_start_number && disk_start_number == 0xFFFF
|
||||
@content = nil
|
||||
[@original_size || original_size,
|
||||
|
@ -55,7 +57,8 @@ module Zip
|
|||
private :extract
|
||||
|
||||
def pack_for_local
|
||||
# local header entries must contain original size and compressed size; other fields do not apply
|
||||
# Local header entries must contain original size and compressed size;
|
||||
# other fields do not apply.
|
||||
return '' unless @original_size && @compressed_size
|
||||
|
||||
[@original_size, @compressed_size].pack('Q<Q<')
|
||||
|
|
|
@ -140,7 +140,8 @@ module Zip
|
|||
# downloaded zip archive without first saving it to disk.)
|
||||
def open_buffer(io, options = {})
|
||||
unless IO_METHODS.map { |method| io.respond_to?(method) }.all? || io.kind_of?(String)
|
||||
raise "Zip::File.open_buffer expects a String or IO-like argument (responds to #{IO_METHODS.join(', ')}). Found: #{io.class}"
|
||||
raise 'Zip::File.open_buffer expects a String or IO-like argument' \
|
||||
"(responds to #{IO_METHODS.join(', ')}). Found: #{io.class}"
|
||||
end
|
||||
|
||||
io = ::StringIO.new(io) if io.kind_of?(::String)
|
||||
|
|
|
@ -41,7 +41,10 @@ module Zip
|
|||
#
|
||||
# TODO: Make the code more understandable
|
||||
#
|
||||
def save_splited_part(zip_file, partial_zip_file_name, zip_file_size, szip_file_index, segment_size, segment_count)
|
||||
def save_splited_part(
|
||||
zip_file, partial_zip_file_name, zip_file_size,
|
||||
szip_file_index, segment_size, segment_count
|
||||
)
|
||||
ssegment_size = zip_file_size - zip_file.pos
|
||||
ssegment_size = segment_size if ssegment_size > segment_size
|
||||
szip_file_name = "#{partial_zip_file_name}.#{format('%03d', szip_file_index)}"
|
||||
|
@ -52,7 +55,7 @@ module Zip
|
|||
chunk_bytes = 0
|
||||
until ssegment_size == chunk_bytes || zip_file.eof?
|
||||
segment_bytes_left = ssegment_size - chunk_bytes
|
||||
buffer_size = segment_bytes_left < DATA_BUFFER_SIZE ? segment_bytes_left : DATA_BUFFER_SIZE
|
||||
buffer_size = [segment_bytes_left, DATA_BUFFER_SIZE].min
|
||||
chunk = zip_file.read(buffer_size)
|
||||
chunk_bytes += buffer_size
|
||||
szip_file << chunk
|
||||
|
@ -63,7 +66,10 @@ module Zip
|
|||
end
|
||||
|
||||
# Splits an archive into parts with segment size
|
||||
def split(zip_file_name, segment_size = MAX_SEGMENT_SIZE, delete_zip_file = true, partial_zip_file_name = nil)
|
||||
def split(
|
||||
zip_file_name, segment_size = MAX_SEGMENT_SIZE,
|
||||
delete_zip_file = true, partial_zip_file_name = nil
|
||||
)
|
||||
raise Error, "File #{zip_file_name} not found" unless ::File.exist?(zip_file_name)
|
||||
raise Errno::ENOENT, zip_file_name unless ::File.readable?(zip_file_name)
|
||||
|
||||
|
@ -78,7 +84,10 @@ module Zip
|
|||
::File.open(zip_file_name, 'rb') do |zip_file|
|
||||
until zip_file.eof?
|
||||
szip_file_index += 1
|
||||
save_splited_part(zip_file, partial_zip_file_name, zip_file_size, szip_file_index, segment_size, segment_count)
|
||||
save_splited_part(
|
||||
zip_file, partial_zip_file_name, zip_file_size,
|
||||
szip_file_index, segment_size, segment_count
|
||||
)
|
||||
end
|
||||
end
|
||||
::File.delete(zip_file_name) if delete_zip_file
|
||||
|
|
|
@ -134,7 +134,10 @@ module Zip
|
|||
@current_entry = ::Zip::Entry.read_local_entry(@archive_io)
|
||||
return if @current_entry.nil?
|
||||
|
||||
raise Error, 'A password is required to decode this zip file' if @current_entry.encrypted? && @decrypter.kind_of?(NullEncrypter)
|
||||
if @current_entry.encrypted? && @decrypter.kind_of?(NullEncrypter)
|
||||
raise Error,
|
||||
'A password is required to decode this zip file'
|
||||
end
|
||||
|
||||
if @current_entry.incomplete? && @current_entry.compressed_size == 0 \
|
||||
&& !@complete_entry
|
||||
|
@ -161,13 +164,16 @@ module Zip
|
|||
return ::Zip::NullDecompressor if @current_entry.nil?
|
||||
|
||||
decompressed_size =
|
||||
if @current_entry.incomplete? && @current_entry.crc == 0 && @current_entry.size == 0 && @complete_entry
|
||||
if @current_entry.incomplete? && @current_entry.crc == 0 \
|
||||
&& @current_entry.size == 0 && @complete_entry
|
||||
@complete_entry.size
|
||||
else
|
||||
@current_entry.size
|
||||
end
|
||||
|
||||
decompressor_class = ::Zip::Decompressor.find_by_compression_method(@current_entry.compression_method)
|
||||
decompressor_class = ::Zip::Decompressor.find_by_compression_method(
|
||||
@current_entry.compression_method
|
||||
)
|
||||
if decompressor_class.nil?
|
||||
raise ::Zip::CompressionMethodError,
|
||||
"Unsupported compression method #{@current_entry.compression_method}"
|
||||
|
|
|
@ -84,7 +84,10 @@ module Zip
|
|||
@output_buffer << produce_input
|
||||
over_limit = (number_of_bytes && @output_buffer.bytesize >= number_of_bytes)
|
||||
end
|
||||
sep_index = [match_index + a_sep_string.bytesize, number_of_bytes || @output_buffer.bytesize].min
|
||||
sep_index = [
|
||||
match_index + a_sep_string.bytesize,
|
||||
number_of_bytes || @output_buffer.bytesize
|
||||
].min
|
||||
@pos += sep_index
|
||||
@output_buffer.slice!(0...sep_index)
|
||||
end
|
||||
|
|
|
@ -142,7 +142,11 @@ module Zip
|
|||
@current_entry.calculate_local_header_size
|
||||
@current_entry.size = @compressor.size
|
||||
@current_entry.crc = @compressor.crc
|
||||
@output_stream << @encrypter.data_descriptor(@current_entry.crc, @current_entry.compressed_size, @current_entry.size)
|
||||
@output_stream << @encrypter.data_descriptor(
|
||||
@current_entry.crc,
|
||||
@current_entry.compressed_size,
|
||||
@current_entry.size
|
||||
)
|
||||
@current_entry.gp_flags |= @encrypter.gp_flags
|
||||
@current_entry = nil
|
||||
@compressor = ::Zip::NullCompressor.instance
|
||||
|
|
|
@ -21,7 +21,8 @@ end
|
|||
|
||||
zf = Zip::File.new('example.zip')
|
||||
zf.each_with_index do |entry, index|
|
||||
puts "entry #{index} is #{entry.name}, size = #{entry.size}, compressed size = #{entry.compressed_size}"
|
||||
puts "entry #{index} is #{entry.name}, size = #{entry.size}, " \
|
||||
"compressed size = #{entry.compressed_size}"
|
||||
# use zf.get_input_stream(entry) to get a ZipInputStream for the entry
|
||||
# entry can be the ZipEntry object or any object which has a to_s method that
|
||||
# returns the name of the entry.
|
||||
|
@ -71,8 +72,11 @@ part_zips_count = Zip::File.split('large_zip_file.zip', 2_097_152, false)
|
|||
puts "Zip file splitted in #{part_zips_count} parts"
|
||||
|
||||
# Track splitting an archive
|
||||
Zip::File.split('large_zip_file.zip', 1_048_576, true, 'part_zip_file') do |part_count, part_index, chunk_bytes, segment_bytes|
|
||||
puts "#{part_index} of #{part_count} part splitting: #{(chunk_bytes.to_f / segment_bytes * 100).to_i}%"
|
||||
Zip::File.split(
|
||||
'large_zip_file.zip', 1_048_576, true, 'part_zip_file'
|
||||
) do |part_count, part_index, chunk_bytes, segment_bytes|
|
||||
puts "#{part_index} of #{part_count} part splitting: " \
|
||||
"#{(chunk_bytes.to_f / segment_bytes * 100).to_i}%"
|
||||
end
|
||||
|
||||
# For other examples, look at zip.rb and ziptest.rb
|
||||
|
|
Loading…
Reference in New Issue