8000 Apply automatic corrections by rubocop · rubyzip/rubyzip@26767e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 26767e9

Browse files
committed
Apply automatic corrections by rubocop
1 parent d80e720 commit 26767e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+206
-216
lines changed

lib/zip/central_directory.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def read_64_e_o_c_d(buf) #:nodoc:
9696
@size_in_bytes = Entry.read_zip_64_long(buf)
9797
@cdir_offset = Entry.read_zip_64_long(buf)
9898
@zip_64_extensible = buf.slice!(0, buf.bytesize)
99-
raise Error, 'Zip consistency problem while reading eocd structure' unless buf.size == 0
99+
raise Error, 'Zip consistency problem while reading eocd structure' unless buf.empty?
100100
end
101101

102102
def read_e_o_c_d(buf) #:nodoc:
@@ -113,7 +113,7 @@ def read_e_o_c_d(buf) #:nodoc:
113113
else
114114
buf.read(comment_length)
115115
end
116-
raise Error, 'Zip consistency problem while reading eocd structure' unless buf.size == 0
116+
raise Error, 'Zip consistency problem while reading eocd structure' unless buf.empty?
117117
end
118118

119119
def read_central_directory_entries(io) #:nodoc:
@@ -130,7 +130,7 @@ def read_central_directory_entries(io) #:nodoc:
130130

131131
def read_from_stream(io) #:nodoc:
132132
buf = start_buf(io)
133-
if self.zip64_file?(buf)
133+
if zip64_file?(buf)
134134
read_64_e_o_c_d(buf)
135135
else
136136
read_e_o_c_d(buf)

lib/zip/compressor.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Zip
22
class Compressor #:nodoc:all
3-
def finish
4-
end
3+
def finish; end
54
end
65
end
76

lib/zip/constants.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ module Zip
1111
VERSION_NEEDED_TO_EXTRACT = 20
1212
VERSION_NEEDED_TO_EXTRACT_ZIP64 = 45
1313

14-
FILE_TYPE_FILE = 010
15-
FILE_TYPE_DIR = 004
16-
FILE_TYPE_SYMLINK = 012
14+
FILE_TYPE_FILE = 0o10
15+
FILE_TYPE_DIR = 0o04
16+
FILE_TYPE_SYMLINK = 0o12
1717

1818
FSTYPE_FAT = 0
1919
FSTYPE_AMIGA = 1

lib/zip/crypto/null_encryption.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ def data_descriptor(_crc32, _compressed_size, _uncomprssed_size)
2424
''
2525
end
2626

27-
def reset!
28-
end
27+
def reset!; end
2928
end
3029

3130
class NullDecrypter < Decrypter
@@ -35,8 +34,7 @@ def decrypt(data)
3534
data
3635
end
3736

38-
def reset!(_header)
39-
end
37+
def reset!(_header); end
4038
end
4139
end
4240

lib/zip/decompressor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Zip
2-
class Decompressor #:nodoc:all
2+
class Decompressor #:nodoc:all
33
CHUNK_SIZE = 32_768
44
def initialize(input_stream)
55
super()

lib/zip/dos_time.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def to_binary_dos_time
1919
end
2020

2121
def to_binary_dos_date
22-
(day) +
22+
day +
2323
(month << 5) +
2424
((year - 1980) << 9)
2525
end

lib/zip/entry.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def file_type_is?(type)
9999
end
100100

101101
# Dynamic checkers
102-
%w(directory file symlink).each do |k|
102+
%w[directory file symlink].each do |k|
103103
define_method "#{k}?" do
104104
file_type_is?(k.to_sym)
105105
end
@@ -239,7 +239,7 @@ def read_local_entry(io) #:nodoc:all
239239
@name = io.read(@name_length)
240240
extra = io.read(@extra_length)
241241

242-
@name.gsub!('\\', '/')
242+
@name.tr!('\\', '/')
243243

