Skip to content

Commit

Permalink
Merge pull request #48 from scouttyg/scott/fix-riff-not-rewinding-on-…
Browse files Browse the repository at this point in the history
…parse

Fix wav files not being rewound, such as when they are missing their file extension
  • Loading branch information
aidewoode authored Aug 13, 2024
2 parents 7f8190c + 89c8818 commit 8c8b5b2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/wahwah/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def self.file_format_from_extension(file_path)
def self.file_format_from_signature(io)
io.rewind
signature = io.read(16)
# Rewind after reading the signature to not mess with the file position
io.rewind

# Source: https://en.wikipedia.org/wiki/List_of_file_signatures

Expand Down
3 changes: 3 additions & 0 deletions lib/wahwah/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def initialize(io, from_path: false)
@file_size = io.size
@file_io = io

# Rewinding at the start just in case some other helper class or parser already read from the file
@file_io.rewind

@comments = []
@images_data = []

Expand Down
2 changes: 1 addition & 1 deletion lib/wahwah/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module WahWah
VERSION = "1.6.4"
VERSION = "1.6.5"
end
21 changes: 21 additions & 0 deletions test/wahwah/riff_tag_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,25 @@ def test_tag_that_riff_chunk_without_data_chunk
assert_equal 16, tag.bit_depth
end
end

def test_tag_works_with_file_missing_extension
blob_data = binary_data("test/files/id3v2.wav")

Tempfile.create("temp-audio-file", binmode: true) do |temp_file|
temp_file.write blob_data
tag = WahWah::RiffTag.new(temp_file)

assert_equal "China Girl", tag.title
assert_equal "Iggy Pop", tag.artist
assert_equal "The Idiot", tag.album
assert_equal "1977", tag.year
assert_equal "Rock", tag.genre
assert_equal ["Iggy Pop Rocks"], tag.comments
assert_equal 8.001133947554926, tag.duration
assert_equal 1411, tag.bitrate
assert_equal "Stereo", tag.channel_mode
assert_equal 44100, tag.sample_rate
assert_equal 16, tag.bit_depth
end
end
end

0 comments on commit 8c8b5b2

Please sign in to comment.