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

Conversation

scouttyg
Copy link
Contributor

@scouttyg scouttyg commented Aug 8, 2024

If a file doesn't have an extension, WahWah will attempt to understand the format from the signature:

def self.file_format_from_signature(io)
  io.rewind
  signature = io.read(16)

  # ...
end

This moves the position of the IO, but parse within RiffTag doesn't take this into account.

To fix this, I do @file_io.rewind at the begining of parse within RiffTag now.

Strangely, I was surprised this didn't affect other tags -- if file_format_from_signature was moving the position, wouldn't this not just affect RiffTag?

Looking around, I guess the answer was "no" -- Mp3Tag rewinds at the start via parse_id3_tag, FlacTag conditionally rewinds, and Mp4Tag seems to seek to some known attributes.

I still wonder if there's some issues with this other places, but for now this at least fixes RiffTag.

@scouttyg scouttyg force-pushed the scott/fix-riff-not-rewinding-on-parse branch from 1592506 to dab3999 Compare August 8, 2024 14:01
@coveralls
Copy link

coveralls commented Aug 8, 2024

Pull Request Test Coverage Report for Build 10354779343

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.005%) to 97.54%

Totals Coverage Status
Change from base Build 10302059979: 0.005%
Covered Lines: 912
Relevant Lines: 935

💛 - Coveralls

@scouttyg
Copy link
Contributor Author

Hey @aidewoode , let me know what you think on this one, or if I should add any new tests or fixes.

@aidewoode
Copy link
Owner

Sorry for late reply, and thanks for your great PR to remind me the issue of file_format_from_signature method. You are right the file_format_from_signature method may case others tag face the same issue as Riff tag does. So I think maybe put the @file_io.rewind in the initialize method of Tag class is better. because it could solve this issue on all different tags and make sure the IO is rewound before parse the tag. What do you think about this?

@scouttyg
Copy link
Contributor Author

@aidewoode An alternative would be to do the rewind right after doing signature = io.read(16) within file_format_from_signature, so it becomes more clear why the rewind is being done right at that moment.

Putting it in Tag helps prevent other future cases where a helper file or other file might read without rewinding, but I feel like it then becomes unclear as to why it needs to be done (e.g. to new developers looking at the codebase), which then involves either more deeper analysis into the classes to get the backstory, or potential accidental removal when people think the code is extraneous.

The downside of putting it in file_format_from_signature though is that the tests won't work as I wrote them above, as RiffTag doesn't implement the file_format = Helper.file_format io logic, only WahWah#open does, whereas if we put rewind in Tag#initialize it would fix it.

I'm fine either way -- if you think it belongs best in Tag#initialize I can make those changes as well, but let me know what you think

@aidewoode
Copy link
Owner

@scouttyg , I think we could add rewind in both, including in file_format_from_signature helper and initialize method of Tag class. As you mentioned, file_format_from_signature should rewind after it read IO. And for another case I will write test to let others know why IO need rewind before parse.

Don't worry about test right now. Just ignore the test. I will write some tests cover both scenarios later, because I don't want to let you spend too much time flighting with test. I am more familiar with those test cases.

…th this issue for other files potentially in the future
Comment on lines +57 to +58
# Rewind after reading the signature to not mess with the file position
io.rewind
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)

Comment on lines +34 to +36
# Rewinding at the start just in case some other helper class or parser already read from the file
@file_io.rewind

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

@aidewoode aidewoode merged commit 8c8b5b2 into aidewoode:master Aug 13, 2024
6 checks passed
@aidewoode
Copy link
Owner

Thanks! Released in v1.6.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants