aboutsummaryrefslogtreecommitdiffstats
path: root/taglib/riff
diff options
context:
space:
mode:
authorTsuda Kageyu <tsuda.kageyu@gmail.com>2017-02-03 17:52:27 +0900
committerTsuda Kageyu <tsuda.kageyu@gmail.com>2017-02-04 23:31:08 +0900
commit931bb042c396f3452b0a8a82b88b93e0fe16dbc9 (patch)
tree7968c9663753318cff711f3a53f159e611aadffb /taglib/riff
parenta5d9e49c4958ef4e91785b74afab52964a521499 (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/riff')
-rw-r--r--taglib/riff/aiff/aifffile.cpp13
-rw-r--r--taglib/riff/aiff/aifffile.h8
-rw-r--r--taglib/riff/wav/wavfile.cpp21
-rw-r--r--taglib/riff/wav/wavfile.h9
4 files changed, 47 insertions, 4 deletions
diff --git a/taglib/riff/aiff/aifffile.cpp b/taglib/riff/aiff/aifffile.cpp
index 1a29938c..72705a9a 100644
--- a/taglib/riff/aiff/aifffile.cpp
+++ b/taglib/riff/aiff/aifffile.cpp
@@ -28,6 +28,7 @@
#include <id3v2tag.h>
#include <tstringlist.h>
#include <tpropertymap.h>
+#include <tagutils.h>
#include "aifffile.h"
@@ -54,6 +55,18 @@ public:
};
////////////////////////////////////////////////////////////////////////////////
+// static members
+////////////////////////////////////////////////////////////////////////////////
+
+bool RIFF::AIFF::File::isValidStream(IOStream *stream)
+{
+ // An AIFF file has to start with "FORM????AIFF" or "FORM????AIFC".
+
+ const ByteVector id = Utils::readHeader(stream, 12, false);
+ return (id.startsWith("FORM") && (id.containsAt("AIFF", 8) || id.containsAt("AIFC", 8)));
+}
+
+////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
diff --git a/taglib/riff/aiff/aifffile.h b/taglib/riff/aiff/aifffile.h
index a79d76b2..611b7338 100644
--- a/taglib/riff/aiff/aifffile.h
+++ b/taglib/riff/aiff/aifffile.h
@@ -126,6 +126,14 @@ namespace TagLib {
*/
bool hasID3v2Tag() const;
+ /*!
+ * Check if the given \a stream can be opened as an AIFF 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 &);
diff --git a/taglib/riff/wav/wavfile.cpp b/taglib/riff/wav/wavfile.cpp
index 79ff9167..5e92b29e 100644
--- a/taglib/riff/wav/wavfile.cpp
+++ b/taglib/riff/wav/wavfile.cpp
@@ -23,10 +23,11 @@
* http://www.mozilla.org/MPL/ *
***************************************************************************/
-#include "tbytevector.h"
-#include "tdebug.h"
-#include "tstringlist.h"
-#include "tpropertymap.h"
+#include <tbytevector.h>
+#include <tdebug.h>
+#include <tstringlist.h>
+#include <tpropertymap.h>
+#include <tagutils.h>
#include "wavfile.h"
#include "id3v2tag.h"
@@ -61,6 +62,18 @@ public:
};
////////////////////////////////////////////////////////////////////////////////
+// static members
+////////////////////////////////////////////////////////////////////////////////
+
+bool RIFF::WAV::File::isValidStream(IOStream *stream)
+{
+ // A WAV file has to start with "RIFF????WAVE".
+
+ const ByteVector id = Utils::readHeader(stream, 12, false);
+ return (id.startsWith("RIFF") && id.containsAt("WAVE", 8));
+}
+
+////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
diff --git a/taglib/riff/wav/wavfile.h b/taglib/riff/wav/wavfile.h
index 80f17a85..47e8116d 100644
--- a/taglib/riff/wav/wavfile.h
+++ b/taglib/riff/wav/wavfile.h
@@ -175,6 +175,15 @@ namespace TagLib {
*/
bool hasInfoTag() const;
+ /*!
+ * Returns whether or not the given \a stream can be opened as a WAV
+ * 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 &);