From 7aa58b2c2c766b51bb697c69d808235a1df6fac8 Mon Sep 17 00:00:00 2001 From: charlessoft Date: Sun, 30 Oct 2016 22:42:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0m=5Fopened(false),=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DIsOpened=E9=9A=8F=E6=9C=BA=E8=BF=94=E5=9B=9Et?= =?UTF-8?q?rue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/OFDPage.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OFDPage.cxx b/src/OFDPage.cxx index 33eb31b..e0a626f 100644 --- a/src/OFDPage.cxx +++ b/src/OFDPage.cxx @@ -12,7 +12,7 @@ using namespace tinyxml2; using namespace ofd; OFDPage::OFDPage(OFDDocument *ofdDocument, uint64_t id, const std::string &filename) - : m_ofdDocument(ofdDocument), m_id(id), m_filename(filename) { + : m_ofdDocument(ofdDocument), m_id(id), m_filename(filename), m_opened(false) { m_attributes.clear(); } From 0afa34c91cb7a184218af9b64cdb188bdac36782 Mon Sep 17 00:00:00 2001 From: charlessoft Date: Sun, 30 Oct 2016 22:56:50 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=AF=BBzip=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/OFDPackage.cxx | 58 +++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/src/OFDPackage.cxx b/src/OFDPackage.cxx index 94efd86..684c081 100644 --- a/src/OFDPackage.cxx +++ b/src/OFDPackage.cxx @@ -69,34 +69,54 @@ size_t OFDPackage::getZipFileSize(zip* handle, const char *filename){ std::tuple OFDPackage::GetFileContent(const std::string &filename) const { bool ok = false; std::string fileContent; + zip_int64_t len = 0; + size_t sum = 0; + char buf[100] = {0}; std::map::const_iterator it = m_files.find(filename); if ( it != m_files.end() ){ std::string filename = it->first; size_t filesize = it->second; - - zip_file *file = zip_fopen(m_zip, filename.c_str(), ZIP_FL_NOCASE); - char *content = new char[filesize]; - const zip_int64_t did_read = zip_fread(file, content, filesize); - if ( did_read > 0 ){ - if ( strlen(content) < filesize ){ - LOG(WARNING) << "File " << filename << " is truncated. from " << filesize << " to " << strlen(content); - } - if ( strlen(content) > filesize ){ - LOG(WARNING) << "File readed " << strlen(content) << " more then " << filesize; - content[filesize] = '\0'; - } - - if ( VLOG_IS_ON(5) ){ - VLOG(5) << "\n[ " << filename << " ]\n\n" << content << "\n\n--------\n\n"; + zip_file *file = zip_fopen(m_zip,filename.c_str(), ZIP_FL_NOCASE); + if(file){ + while( sum != filesize ){ + len = zip_fread(file,buf,100); + if( len < 0 ){ + LOG(ERROR) << "zip_fread error\n"; + zip_fclose(file); + return std::make_tuple("",ok); + } + fileContent.append(buf,len); + sum += len; } - - fileContent = std::string(content); + zip_fclose(file); + LOG(INFO) << "filesize:" << filesize << " fileContent size:" << fileContent.size(); ok = true; - delete[] content; } - zip_fclose(file); + + + //zip_file *file = zip_fopen(m_zip, filename.c_str(), ZIP_FL_NOCASE); + //char *content = new char[filesize]; + //const zip_int64_t did_read = zip_fread(file, content, filesize); + //if ( did_read > 0 ){ + // if ( strlen(content) < filesize ){ + // LOG(WARNING) << "File " << filename << " is truncated. from " << filesize << " to " << strlen(content); + // } + // if ( strlen(content) > filesize ){ + // LOG(WARNING) << "File readed " << strlen(content) << " more then " << filesize; + // content[filesize] = '\0'; + // } + + // if ( VLOG_IS_ON(5) ){ + // VLOG(5) << "\n[ " << filename << " ]\n\n" << content << "\n\n--------\n\n"; + // } + + // fileContent = std::string(content); + // ok = true; + // delete[] content; + //} + //zip_fclose(file); } else { LOG(ERROR) << filename << " is not exist in zipfile."; }