-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build boost with zlib support #14
Comments
NSS branch may have a need for our Windows build of boost to support zlib/gzip:
|
Boost.Iostreams Installation How to build boost iostreams with gzip and bzip2 support on Windows Building Zlib and Iostreams |
feature branch started |
bzip2 source in git repo bzip2 website bzip2 downloads |
http://www.boost.org/doc/libs/1_56_0/libs/iostreams/doc/classes/bzip2.html#examples #include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
int main()
{
using namespace std;
using namespace boost::iostreams;
ifstream file("hello.bz2", ios_base::in | ios_base::binary);
filtering_streambuf<input> in;
in.push(bzip2_decompressor());
in.push(file);
boost::iostreams::copy(in, cout);
} http://www.boost.org/doc/libs/1_50_0/libs/iostreams/doc/classes/zlib.html#examples #include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
int main()
{
using namespace std;
ifstream file("hello.z", ios_base::in | ios_base::binary);
filtering_streambuf<input> in;
in.push(zlib_decompressor());
in.push(file);
boost::iostreams::copy(in, cout);
} |
http://www.boost.org/doc/libs/1_42_0/libs/iostreams/doc/classes/gzip.html#examples #include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
int main()
{
using namespace std;
ifstream file("hello.gz", ios_base::in | ios_base::binary);
filtering_streambuf<input> in;
in.push(gzip_decompressor());
in.push(file);
boost::iostreams::copy(in, cout);
} |
Combined example code that decompresses data based on file extension of input argument. #include <fstream>
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>
#pragma warning(push)
// conversion from std::streamsize to int, possible loss of data
#pragma warning(disable : 4244)
#include <boost/iostreams/copy.hpp>
#pragma warning(pop)
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filter/zlib.hpp>
int main(int argc, char** argv)
{
namespace bfs = boost::filesystem;
namespace bio = boost::iostreams;
bfs::path exepath = bfs::path(std::string(argv[0]));
if (argc != 2)
{
std::cerr << "usage: " << exepath.filename().string() << " file.[bz2|gz|Z]" << std::endl;
return 1;
}
try
{
bfs::path filepath = bfs::path(std::string(argv[1]));
if (!bfs::exists(filepath))
{
std::cerr << filepath.string() << ": doesn't exist" << std::endl;
return 1;
}
bio::filtering_streambuf<bio::input> in;
std::string ext = filepath.extension().string();
if (ext.compare(".bz2") == 0)
in.push(bio::bzip2_decompressor());
else if (ext.compare(".gz") == 0)
in.push(bio::gzip_decompressor());
else if (ext.compare(".Z") == 0)
in.push(bio::zlib_decompressor());
else
{
std::cerr << filepath.filename().string() << ": unsupported extension (must be .[bz2|gz|Z])" << std::endl;
return 1;
}
std::ifstream file(argv[1], std::ios_base::in | std::ios_base::binary);
in.push(file);
bio::copy(in, std::cout);
}
//catch (const bio::bzip2_error& e)
catch (const bio::zlib_error& e)
{
int err = e.error();
if (err == bio::zlib::buf_error)
std::cerr << "zlib buffer error" << std::endl;
else if (err == bio::zlib::data_error)
std::cerr << "zlib data error" << std::endl;
else if (err == bio::zlib::mem_error)
std::cerr << "zlib memory error" << std::endl;
else if (err == bio::zlib::stream_error)
std::cerr << "zlib stream error" << std::endl;
else if (err == bio::zlib::version_error)
std::cerr << "zlib version error" << std::endl;
else
std::cerr << "zlib unknown error" << std::endl;
return 1;
}
catch (const std::exception& e)
{
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
} CMakeLists.txt cmake_minimum_required(VERSION 3.3)
project(decompressor)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
set(externpro_REV 16.01.1)
find_package(externpro REQUIRED)
include(${externpro_DIR}/share/cmake/flags.cmake)
set(Boost_LIBS filesystem system iostreams)
if(MSVC)
xpGetExtern(externIncs externLibs PUBLIC boost)
xpGetExtern(dontcare zlibBinary PRIVATE zlib)
add_definitions(
-DBOOST_ZLIB_BINARY=$<TARGET_FILE:${zlibBinary}>
#-DBOOST_BZIP2_BINARY=
)
else()
xpGetExtern(externIncs externLibs PUBLIC boost zlib)
find_package(BZip2 REQUIRED)
list(APPEND externLibs ${BZIP2_LIBRARIES})
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_executable(${PROJECT_NAME} decompress.cpp)
target_link_libraries(${PROJECT_NAME} ${externLibs})
target_include_directories(${PROJECT_NAME} ${externIncs}) |
completed with pull to dev branch |
with work merged to dev branch (the zlib and bzip2 dependencies are part of the boost use script now), the CMakeLists.txt for the sample app is now simply: cmake_minimum_required(VERSION 3.7.2)
project(decompressor)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
set(externpro_REV 17.05.1)
find_package(externpro REQUIRED)
include(${externpro_DIR}/share/cmake/flags.cmake)
set(Boost_LIBS filesystem system iostreams)
xpGetExtern(externIncs externLibs PUBLIC boost)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_executable(${PROJECT_NAME} decompress.cpp)
target_link_libraries(${PROJECT_NAME} ${externLibs})
target_include_directories(${PROJECT_NAME} ${externIncs}) |
Testing Then I verified that I also created a
When I put in the try/catch, specifically catching the boost::iostreams::zlib_error, the error is reported:
|
A similar exception is reported "Boost Iostreams zlib_error with Custom Source" A similar exception (but gzip_error, not zlib_error) was also reported in "Possible bug in gzip_decompressor"
A ticket for The proposed fix ( |
Searching for I found There is an open pull to boostorg/iostreams I forked boost iostreams, cherry-picked the commits to an xp1.57.0 and xphpp1.57.0 branch -- NOTE: had to separate cpp mods from hpp mods so the patching of the downloaded boost .tar.bz2 file works correctly And created an externpro patch of iostreams -- but this also did not fix the issue I'm seeing |
The sample decompress.cpp code above determines the decompressor to push by looking at the file extension: std::string ext = filepath.extension().string();
if (ext.compare(".bz2") == 0)
in.push(bio::bzip2_decompressor());
else if (ext.compare(".gz") == 0)
in.push(bio::gzip_decompressor());
else if (ext.compare(".Z") == 0)
in.push(bio::zlib_decompressor());
else
{
std::cerr << filepath.filename().string() << ": unsupported extension (must be .[bz2|gz|Z])" << std::endl;
return 1;
} As I was searching for answers to issues I was dealing with, I came across an interesting idea:
|
we've been relying on a separate install of the zlib developement package (on linux, perhaps also on Solaris? - I don't remember, but most likely) to build boost iostreams
now that we build zlib as part of externpro, we should make an externpro project dependency between the two (boost on zlib) and have boost build against our zlib build
this would also enhance our windows build of boost, which doesn't have zlib support yet
The text was updated successfully, but these errors were encountered: