]> granicus.if.org Git - taglib/commitdiff
Support Boost iostreams library to decode compressed ID3v2 frames in additiion to...
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Tue, 23 Feb 2016 15:26:37 +0000 (00:26 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Wed, 2 Mar 2016 02:14:11 +0000 (11:14 +0900)
This will help Windows users build TagLib without zlib source.

ConfigureChecks.cmake
config.h.cmake
taglib/CMakeLists.txt
taglib/toolkit/tzlib.cpp

index 0f2b6d874a34284abdd91fe6eae627d2de66316d..ee4fdc2ef8795fc345900a3bf786695b33a06f29 100644 (file)
@@ -225,6 +225,15 @@ if(NOT ZLIB_SOURCE)
   else()
     set(HAVE_ZLIB 0)
   endif()
+
+  if(NOT HAVE_ZLIB)
+    find_package(Boost COMPONENTS iostreams zlib)
+    if(Boost_IOSTREAMS_FOUND AND Boost_ZLIB_FOUND)
+      set(HAVE_BOOST_ZLIB 1)
+    else()
+      set(HAVE_BOOST_ZLIB 0)
+    endif()
+  endif()
 endif()
 
 # Determine whether CppUnit is installed.
index 7ac724108470f6f9aa80552da4a76a588c133569..7eb5993f5247aa7d6fa20e6f87307933f77a2136 100644 (file)
@@ -25,6 +25,7 @@
 
 /* Defined if zlib is installed */
 #cmakedefine   HAVE_ZLIB 1
+#cmakedefine   HAVE_BOOST_ZLIB 1
 
 /* Indicates whether debug messages are shown even in release mode */
 #cmakedefine   TRACE_IN_RELEASE 1
index f248d0d1fbd152f73a8fd21bb3b7cb47dbc84fb9..000f79378563b643cb36915bbbc6c5de38255b37 100644 (file)
@@ -32,7 +32,7 @@ elseif(HAVE_ZLIB_SOURCE)
   include_directories(${ZLIB_SOURCE})
 endif()
 
-if(HAVE_BOOST_BYTESWAP OR HAVE_BOOST_ATOMIC)
+if(HAVE_BOOST_BYTESWAP OR HAVE_BOOST_ATOMIC OR HAVE_BOOST_ZLIB)
   include_directories(${Boost_INCLUDE_DIR})
 endif()
 
@@ -352,6 +352,10 @@ if(HAVE_BOOST_ATOMIC)
   target_link_libraries(tag ${Boost_ATOMIC_LIBRARY})
 endif()
 
+if(HAVE_BOOST_ZLIB)
+  target_link_libraries(tag ${Boost_IOSTREAMS_LIBRARY} ${Boost_ZLIB_LIBRARY})
+endif()
+
 set_target_properties(tag PROPERTIES
   VERSION ${TAGLIB_SOVERSION_MAJOR}.${TAGLIB_SOVERSION_MINOR}.${TAGLIB_SOVERSION_PATCH}
   SOVERSION ${TAGLIB_SOVERSION_MAJOR}
index 3d49732a2a35c391cd61f41c5c51990c67b7c338..40158fd2eda655ec9dda71f66367ecd8c0cea65e 100644 (file)
 # include <config.h>
 #endif
 
-#ifdef HAVE_ZLIB
+#if defined(HAVE_ZLIB)
 # include <zlib.h>
+#elif defined(HAVE_BOOST_ZLIB)
+# include <boost/iostreams/filtering_streambuf.hpp>
+# include <boost/iostreams/filter/zlib.hpp>
 #endif
 
 #include <tstring.h>
@@ -40,7 +43,7 @@ using namespace TagLib;
 
 bool zlib::isAvailable()
 {
-#ifdef HAVE_ZLIB
+#if defined(HAVE_ZLIB) || defined(HAVE_BOOST_ZLIB)
 
   return true;
 
@@ -53,7 +56,7 @@ bool zlib::isAvailable()
 
 ByteVector zlib::decompress(const ByteVector &data)
 {
-#ifdef HAVE_ZLIB
+#if defined(HAVE_ZLIB)
 
   z_stream stream = {};
 
@@ -81,9 +84,9 @@ ByteVector zlib::decompress(const ByteVector &data)
     const int result = inflate(&stream, Z_NO_FLUSH);
 
     if(result == Z_STREAM_ERROR ||
-        result == Z_NEED_DICT ||
-        result == Z_DATA_ERROR ||
-        result == Z_MEM_ERROR)
+       result == Z_NEED_DICT ||
+       result == Z_DATA_ERROR ||
+       result == Z_MEM_ERROR)
     {
       if(result != Z_STREAM_ERROR)
         inflateEnd(&stream);
@@ -99,6 +102,38 @@ ByteVector zlib::decompress(const ByteVector &data)
 
   return outData;
 
+#elif defined(HAVE_BOOST_ZLIB)
+
+  using namespace boost::iostreams;
+
+  struct : public sink
+  {
+    ByteVector data;
+
+    typedef char     char_type;
+    typedef sink_tag category;
+
+    std::streamsize write(char const* s, std::streamsize n)
+    {
+      const unsigned int originalSize = data.size();
+
+      data.resize(static_cast<unsigned int>(originalSize + n));
+      ::memcpy(data.data() + originalSize, s, static_cast<size_t>(n));
+
+      return n;
+    }
+  } sink;
+
+  try {
+    zlib_decompressor().write(sink, data.data(), data.size());
+  }
+  catch(const zlib_error &) {
+    debug("zlib::decompress() - Error reading compressed stream.");
+    return ByteVector();
+  }
+
+  return sink.data;
+
 #else
 
   return ByteVector();