fix rubocop Style/NumericLiterals cop

This commit is contained in:
Pavel Lobashov 2015-03-23 19:23:04 +03:00
parent 77b7d6c35d
commit 1ba81ff46f
17 changed files with 40 additions and 45 deletions

View File

@ -198,11 +198,6 @@ Style/NonNilCheck:
Style/Not: Style/Not:
Enabled: false Enabled: false
# Offense count: 43
# Cop supports --auto-correct.
Style/NumericLiterals:
MinDigits: 12
# Offense count: 3 # Offense count: 3
# Configuration parameters: MaxSlashes. # Configuration parameters: MaxSlashes.
Style/RegexpLiteral: Style/RegexpLiteral:

View File

@ -5,7 +5,7 @@ module Zip
END_OF_CDS = 0x06054b50 END_OF_CDS = 0x06054b50
ZIP64_END_OF_CDS = 0x06064b50 ZIP64_END_OF_CDS = 0x06064b50
ZIP64_EOCD_LOCATOR = 0x07064b50 ZIP64_EOCD_LOCATOR = 0x07064b50
MAX_END_OF_CDS_SIZE = 65536 + 18 MAX_END_OF_CDS_SIZE = 65_536 + 18
STATIC_EOCD_SIZE = 22 STATIC_EOCD_SIZE = 22
attr_reader :comment attr_reader :comment

View File

@ -26,7 +26,7 @@ module Zip
def update_keys(n) def update_keys(n)
@key0 = ~Zlib.crc32(n, ~@key0) @key0 = ~Zlib.crc32(n, ~@key0)
@key1 = ((@key1 + (@key0 & 0xff)) * 134775813 + 1) & 0xffffffff @key1 = ((@key1 + (@key0 & 0xff)) * 134_775_813 + 1) & 0xffffffff
@key2 = ~Zlib.crc32((@key1 >> 24).chr, ~@key2) @key2 = ~Zlib.crc32((@key1 >> 24).chr, ~@key2)
end end

View File

@ -1,6 +1,6 @@
module Zip module Zip
class Decompressor #:nodoc:all class Decompressor #:nodoc:all
CHUNK_SIZE = 32768 CHUNK_SIZE = 32_768
def initialize(input_stream) def initialize(input_stream)
super() super()
@input_stream = input_stream @input_stream = input_stream

View File

@ -5,8 +5,8 @@ module Zip
HEADER_ID = [0x000A].pack('v') HEADER_ID = [0x000A].pack('v')
register_map register_map
WINDOWS_TICK = 10000000.0 WINDOWS_TICK = 10_000_000.0
SEC_TO_UNIX_EPOCH = 11644473600 SEC_TO_UNIX_EPOCH = 11_644_473_600
def initialize(binstr = nil) def initialize(binstr = nil)
@ctime = nil @ctime = nil

View File

@ -46,8 +46,8 @@ module Zip
CREATE = 1 CREATE = 1
SPLIT_SIGNATURE = 0x08074b50 SPLIT_SIGNATURE = 0x08074b50
ZIP64_EOCD_SIGNATURE = 0x06064b50 ZIP64_EOCD_SIGNATURE = 0x06064b50
MAX_SEGMENT_SIZE = 3221225472 MAX_SEGMENT_SIZE = 3_221_225_472
MIN_SEGMENT_SIZE = 65536 MIN_SEGMENT_SIZE = 65_536
DATA_BUFFER_SIZE = 8192 DATA_BUFFER_SIZE = 8192
attr_reader :name attr_reader :name

View File

@ -163,7 +163,7 @@ module Zip
if e.fstype == 3 if e.fstype == 3
e.external_file_attributes >> 16 e.external_file_attributes >> 16
else else
33206 # 33206 is equivalent to -rw-rw-rw- 33_206 # 33206 is equivalent to -rw-rw-rw-
end end
end end
end end

View File

@ -1,6 +1,6 @@
module Zip module Zip
module IOExtras #:nodoc: module IOExtras #:nodoc:
CHUNK_SIZE = 131072 CHUNK_SIZE = 131_072
RANGE_ALL = 0..-1 RANGE_ALL = 0..-1

View File

@ -61,16 +61,16 @@ Zip::OutputStream.open('large_zip_file.zip') do |zos|
puts 'Creating zip file...' puts 'Creating zip file...'
10.times do |i| 10.times do |i|
zos.put_next_entry("large_entry_#{i}.txt") zos.put_next_entry("large_entry_#{i}.txt")
zos.puts 'Hello' * 104857600 zos.puts 'Hello' * 104_857_600
end end
end end
# Splitting created large zip file # Splitting created large zip file
part_zips_count = Zip::File.split('large_zip_file.zip', 2097152, false) part_zips_count = Zip::File.split('large_zip_file.zip', 2_097_152, false)
puts "Zip file splitted in #{part_zips_count} parts" puts "Zip file splitted in #{part_zips_count} parts"
# Track splitting an archive # Track splitting an archive
Zip::File.split('large_zip_file.zip', 1048576, true, 'part_zip_file') do |part_count, part_index, chunk_bytes, segment_bytes| 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.to_f * 100).to_i}%" puts "#{part_index} of #{part_count} part splitting: #{(chunk_bytes.to_f / segment_bytes.to_f * 100).to_i}%"
end end

View File

@ -7,7 +7,7 @@ class ZipCentralDirectoryEntryTest < MiniTest::Test
assert_equal('longAscii.txt', entry.name) assert_equal('longAscii.txt', entry.name)
assert_equal(::Zip::Entry::DEFLATED, entry.compression_method) assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
assert_equal(106490, entry.size) assert_equal(106_490, entry.size)
assert_equal(3784, entry.compressed_size) assert_equal(3784, entry.compressed_size)
assert_equal(0xfcd1799c, entry.crc) assert_equal(0xfcd1799c, entry.crc)
assert_equal('', entry.comment) assert_equal('', entry.comment)
@ -31,8 +31,8 @@ class ZipCentralDirectoryEntryTest < MiniTest::Test
entry = ::Zip::Entry.read_c_dir_entry(file) entry = ::Zip::Entry.read_c_dir_entry(file)
assert_equal('longBinary.bin', entry.name) assert_equal('longBinary.bin', entry.name)
assert_equal(::Zip::Entry::DEFLATED, entry.compression_method) assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
assert_equal(1000024, entry.size) assert_equal(1_000_024, entry.size)
assert_equal(70847, entry.compressed_size) assert_equal(70_847, entry.compressed_size)
assert_equal(0x10da7d59, entry.crc) assert_equal(0x10da7d59, entry.crc)
assert_equal('', entry.comment) assert_equal('', entry.comment)

View File

@ -52,10 +52,10 @@ class ZipCentralDirectoryTest < MiniTest::Test
def test_write64_to_stream def test_write64_to_stream
::Zip.write_zip64_support = true ::Zip.write_zip64_support = true
entries = [::Zip::Entry.new('file.zip', 'file1-little', 'comment1', '', 200, 101, ::Zip::Entry::STORED, 200), entries = [::Zip::Entry.new('file.zip', 'file1-little', 'comment1', '', 200, 101, ::Zip::Entry::STORED, 200),
::Zip::Entry.new('file.zip', 'file2-big', 'comment2', '', 18000000000, 102, ::Zip::Entry::DEFLATED, 20000000000), ::Zip::Entry.new('file.zip', 'file2-big', 'comment2', '', 18_000_000_000, 102, ::Zip::Entry::DEFLATED, 20_000_000_000),
::Zip::Entry.new('file.zip', 'file3-alsobig', 'comment3', '', 15000000000, 103, ::Zip::Entry::DEFLATED, 21000000000), ::Zip::Entry.new('file.zip', 'file3-alsobig', 'comment3', '', 15_000_000_000, 103, ::Zip::Entry::DEFLATED, 21_000_000_000),
::Zip::Entry.new('file.zip', 'file4-little', 'comment4', '', 100, 104, ::Zip::Entry::DEFLATED, 121)] ::Zip::Entry.new('file.zip', 'file4-little', 'comment4', '', 100, 104, ::Zip::Entry::DEFLATED, 121)]
[0, 250, 18000000300, 33000000350].each_with_index do |offset, index| [0, 250, 18_000_000_300, 33_000_000_350].each_with_index do |offset, index|
entries[index].local_header_offset = offset entries[index].local_header_offset = offset
end end
cdir = ::Zip::CentralDirectory.new(entries, 'zip comment') cdir = ::Zip::CentralDirectory.new(entries, 'zip comment')

View File

