//---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- // File : Writer.cpp Data : 02.06.15 Versione : 1.6f1 // Contenuto : Implementazione della classe Writer. // Scrittura di file di testo con codifica UTF-8. // // // Modifiche : 02.06.15 DS Creazione modulo. // // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "/EgtDev/Include/EGnWriter.h" #include "/EgtDev/Include/EgtStringConverter.h" #include "/EgtDev/Extern/Zlib/Include/zlib.h" using namespace std ; //---------------------------------------------------------------------------- bool Writer::Init( const string& sFileOut, bool bCompressed) { // apertura del file di uscita m_OutFile = gzopen_w( stringtoW( sFileOut), ( bCompressed ? "wb" : "wbT")) ; if ( m_OutFile == nullptr) return false ; const int DIM_BUFFER = 65536 ; if ( gzbuffer( m_OutFile, DIM_BUFFER) != Z_OK) return false ; if ( bCompressed) { const int COMPR_LEVEL = 3 ; // 0 = no compression ... 9 = max compression if ( gzsetparams( m_OutFile, COMPR_LEVEL, Z_DEFAULT_STRATEGY) != Z_OK) return false ; } return true ; } //---------------------------------------------------------------------------- bool Writer::Close( void) { if ( m_OutFile != nullptr) { bool bOk = ( gzclose( m_OutFile) == Z_OK) ; m_OutFile = nullptr ; return bOk ; } return true ; } //---------------------------------------------------------------------------- bool Writer::OutText( const string& sText, bool bEndL) { // verifico apertura file if ( m_OutFile == nullptr) return false ; // scrivo stringa if ( gzputs( m_OutFile, sText.c_str()) == Z_ERRNO) return false ; // se richiesto, scrivo fine linea if ( bEndL) { if ( gzputs( m_OutFile, "\r\n") == Z_ERRNO) return false ; } return true ; }