244244
if extra && extra.bytesize != @extra_length
245245
raise ::Zip::Error, 'Truncated local zip entry header'
@@ -263,8 +263,8 @@ def pack_local_entry
263263
@time.to_binary_dos_time, # @last_mod_time ,
264264
@time.to_binary_dos_date, # @last_mod_date ,
265265
@crc,
266-
(zip64 && zip64.compressed_size) ? 0xFFFFFFFF : @compressed_size,
267-
(zip64 && zip64.original_size) ? 0xFFFFFFFF : @size,
266+
zip64 && zip64.compressed_size ? 0xFFFFFFFF : @compressed_size,
267+
zip64 && zip64.original_size ? 0xFFFFFFFF : @size,
268268
name_size,
269269
@extra ? @extra.local_size : 0].pack('VvvvvvVVVvv')
270270
end
@@ -308,7 +308,7 @@ def unpack_c_dir_entry(buf)
308308
def set_ftype_from_c_dir_entry
309309
@ftype = case @fstype
310310
when ::Zip::FSTYPE_UNIX
311-
@unix_perms = (@external_file_attributes >> 16) & 07777
311+
@unix_perms = (@external_file_attributes >> 16) & 0o7777
312312
case (@external_file_attributes >> 28)
313313
when ::Zip::FILE_TYPE_DIR
314314
:directory
@@ -384,14 +384,14 @@ def get_extra_attributes_from_path(path) # :nodoc:
384384
stat = file_stat(path)
385385
@unix_uid = stat.uid
386386
@unix_gid = stat.gid
387-
@unix_perms = stat.mode & 07777
387+
@unix_perms = stat.mode & 0o7777
388388
end
389389

390390
def set_unix_permissions_on_path(dest_path)
391391
# BUG: does not update timestamps into account
392392
# ignore setuid/setgid bits by default. honor if @restore_ownership
393-
unix_perms_mask = 01777
394-
unix_perms_mask = 07777 if @restore_ownership
393+
unix_perms_mask = 0o1777
394+
unix_perms_mask = 0o7777 if @restore_ownership
395395
::FileUtils.chmod(@unix_perms & unix_perms_mask, dest_path) if @restore_permissions && @unix_perms
396396
::FileUtils.chown(@unix_uid, @unix_gid, dest_path) if @restore_ownership && @unix_uid && @unix_gid && ::Process.egid == 0
397397
# File::utimes()
@@ -418,15 +418,15 @@ def pack_c_dir_entry
418418
@time.to_binary_dos_time, # @last_mod_time ,
419419
@time.to_binary_dos_date, # @last_mod_date ,
420420
@crc,
421-
(zip64 && zip64.compressed_size) ? 0xFFFFFFFF : @compressed_size,
422-
(zip64 && zip64.original_size) ? 0xFFFFFFFF : @size,
421+
zip64 && zip64.compressed_size ? 0xFFFFFFFF : @compressed_size,
422+
zip64 && zip64.original_size ? 0xFFFFFFFF : @size,
423423
name_size,
424424
@extra ? @extra.c_dir_size : 0,
425425
comment_size,
426-
(zip64 && zip64.disk_start_number) ? 0xFFFF : 0, # disk number start
426+
zip64 && zip64.disk_start_number ? 0xFFFF : 0, # disk number start
427427
@internal_file_attributes, # file type (binary=0, text=1)
428428
@external_file_attributes, # native filesystem attributes
429-
(zip64 && zip64.relative_header_offset) ? 0xFFFFFFFF : @local_header_offset,
429+
zip64 && zip64.relative_header_offset ? 0xFFFFFFFF : @local_header_offset,
430430
@name,
431431
@extra,
432432
@comment
@@ -439,18 +439,18 @@ def write_c_dir_entry(io) #:nodoc:all
439439
when ::Zip::FSTYPE_UNIX
440440
ft = case @ftype
441441
when :file
442-
@unix_perms ||= 0644
442+
@unix_perms ||= 0o644
443443
::Zip::FILE_TYPE_FILE
444444
when :directory
445-
@unix_perms ||= 0755
445+
@unix_perms ||= 0o755
446446
::Zip::FILE_TYPE_DIR
447447
when :symlink
448-
@unix_perms ||= 0755
448+
@unix_perms ||= 0o755
449449
::Zip::FILE_TYPE_SYMLINK
450450
end
451451

452452
unless ft.nil?
453-
@external_file_attributes = (ft << 12 | (@unix_perms & 07777)) << 16
453+
@external_file_attributes = (ft << 12 | (@unix_perms & 0o7777)) << 16
454454
end
455455
end
456456

@@ -464,7 +464,7 @@ def write_c_dir_entry(io) #:nodoc:all
464464
def ==(other)
465465
return false unless other.class == self.class
466466
# Compares contents of local entry and exposed fields
467-
keys_equal = %w(compression_method crc compressed_size size name extra filepath).all? do |k|
467+
keys_equal = %w[compression_method crc compressed_size size name extra filepath].all? do |k|
468468
other.__send__(k.to_sym) == __send__(k.to_sym)
469469
end
470470
keys_equal && time.dos_equals(other.time)

lib/zip/entry_set.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class EntrySet #:nodoc:all
55

66
def initialize(an_enumerable = [])
77
super()
8-
@entry_set = {}
8+
@entry_set = {}
99
an_enumerable.each { |o| push(o) }
1010
end
1111

@@ -33,9 +33,9 @@ def delete(entry)
3333
entry if @entry_set.delete(to_key(entry))
3434
end
3535

36-
def each(&block)
36+
def each
3737
@entry_set = sorted_entries.dup.each do |_, value|
38-
block.call(value)
38+
yield(value)
3939
end
4040
end
4141

lib/zip/extra_field.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module Zip
22
class ExtraField < Hash
3-
ID_MAP = {}
3+
ID_MAP = {}.freeze
44

55
def initialize(binstr = nil)
66
merge(binstr) if binstr
77
end
88

99
def extra_field_type_exist(binstr, id, len, i)
1010
field_name = ID_MAP[id].name
11-
if self.member?(field_name)
11+
if member?(field_name)
1212
self[field_name].merge(binstr[i, len + 4])
1313
else
1414
field_obj = ID_MAP[id].new(binstr[i, len + 4])

lib/zip/extra_field/generic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Zip
22
class ExtraField::Generic
33
def self.register_map
4-
if self.const_defined?(:HEADER_ID)
4+
if const_defined?(:HEADER_ID)
55
::Zip::ExtraField::ID_MAP[const_get(:HEADER_ID)] = self
66
end
77
end

lib/zip/extra_field/old_unix.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Zip
22
# Olf Info-ZIP Extra for UNIX uid/gid and file timestampes
33
class ExtraField::OldUnix < ExtraField::Generic
4-
HEADER_ID = 'UX'
4+
HEADER_ID = 'UX'.freeze
55
register_map
66

77
def initialize(binstr = nil)

lib/zip/extra_field/universal_time.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Zip
22
# Info-ZIP Additional timestamp field
33
class ExtraField::UniversalTime < ExtraField::Generic
4-
HEADER_ID = 'UT'
4+
HEADER_ID = 'UT'.freeze
55
register_map
66

77
def initialize(binstr = nil)

lib/zip/extra_field/unix.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Zip
22
# Info-ZIP Extra for UNIX uid/gid
33
class ExtraField::IUnix < ExtraField::Generic
4-
HEADER_ID = 'Ux'
4+
HEADER_ID = 'Ux'.freeze
55
register_map
66

77
def initialize(binstr = nil)

lib/zip/extra_field/zip64_placeholder.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ class ExtraField::Zip64Placeholder < ExtraField::Generic
66
HEADER_ID = ['9999'].pack('H*') # this ID is used by other libraries such as .NET's Ionic.zip
77
register_map
88

