Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wav files not being rewound, such as when they are missing their file extension #48

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +57 to +58
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aidewoode Added rewind to the helper (I'll also be adding it to the Tag class as discussed)


# 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

Comment on lines +34 to +36
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aidewoode Added rewind to the Tag class instead of the specific RiffTag class

@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
Loading