detectByResolvers: Don't mandate an actual file to be present

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.
This commit is contained in:
Hugo Beauzée-Luyssen 2022-02-09 13:52:04 +01:00 committed by Urs Fleisch
parent f7887e7235
commit 82964ba176

View File

@ -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,
@ -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;