Skip to content
This repository was archived by the owner on Nov 18, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 39 additions & 19 deletions src/OFDPackage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,34 +69,54 @@ size_t OFDPackage::getZipFileSize(zip* handle, const char *filename){
std::tuple<std::string, bool> 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<std::string, size_t>::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.";
}
Expand Down
2 changes: 1 addition & 1 deletion src/OFDPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down