/* 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
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()
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}
# 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>
bool zlib::isAvailable()
{
-#ifdef HAVE_ZLIB
+#if defined(HAVE_ZLIB) || defined(HAVE_BOOST_ZLIB)
return true;
ByteVector zlib::decompress(const ByteVector &data)
{
-#ifdef HAVE_ZLIB
+#if defined(HAVE_ZLIB)
z_stream stream = {};
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);
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();