Skip to content

Commit 2806bc8

Browse files
authored
Merge pull request #56 from djberg96/binary_encoding_revert
Binary encoding revert
2 parents 08d1a11 + 35e5d7e commit 2806bc8

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace 'spec' do
8282

8383
RSpec::Core::RakeTask.new(:all) do |t|
8484
t.pattern = 'spec/*_spec.rb'
85-
t.rspec_opts = '-f documentation'
85+
t.rspec_opts = '-f documentation -w'
8686
end
8787
end
8888

lib/ptools.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def self.touch(filename)
332332
# 'lines'.
333333
#
334334
def self.wc(filename, option = 'all')
335-
option.downcase!
335+
option = option.downcase
336336
valid = %w[all bytes characters chars lines words]
337337

338338
raise ArgumentError, "Invalid option: '#{option}'" unless valid.include?(option)
@@ -430,27 +430,27 @@ def self.bmp?(file)
430430
# Is the file a jpeg file?
431431
#
432432
def self.jpg?(file)
433-
File.read(file, 10, nil, :encoding => 'binary') == "\xFF\xD8\xFF\xE0\x00\x10JFIF".force_encoding(Encoding::BINARY)
433+
File.read(file, 10, nil, :encoding => 'binary') == String.new("\377\330\377\340\000\020JFIF").force_encoding(Encoding::BINARY)
434434
end
435435

436436
# Is the file a png file?
437437
#
438438
def self.png?(file)
439-
File.read(file, 4, nil, :encoding => 'binary') == "\x89PNG".force_encoding(Encoding::BINARY)
439+
File.read(file, 4, nil, :encoding => 'binary') == String.new("\211PNG").force_encoding(Encoding::BINARY)
440440
end
441441

442442
# Is the file a gif?
443443
#
444444
def self.gif?(file)
445-
%w[GIF89a GIF97a].include?(File.read(file, 6, nil, :encoding => 'binary'))
445+
%w[GIF89a GIF97a].include?(File.read(file, 6))
446446
end
447447

448448
# Is the file a tiff?
449449
#
450450
def self.tiff?(file)
451451
return false if File.size(file) < 12
452452

453-
bytes = File.read(file, 4, nil, :encoding => 'binary')
453+
bytes = File.read(file, 4)
454454

455455
# II is Intel, MM is Motorola
456456
return false if bytes[0..1] != 'II' && bytes[0..1] != 'MM'
@@ -465,6 +465,6 @@ def self.tiff?(file)
465465
# Is the file an ico file?
466466
#
467467
def self.ico?(file)
468-
["\x00\x00\x01\x00".force_encoding(Encoding::BINARY), "\x00\x00\x02\x00".force_encoding(Encoding::BINARY)].include?(File.read(file, 4, nil, :encoding => 'binary'))
468+
["\000\000\001\000", "\000\000\002\000"].include?(File.read(file, 4, nil, :encoding => 'binary'))
469469
end
470470
end

0 commit comments

Comments
 (0)