9-
def initialize(_binstr = nil)
10-
end
9+
def initialize(_binstr = nil); end
1110

1211
def pack_for_local
1312
"\x00" * 16

lib/zip/file.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class File < CentralDirectory
4949
MAX_SEGMENT_SIZE = 3_221_225_472
5050
MIN_SEGMENT_SIZE = 65_536
5151
DATA_BUFFER_SIZE = 8192
52-
IO_METHODS = [:tell, :seek, :read, :close]
52+
IO_METHODS = [:tell, :seek, :read, :close].freeze
5353

5454
attr_reader :name
5555

@@ -69,16 +69,15 @@ def initialize(file_name, create = false, buffer = false, options = {})
6969
@name = file_name
7070
@comment = ''
7171
@create = create ? true : false # allow any truthy value to mean true
72-
case
73-
when !buffer && ::File.size?(file_name)
72+
if !buffer && ::File.size?(file_name)
7473
@create = false
7574
@file_permissions = ::File.stat(file_name).mode
7675
::File.open(name, 'rb') do |f|
7776
read_from_stream(f)
7877
end
79-
when @create
78+
elsif @create
8079
@entry_set = EntrySet.new
81-
when ::File.zero?(file_name)
80+
elsif ::File.zero?(file_name)
8281
raise Error, "File #{file_name} has zero size. Did you mean to pass the create flag?"
8382
else
8483
raise Error, "File #{file_name} not found"
@@ -151,19 +150,20 @@ def foreach(aZipFileName, &block)
151150
end
152151

153152
def get_segment_size_for_split(segment_size)
154-
case
155-
when MIN_SEGMENT_SIZE > segment_size
153+
if MIN_SEGMENT_SIZE > segment_size
156154
MIN_SEGMENT_SIZE
157-
when MAX_SEGMENT_SIZE < segment_size
155+
elsif MAX_SEGMENT_SIZE < segment_size
158156
MAX_SEGMENT_SIZE
159157
else
160158
segment_size
161159
end
162160
end
163161

164162
def get_partial_zip_file_name(zip_file_name, partial_zip_file_name)
165-
partial_zip_file_name = zip_file_name.sub(/#{::File.basename(zip_file_name)}\z/,
166-
partial_zip_file_name + ::File.extname(zip_file_name)) unless partial_zip_file_name.nil?
163+
unless partial_zip_file_name.nil?
164+
partial_zip_file_name = zip_file_name.sub(/#{::File.basename(zip_file_name)}\z/,
165+
partial_zip_file_name + ::File.extname(zip_file_name))
166+
end
167167
partial_zip_file_name ||= zip_file_name
168168
partial_zip_file_name
169169
end
@@ -237,7 +237,7 @@ def get_input_stream(entry, &aProc)
237237
# specified. If a block is passed the stream object is passed to the block and
238238
# the stream is automatically closed afterwards just as with ruby's builtin
239239
# File.open method.
240-
def get_output_stream(entry, permission_int = nil, comment = nil, extra = nil, compressed_size = nil, crc = nil, compression_method = nil, size = nil, time = nil, &aProc)
240+
def get_output_stream(entry, permission_int = nil, comment = nil, extra = nil, compressed_size = nil, crc = nil, compression_method = nil, size = nil, time = nil, &aProc)
241241
new_entry =
242242
if entry.kind_of?(Entry)
243243
entry
@@ -366,7 +366,7 @@ def get_entry(entry)
366366
end
367367

368368
# Creates a directory
369-
def mkdir(entryName, permissionInt = 0755)
369+
def mkdir(entryName, permissionInt = 0o755)
370370
raise Errno::EEXIST, "File exists - #{entryName}" if find_entry(entryName)
371371
entryName = entryName.dup.to_s
372372
entryName << '/' unless entryName.end_with?('/')

0 commit comments

Comments
 (0)
0