grive2/libgrive/src/http/Download.cc

79 lines
1.9 KiB
C++
Raw Normal View History

/*
grive: an GPL program to sync a local directory with Google Drive
Copyright (C) 2012 Wan Wai Ho
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation version 2
of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "Download.hh"
2012-05-02 20:17:16 +04:00
// #include "util/SignalHandler.hh"
2012-05-13 11:27:58 +04:00
#include "Error.hh"
2012-06-10 11:36:37 +04:00
#include "util/Crypt.hh"
2012-05-13 11:27:58 +04:00
// boost headers
#include <boost/throw_exception.hpp>
#include <boost/exception/errinfo_api_function.hpp>
#include <boost/exception/errinfo_at_line.hpp>
#include <boost/exception/errinfo_errno.hpp>
#include <boost/exception/errinfo_file_handle.hpp>
#include <boost/exception/errinfo_file_name.hpp>
#include <boost/exception/errinfo_file_open_mode.hpp>
#include <boost/exception/info.hpp>
#include <cassert>
#include <new>
#include <signal.h>
2012-05-13 11:27:58 +04:00
namespace gr { namespace http {
Download::Download( const std::string& filename ) :
2012-05-27 10:55:26 +04:00
m_file( filename, 0600 ),
2012-06-10 11:36:37 +04:00
m_crypt( new crypt::MD5 )
{
}
Download::Download( const std::string& filename, NoChecksum ) :
2012-06-10 11:36:37 +04:00
m_file( filename, 0600 )
{
}
2012-06-10 11:36:37 +04:00
Download::~Download()
{
}
2012-05-09 18:25:42 +04:00
void Download::Clear()
{
// no need to do anything
}
std::string Download::Finish() const
{
2012-06-10 11:36:37 +04:00
return m_crypt.get() != 0 ? m_crypt->Get() : "" ;
}
std::size_t Download::OnData( void *data, std::size_t count )
{
assert( data != 0 ) ;
2012-06-10 11:36:37 +04:00
if ( m_crypt.get() != 0 )
m_crypt->Write( data, count ) ;
2013-04-28 14:40:21 +04:00
return m_file.Write( static_cast<char*>(data), count ) ;
}
2012-05-13 11:27:58 +04:00
} } // end of namespace