Skip to content

Commit

Permalink
detectByResolvers: Don't mandate an actual file to be present
Browse files Browse the repository at this point in the history
The main point of IOStream is to be able to use taglib with some content
that can't be fopen()'ed, for instance a network file, or a local file
on a system that doesn't support opening a file directly through fopen
& such.
This commit adds an overload for detectByResolvers that will stick to
using an IOStream all the way.
  • Loading branch information
chouquette committed Feb 16, 2022
1 parent 5722a57 commit 27d4107
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion taglib/fileref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ namespace
return 0;
}

File *detectByResolvers(IOStream* stream, bool readAudioProperties,
AudioProperties::ReadStyle audioPropertiesStyle)
{
ResolverList::ConstIterator it = fileTypeResolvers.begin();
for(; it != fileTypeResolvers.end(); ++it) {
const FileRef::StreamTypeResolver* streamResolver =
dynamic_cast<const FileRef::StreamTypeResolver*>(*it);
if (!streamResolver)
continue;
File *file = streamResolver->createFileFromStream(stream, readAudioProperties, audioPropertiesStyle);
if(file)
return file;
}

return 0;
}

// Detect the file type based on the file extension.

File* detectByExtension(IOStream *stream, bool readAudioProperties,
Expand Down Expand Up @@ -482,7 +499,7 @@ void FileRef::parse(IOStream *stream, bool readAudioProperties,
{
// Try user-defined resolvers.

d->file = detectByResolvers(stream->name(), readAudioProperties, audioPropertiesStyle);
d->file = detectByResolvers(stream, readAudioProperties, audioPropertiesStyle);
if(d->file)
return;

Expand Down

0 comments on commit 27d4107

Please sign in to comment.