diff options
author | Tsuda Kageyu <tsuda.kageyu@gmail.com> | 2017-02-03 17:52:27 +0900 |
---|---|---|
committer | Tsuda Kageyu <tsuda.kageyu@gmail.com> | 2017-02-04 23:31:08 +0900 |
commit | 931bb042c396f3452b0a8a82b88b93e0fe16dbc9 (patch) | |
tree | 7968c9663753318cff711f3a53f159e611aadffb /taglib/flac | |
parent | a5d9e49c4958ef4e91785b74afab52964a521499 (diff) |
Enable FileRef to detect file types by the actual content of a stream.
FileRef doesn't work with ByteVectorStream as reported at #796, since ByteVectorStream is not associated with a file name and FileRef detects file types based on file extensions.
This commit makes FileRef to work with ByteVectorStream by enabling it to detect file types based on the actual content of a stream.
Diffstat (limited to 'taglib/flac')
-rw-r--r-- | taglib/flac/flacfile.cpp | 12 | ||||
-rw-r--r-- | taglib/flac/flacfile.h | 9 |
2 files changed, 21 insertions, 0 deletions
diff --git a/taglib/flac/flacfile.cpp b/taglib/flac/flacfile.cpp index b6b72960..780ab1c3 100644 --- a/taglib/flac/flacfile.cpp +++ b/taglib/flac/flacfile.cpp @@ -96,6 +96,18 @@ public: }; //////////////////////////////////////////////////////////////////////////////// +// static members +//////////////////////////////////////////////////////////////////////////////// + +bool FLAC::File::isValidStream(IOStream *stream) +{ + // A FLAC file has an ID "fLaC" somewhere. An ID3v2 tag may precede. + + const ByteVector buffer = Utils::readHeader(stream, bufferSize(), true); + return (buffer.find("fLaC") >= 0); +} + +//////////////////////////////////////////////////////////////////////////////// // public members //////////////////////////////////////////////////////////////////////////////// diff --git a/taglib/flac/flacfile.h b/taglib/flac/flacfile.h index 65d85679..56755ec5 100644 --- a/taglib/flac/flacfile.h +++ b/taglib/flac/flacfile.h @@ -318,6 +318,15 @@ namespace TagLib { */ bool hasID3v2Tag() const; + /*! + * Returns whether or not the given \a stream can be opened as a FLAC + * file. + * + * \note This method is designed to do a quick check. The result may + * not necessarily be correct. + */ + static bool isValidStream(IOStream *stream); + private: File(const File &); File &operator=(const File &); |