@ -4,7 +4,7 @@ class ZipEntryTest < MiniTest::Test
TEST_ZIPFILE = 'someZipFile.zip' TEST_ZIPFILE = 'someZipFile.zip'
TEST_COMMENT = 'a comment' TEST_COMMENT = 'a comment'
TEST_COMPRESSED_SIZE = 1234 TEST_COMPRESSED_SIZE = 1234
TEST_CRC = 325324 TEST_CRC = 325_324
TEST_EXTRA = 'Some data here' TEST_EXTRA = 'Some data here'
TEST_COMPRESSIONMETHOD = ::Zip::Entry::DEFLATED TEST_COMPRESSIONMETHOD = ::Zip::Entry::DEFLATED
TEST_NAME = 'entry name' TEST_NAME = 'entry name'
@ -50,28 +50,28 @@ class ZipEntryTest < MiniTest::Test
def test_equality def test_equality
entry1 = ::Zip::Entry.new('file.zip', 'name', 'isNotCompared', entry1 = ::Zip::Entry.new('file.zip', 'name', 'isNotCompared',
'something extra', 123, 1234, 'something extra', 123, 1234,
::Zip::Entry::DEFLATED, 10000) ::Zip::Entry::DEFLATED, 10_000)
entry2 = ::Zip::Entry.new('file.zip', 'name', 'isNotComparedXXX', entry2 = ::Zip::Entry.new('file.zip', 'name', 'isNotComparedXXX',
'something extra', 123, 1234, 'something extra', 123, 1234,
::Zip::Entry::DEFLATED, 10000) ::Zip::Entry::DEFLATED, 10_000)
entry3 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX', entry3 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
'something extra', 123, 1234, 'something extra', 123, 1234,
::Zip::Entry::DEFLATED, 10000) ::Zip::Entry::DEFLATED, 10_000)
entry4 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX', entry4 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
'something extraXX', 123, 1234, 'something extraXX', 123, 1234,
::Zip::Entry::DEFLATED, 10000) ::Zip::Entry::DEFLATED, 10_000)
entry5 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX', entry5 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
'something extraXX', 12, 1234, 'something extraXX', 12, 1234,
::Zip::Entry::DEFLATED, 10000) ::Zip::Entry::DEFLATED, 10_000)
entry6 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX', entry6 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
'something extraXX', 12, 123, 'something extraXX', 12, 123,
::Zip::Entry::DEFLATED, 10000) ::Zip::Entry::DEFLATED, 10_000)
entry7 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX', entry7 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
'something extraXX', 12, 123, 'something extraXX', 12, 123,
::Zip::Entry::STORED, 10000) ::Zip::Entry::STORED, 10_000)
entry8 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX', entry8 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
'something extraXX', 12, 123, 'something extraXX', 12, 123,
::Zip::Entry::STORED, 100000) ::Zip::Entry::STORED, 100_000)
assert_equal(entry1, entry1) assert_equal(entry1, entry1)
assert_equal(entry1, entry2) assert_equal(entry1, entry2)

View File

@ -21,7 +21,7 @@ class ZipExtraFieldTest < MiniTest::Test
str = "\x0A\x00 \x00\x00\x00\x00\x00\x01\x00\x18\x00\xC0\x81\x17\xE8B\xCE\xCF\x01\xC0\x81\x17\xE8B\xCE\xCF\x01\xC0\x81\x17\xE8B\xCE\xCF\x01" str = "\x0A\x00 \x00\x00\x00\x00\x00\x01\x00\x18\x00\xC0\x81\x17\xE8B\xCE\xCF\x01\xC0\x81\x17\xE8B\xCE\xCF\x01\xC0\x81\x17\xE8B\xCE\xCF\x01"
extra = ::Zip::ExtraField.new(str) extra = ::Zip::ExtraField.new(str)
assert(extra.member?('NTFS')) assert(extra.member?('NTFS'))
t = ::Zip::DOSTime.at(1410496497.405178) t = ::Zip::DOSTime.at(1_410_496_497.405178)
assert_equal(t, extra['NTFS'].mtime) assert_equal(t, extra['NTFS'].mtime)
assert_equal(t, extra['NTFS'].atime) assert_equal(t, extra['NTFS'].atime)
assert_equal(t, extra['NTFS'].ctime) assert_equal(t, extra['NTFS'].ctime)

View File

@ -25,7 +25,7 @@ class ZipFileSplitTest < MiniTest::Test
end end
def test_split def test_split
result = ::Zip::File.split(TEST_ZIP.zip_name, 65536, false) result = ::Zip::File.split(TEST_ZIP.zip_name, 65_536, false)
unless result.nil? unless result.nil?
Dir["#{TEST_ZIP.zip_name}.*"].sort.each_with_index do |zip_file_name, index| Dir["#{TEST_ZIP.zip_name}.*"].sort.each_with_index do |zip_file_name, index|

View File

