Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3595598
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:52:24+00:00 2026-05-18T19:52:24+00:00

The POCO Library requires an istream for input and ostream for output to compress

  • 0

The POCO Library requires an istream for input and ostream for output to compress data using its zlib wrapper. I have data in a std::vector(unsigned char) and would like to compress this data into another std::vector(unsigned char). Is there any easy way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T19:52:25+00:00Added an answer on May 18, 2026 at 7:52 pm

    I don’t know that this is the most efficient way, but as a start I’d try this:

    typedef unsigned char uc;
    typedef vector<uc> v;
    void Doit(const v& in, v& out)
    {
       ostringstream outStream;
       DeflatingOutputStream compressor(outStream, DeflatingStreamBuf::STREAM_GZIP);
       copy(in.begin(), in.end(), ostream_iterator<uc>(compressor));
       compressor.close();
       string outStr(outStream.str());
       out.assign(outStr.begin(), outStr.end());
    }
    

    I suspect this copies the data twice, unnecessarily. First, the call to ostringstream::str() makes a copy, and next std::vector::assign() makes a copy.

    @Alf P. Steinbach had an excellent suggestion — use Boost stream adapters. If you have boost::iostreams::filtering_ostream available to you, you could try this:

    typedef unsigned char uc;
    typedef vector<uc> v;
    
    void Doit(const v& in, v& out)
    {
       filtering_ostream outStream(back_inserter(out));
       DeflatingOutputStream compressor(outStream, DeflatingStreamBuf::STREAM_GZIP);
       std::copy(in.begin(), in.end(), ostream_iterator<uc>(compressor));
       compressor.close();
       outStream.flush();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The POCO Library requires an istream for input and ostream for output to compress
I have built the Poco C++ library on Mac. When inspecting the built output
I have a simple Poco-Model using abstract classes, and it seems not to work
I am using Poco library and when running my program on other machines which
I'm using crypto package in poco library. the application is release /MT and i
IDE: VS2005 Say I am using Poco library and the executable needs below dlls.
I have a serializable POCO called DataUnification.ClientData.ClientInfo in a .NET class library project A
I have an existing POCO class library where children collections are all stored in
I created an application in visual studio 2008 using c++ and poco library. Since
I have a POCO classes that I am using with NHibernate in a WCF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.