Overview
Features
Download
Documentation
Community
Add-Ons & Services

MD5 of Compressed stream ?

Please post support and help requests here.

MD5 of Compressed stream ?

Postby rmoffer » 21 Jul 2013, 16:55

How do I combine a DeflateOutputStream and DigestOutputStream ?


Since I'm dealing with large content (in pieces) I'm using the write() method, not copyStream()



richard.
rmoffer
 
Posts: 49
Joined: 09 Feb 2009, 19:20
Location: San Francisco bay area.

Re: MD5 of Compressed stream ?

Postby guenter » 22 Jul 2013, 10:07

Code: Select all
#include "Poco/DeflatingStream.h"
#include "Poco/DigestStream.h"
#include "Poco/MD5Engine.h"
#include "Poco/StreamCopier.h"
#include <iostream>
#include <fstream>


using Poco::DeflatingOutputStream;
using Poco::DigestOutputStream;
using Poco::StreamCopier;


int main(int argc, char** argv)
{
   if (argc != 3)
   {
      std::cout << "usage: " << argv[0] << ": <input_file> <output_file>" << std::endl
                << "       read <input_file>, deflate (compress) it and write the result to <output_file>" << std::endl;
      return 1;
   }
   
   std::ifstream istr(argv[1], std::ios::binary);
   if (!istr)
   {
      std::cerr << "cannot open input file: " << argv[1] << std::endl;
      return 2;
   }
   
   std::ofstream ostr(argv[2], std::ios::binary);
   if (!ostr)
   {
      std::cerr << "cannot open output file: " << argv[2] << std::endl;
      return 3;
   }
   
   Poco::MD5Engine md5;
   DigestOutputStream digest(md5, ostr);
   DeflatingOutputStream deflater(digest);
   StreamCopier::copyStream(istr, deflater);
   
   if (!ostr)
   {
      std::cerr << "error writing output file: " << argv[2] << std::endl;
      return 4;
   }
   
   deflater.close();
   digest.close();
   
   std::cout << Poco::DigestEngine::digestToHex(md5.digest()) << std::endl;
   
   return 0;
}
guenter
 
Posts: 1165
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests