From 82964ba17607e9c90813b3b8741734887c337c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Wed, 9 Feb 2022 13:52:04 +0100 Subject: [PATCH] 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. --- taglib/fileref.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index f91209a0..88e53ed1 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -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(*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;