From 1ba81ff46f00b83d50c9635c74e9f777192ac5d5 Mon Sep 17 00:00:00 2001 From: Pavel Lobashov Date: Mon, 23 Mar 2015 19:23:04 +0300 Subject: [PATCH] fix rubocop Style/NumericLiterals cop --- .rubocop_rubyzip.yml | 5 ----- lib/zip/central_directory.rb | 2 +- lib/zip/crypto/traditional_encryption.rb | 2 +- lib/zip/decompressor.rb | 2 +- lib/zip/extra_field/ntfs.rb | 4 ++-- lib/zip/file.rb | 4 ++-- lib/zip/filesystem.rb | 2 +- lib/zip/ioextras.rb | 2 +- samples/example.rb | 6 +++--- test/central_directory_entry_test.rb | 6 +++--- test/central_directory_test.rb | 6 +++--- test/entry_test.rb | 18 +++++++++--------- test/extra_field_test.rb | 2 +- test/file_split_test.rb | 2 +- test/filesystem/file_nonmutating_test.rb | 10 +++++----- test/local_entry_test.rb | 8 ++++---- test/zip64_full_test.rb | 4 ++-- 17 files changed, 40 insertions(+), 45 deletions(-) diff --git a/.rubocop_rubyzip.yml b/.rubocop_rubyzip.yml index eb3c845..ea8672a 100644 --- a/.rubocop_rubyzip.yml +++ b/.rubocop_rubyzip.yml @@ -198,11 +198,6 @@ Style/NonNilCheck: Style/Not: Enabled: false -# Offense count: 43 -# Cop supports --auto-correct. -Style/NumericLiterals: - MinDigits: 12 - # Offense count: 3 # Configuration parameters: MaxSlashes. Style/RegexpLiteral: diff --git a/lib/zip/central_directory.rb b/lib/zip/central_directory.rb index 7837ebd..cb7e2da 100755 --- a/lib/zip/central_directory.rb +++ b/lib/zip/central_directory.rb @@ -5,7 +5,7 @@ module Zip END_OF_CDS = 0x06054b50 ZIP64_END_OF_CDS = 0x06064b50 ZIP64_EOCD_LOCATOR = 0x07064b50 - MAX_END_OF_CDS_SIZE = 65536 + 18 + MAX_END_OF_CDS_SIZE = 65_536 + 18 STATIC_EOCD_SIZE = 22 attr_reader :comment diff --git a/lib/zip/crypto/traditional_encryption.rb b/lib/zip/crypto/traditional_encryption.rb index ec71462..91e6ce1 100644 --- a/lib/zip/crypto/traditional_encryption.rb +++ b/lib/zip/crypto/traditional_encryption.rb @@ -26,7 +26,7 @@ module Zip def update_keys(n) @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) end diff --git a/lib/zip/decompressor.rb b/lib/zip/decompressor.rb index 2dcbe8f..cd0fb05 100755 --- a/lib/zip/decompressor.rb +++ b/lib/zip/decompressor.rb @@ -1,6 +1,6 @@ module Zip class Decompressor #:nodoc:all - CHUNK_SIZE = 32768 + CHUNK_SIZE = 32_768 def initialize(input_stream) super() @input_stream = input_stream diff --git a/lib/zip/extra_field/ntfs.rb b/lib/zip/extra_field/ntfs.rb index 801446a..1de6b2b 100644 --- a/lib/zip/extra_field/ntfs.rb +++ b/lib/zip/extra_field/ntfs.rb @@ -5,8 +5,8 @@ module Zip HEADER_ID = [0x000A].pack('v') register_map - WINDOWS_TICK = 10000000.0 - SEC_TO_UNIX_EPOCH = 11644473600 + WINDOWS_TICK = 10_000_000.0 + SEC_TO_UNIX_EPOCH = 11_644_473_600 def initialize(binstr = nil) @ctime = nil diff --git a/lib/zip/file.rb b/lib/zip/file.rb index fb28c89..b9e766b 100755 --- a/lib/zip/file.rb +++ b/lib/zip/file.rb @@ -46,8 +46,8 @@ module Zip CREATE = 1 SPLIT_SIGNATURE = 0x08074b50 ZIP64_EOCD_SIGNATURE = 0x06064b50 - MAX_SEGMENT_SIZE = 3221225472 - MIN_SEGMENT_SIZE = 65536 + MAX_SEGMENT_SIZE = 3_221_225_472 + MIN_SEGMENT_SIZE = 65_536 DATA_BUFFER_SIZE = 8192 attr_reader :name diff --git a/lib/zip/filesystem.rb b/lib/zip/filesystem.rb index 0c85a4b..3855754 100755 --- a/lib/zip/filesystem.rb +++ b/lib/zip/filesystem.rb @@ -163,7 +163,7 @@ module Zip if e.fstype == 3 e.external_file_attributes >> 16 else - 33206 # 33206 is equivalent to -rw-rw-rw- + 33_206 # 33206 is equivalent to -rw-rw-rw- end end end diff --git a/lib/zip/ioextras.rb b/lib/zip/ioextras.rb index f205aea..2412480 100755 --- a/lib/zip/ioextras.rb +++ b/lib/zip/ioextras.rb @@ -1,6 +1,6 @@ module Zip module IOExtras #:nodoc: - CHUNK_SIZE = 131072 + CHUNK_SIZE = 131_072 RANGE_ALL = 0..-1 diff --git a/samples/example.rb b/samples/example.rb index 39a610c..12e6b31 100755 --- a/samples/example.rb +++ b/samples/example.rb @@ -61,16 +61,16 @@ Zip::OutputStream.open('large_zip_file.zip') do |zos| puts 'Creating zip file...' 10.times do |i| zos.put_next_entry("large_entry_#{i}.txt") - zos.puts 'Hello' * 104857600 + zos.puts 'Hello' * 104_857_600 end end # 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" # 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}%" end diff --git a/test/central_directory_entry_test.rb b/test/central_directory_entry_test.rb index f881148..99d59b2 100644 --- a/test/central_directory_entry_test.rb +++ b/test/central_directory_entry_test.rb @@ -7,7 +7,7 @@ class ZipCentralDirectoryEntryTest < MiniTest::Test assert_equal('longAscii.txt', entry.name) 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(0xfcd1799c, entry.crc) assert_equal('', entry.comment) @@ -31,8 +31,8 @@ class ZipCentralDirectoryEntryTest < MiniTest::Test entry = ::Zip::Entry.read_c_dir_entry(file) assert_equal('longBinary.bin', entry.name) assert_equal(::Zip::Entry::DEFLATED, entry.compression_method) - assert_equal(1000024, entry.size) - assert_equal(70847, entry.compressed_size) + assert_equal(1_000_024, entry.size) + assert_equal(70_847, entry.compressed_size) assert_equal(0x10da7d59, entry.crc) assert_equal('', entry.comment) diff --git a/test/central_directory_test.rb b/test/central_directory_test.rb index 80e0419..17227b3 100644 --- a/test/central_directory_test.rb +++ b/test/central_directory_test.rb @@ -52,10 +52,10 @@ class ZipCentralDirectoryTest < MiniTest::Test def test_write64_to_stream ::Zip.write_zip64_support = true 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', 'file3-alsobig', 'comment3', '', 15000000000, 103, ::Zip::Entry::DEFLATED, 21000000000), + ::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', '', 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)] - [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 end cdir = ::Zip::CentralDirectory.new(entries, 'zip comment') diff --git a/test/entry_test.rb b/test/entry_test.rb index 8c21388..d92623f 100644 --- a/test/entry_test.rb +++ b/test/entry_test.rb @@ -4,7 +4,7 @@ class ZipEntryTest < MiniTest::Test TEST_ZIPFILE = 'someZipFile.zip' TEST_COMMENT = 'a comment' TEST_COMPRESSED_SIZE = 1234 - TEST_CRC = 325324 + TEST_CRC = 325_324 TEST_EXTRA = 'Some data here' TEST_COMPRESSIONMETHOD = ::Zip::Entry::DEFLATED TEST_NAME = 'entry name' @@ -50,28 +50,28 @@ class ZipEntryTest < MiniTest::Test def test_equality entry1 = ::Zip::Entry.new('file.zip', 'name', 'isNotCompared', 'something extra', 123, 1234, - ::Zip::Entry::DEFLATED, 10000) + ::Zip::Entry::DEFLATED, 10_000) entry2 = ::Zip::Entry.new('file.zip', 'name', 'isNotComparedXXX', 'something extra', 123, 1234, - ::Zip::Entry::DEFLATED, 10000) + ::Zip::Entry::DEFLATED, 10_000) entry3 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX', 'something extra', 123, 1234, - ::Zip::Entry::DEFLATED, 10000) + ::Zip::Entry::DEFLATED, 10_000) entry4 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX', 'something extraXX', 123, 1234, - ::Zip::Entry::DEFLATED, 10000) + ::Zip::Entry::DEFLATED, 10_000) entry5 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX', 'something extraXX', 12, 1234, - ::Zip::Entry::DEFLATED, 10000) + ::Zip::Entry::DEFLATED, 10_000) entry6 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX', 'something extraXX', 12, 123, - ::Zip::Entry::DEFLATED, 10000) + ::Zip::Entry::DEFLATED, 10_000) entry7 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX', 'something extraXX', 12, 123, - ::Zip::Entry::STORED, 10000) + ::Zip::Entry::STORED, 10_000) entry8 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX', 'something extraXX', 12, 123, - ::Zip::Entry::STORED, 100000) + ::Zip::Entry::STORED, 100_000) assert_equal(entry1, entry1) assert_equal(entry1, entry2) diff --git a/test/extra_field_test.rb b/test/extra_field_test.rb index 9ce15f5..fa6e212 100644 --- a/test/extra_field_test.rb +++ b/test/extra_field_test.rb @@ -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" extra = ::Zip::ExtraField.new(str) 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'].atime) assert_equal(t, extra['NTFS'].ctime) diff --git a/test/file_split_test.rb b/test/file_split_test.rb index 090a8ca..2cb63d4 100644 --- a/test/file_split_test.rb +++ b/test/file_split_test.rb @@ -25,7 +25,7 @@ class ZipFileSplitTest < MiniTest::Test end 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? Dir["#{TEST_ZIP.zip_name}.*"].sort.each_with_index do |zip_file_name, index| diff --git a/test/filesystem/file_nonmutating_test.rb b/test/filesystem/file_nonmutating_test.rb index f0fd7a8..9e8c8d3 100644 --- a/test/filesystem/file_nonmutating_test.rb +++ b/test/filesystem/file_nonmutating_test.rb @@ -275,17 +275,17 @@ class ZipFsFileNonmutatingTest < MiniTest::Test end def test_mtime - assert_equal(::Zip::DOSTime.at(1027694306), + assert_equal(::Zip::DOSTime.at(1_027_694_306), @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')) assert_raises(Errno::ENOENT) do @zip_file.file.mtime('noSuchEntry') end - assert_equal(::Zip::DOSTime.at(1027694306), + assert_equal(::Zip::DOSTime.at(1_027_694_306), @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) end @@ -301,7 +301,7 @@ class ZipFsFileNonmutatingTest < MiniTest::Test def test_ntfs_time ::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.atime('data.txt'), t) assert_equal(zf.file.ctime('data.txt'), t) diff --git a/test/local_entry_test.rb b/test/local_entry_test.rb index a429051..b935100 100644 --- a/test/local_entry_test.rb +++ b/test/local_entry_test.rb @@ -30,7 +30,7 @@ class ZipLocalEntryTest < MiniTest::Test ::File.open('test/data/rubycode.zip', 'rb') do |file| entry = ::Zip::Entry.read_local_entry(file) 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 @@ -52,7 +52,7 @@ class ZipLocalEntryTest < MiniTest::Test def test_writeEntry entry = ::Zip::Entry.new('file.zip', 'entryName', 'my little comment', - 'thisIsSomeExtraInformation', 100, 987654, + 'thisIsSomeExtraInformation', 100, 987_654, ::Zip::Entry::DEFLATED, 400) write_to_file(LEH_FILE, CEH_FILE, entry) entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE) @@ -64,7 +64,7 @@ class ZipLocalEntryTest < MiniTest::Test def test_writeEntryWithZip64 ::Zip.write_zip64_support = true entry = ::Zip::Entry.new('file.zip', 'entryName', 'my little comment', - 'thisIsSomeExtraInformation', 100, 987654, + 'thisIsSomeExtraInformation', 100, 987_654, ::Zip::Entry::DEFLATED, 400) write_to_file(LEH_FILE, CEH_FILE, entry) entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE) @@ -105,7 +105,7 @@ class ZipLocalEntryTest < MiniTest::Test def test_readLocalOffset 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) } read_entry = nil ::File.open(CEH_FILE, 'rb') { |f| read_entry = ::Zip::Entry.read_c_dir_entry(f) } diff --git a/test/zip64_full_test.rb b/test/zip64_full_test.rb index db24add..d9dae69 100644 --- a/test/zip64_full_test.rb +++ b/test/zip64_full_test.rb @@ -27,9 +27,9 @@ if ENV['FULL_ZIP64_TEST'] io.write(first_text) # 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) - 65537.times { io.write(buf) } + 65_537.times { io.write(buf) } io.put_next_entry('last_file.txt') io.write(last_text)