Use readnext() method to read even 1st chunk of text files to perform appropriate end of chunk truncation to eol. Wont affect uncunked files

This commit is contained in:
Jean-Francois Dockes 2015-01-21 16:03:26 +01:00
parent aa36cda20c
commit 5cbae3985b

View file

@ -71,17 +71,11 @@ bool MimeHandlerText::set_document_file(const string& mt, const string &fn)
ps *= KB;
m_paging = true;
}
// Note: size_t is guaranteed unsigned, so max if ps is -1
m_pagesz = size_t(ps);
string reason;
LOGDEB(("calling file_to_string\n"));
// file_to_string() takes pagesz == size_t(-1) to mean read all.
if (!file_to_string(fn, m_text, 0, m_pagesz, &reason)) {
LOGERR(("MimeHandlerText: can't read file: %s\n", reason.c_str()));
if (!readnext())
return false;
}
LOGDEB(("file_to_string OK\n"));
m_offs = m_text.length();
}
if (!m_forPreview) {
string md5, xmd5;
MD5String(m_text, md5);
@ -178,7 +172,8 @@ bool MimeHandlerText::readnext()
}
// If possible try to adjust the chunk to end right after a line
// Don't do this for the last chunk
// Don't do this for the last chunk. Last chunk of exactly the
// page size might be unduly split, no big deal
if (m_text.length() == m_pagesz) {
string::size_type pos = m_text.find_last_of("\n\r");
if (pos != string::npos && pos != 0) {