@ -275,17 +275,17 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
end end
def test_mtime def test_mtime
assert_equal(::Zip::DOSTime.at(1027694306), assert_equal(::Zip::DOSTime.at(1_027_694_306),
@zip_file.file.mtime('dir2/file21')) @zip_file.file.mtime('dir2/file21'))
assert_equal(::Zip::DOSTime.at(1027690863), assert_equal(::Zip::DOSTime.at(1_027_690_863),
@zip_file.file.mtime('dir2/dir21')) @zip_file.file.mtime('dir2/dir21'))
assert_raises(Errno::ENOENT) do assert_raises(Errno::ENOENT) do
@zip_file.file.mtime('noSuchEntry') @zip_file.file.mtime('noSuchEntry')
end end
assert_equal(::Zip::DOSTime.at(1027694306), assert_equal(::Zip::DOSTime.at(1_027_694_306),
@zip_file.file.stat('dir2/file21').mtime) @zip_file.file.stat('dir2/file21').mtime)
assert_equal(::Zip::DOSTime.at(1027690863), assert_equal(::Zip::DOSTime.at(1_027_690_863),
@zip_file.file.stat('dir2/dir21').mtime) @zip_file.file.stat('dir2/dir21').mtime)
end end
@ -301,7 +301,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
def test_ntfs_time def test_ntfs_time
::Zip::File.open('test/data/ntfs.zip') do |zf| ::Zip::File.open('test/data/ntfs.zip') do |zf|
t = ::Zip::DOSTime.at(1410496497.405178) t = ::Zip::DOSTime.at(1_410_496_497.405178)
assert_equal(zf.file.mtime('data.txt'), t) assert_equal(zf.file.mtime('data.txt'), t)
assert_equal(zf.file.atime('data.txt'), t) assert_equal(zf.file.atime('data.txt'), t)
assert_equal(zf.file.ctime('data.txt'), t) assert_equal(zf.file.ctime('data.txt'), t)

View File

@ -30,7 +30,7 @@ class ZipLocalEntryTest < MiniTest::Test
::File.open('test/data/rubycode.zip', 'rb') do |file| ::File.open('test/data/rubycode.zip', 'rb') do |file|
entry = ::Zip::Entry.read_local_entry(file) entry = ::Zip::Entry.read_local_entry(file)
assert_equal('zippedruby1.rb', entry.name) assert_equal('zippedruby1.rb', entry.name)
assert_equal(::Zip::DOSTime.at(1019261638), entry.time) assert_equal(::Zip::DOSTime.at(1_019_261_638), entry.time)
end end
end end
@ -52,7 +52,7 @@ class ZipLocalEntryTest < MiniTest::Test
def test_writeEntry def test_writeEntry
entry = ::Zip::Entry.new('file.zip', 'entryName', 'my little comment', entry = ::Zip::Entry.new('file.zip', 'entryName', 'my little comment',
'thisIsSomeExtraInformation', 100, 987654, 'thisIsSomeExtraInformation', 100, 987_654,
::Zip::Entry::DEFLATED, 400) ::Zip::Entry::DEFLATED, 400)
write_to_file(LEH_FILE, CEH_FILE, entry) write_to_file(LEH_FILE, CEH_FILE, entry)
entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE) entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE)
@ -64,7 +64,7 @@ class ZipLocalEntryTest < MiniTest::Test
def test_writeEntryWithZip64 def test_writeEntryWithZip64
::Zip.write_zip64_support = true ::Zip.write_zip64_support = true
entry = ::Zip::Entry.new('file.zip', 'entryName', 'my little comment', entry = ::Zip::Entry.new('file.zip', 'entryName', 'my little comment',
'thisIsSomeExtraInformation', 100, 987654, 'thisIsSomeExtraInformation', 100, 987_654,
::Zip::Entry::DEFLATED, 400) ::Zip::Entry::DEFLATED, 400)
write_to_file(LEH_FILE, CEH_FILE, entry) write_to_file(LEH_FILE, CEH_FILE, entry)
entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE) entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE)
@ -105,7 +105,7 @@ class ZipLocalEntryTest < MiniTest::Test
def test_readLocalOffset def test_readLocalOffset
entry = ::Zip::Entry.new('file.zip', 'entryName') entry = ::Zip::Entry.new('file.zip', 'entryName')
entry.local_header_offset = 12345 entry.local_header_offset = 12_345
::File.open(CEH_FILE, 'wb') { |f| entry.write_c_dir_entry(f) } ::File.open(CEH_FILE, 'wb') { |f| entry.write_c_dir_entry(f) }
read_entry = nil read_entry = nil
::File.open(CEH_FILE, 'rb') { |f| read_entry = ::Zip::Entry.read_c_dir_entry(f) } ::File.open(CEH_FILE, 'rb') { |f| read_entry = ::Zip::Entry.read_c_dir_entry(f) }

View File

@ -27,9 +27,9 @@ if ENV['FULL_ZIP64_TEST']
io.write(first_text) io.write(first_text)
# write just over 4GB (stored, so the zip file exceeds 4GB) # write just over 4GB (stored, so the zip file exceeds 4GB)
buf = 'blah' * 16384 buf = 'blah' * 16_384
io.put_next_entry('huge_file', nil, nil, ::Zip::Entry::STORED) io.put_next_entry('huge_file', nil, nil, ::Zip::Entry::STORED)
65537.times { io.write(buf) } 65_537.times { io.write(buf) }
io.put_next_entry('last_file.txt') io.put_next_entry('last_file.txt')
io.write(last_text) io.write(last_text)