Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt: add debug log and more friendly error message #2039

Merged
merged 4 commits into from
Dec 27, 2024
Merged
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
26 changes: 18 additions & 8 deletions src/dict/utils/indexedzip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data )
return (size_t)zip.read( &data.front(), data.size() ) == data.size();

case ZipFile::Deflated: {
// Now do the deflation
// Decompress the data using the zlib library

QByteArray compressedData = zip.read( header.compressedSize );

Expand All @@ -94,9 +94,7 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data )

data.resize( header.uncompressedSize );

z_stream stream;

memset( &stream, 0, sizeof( stream ) );
z_stream stream = {};

stream.next_in = (Bytef *)compressedData.data();
stream.avail_in = compressedData.size();
Expand All @@ -108,17 +106,29 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data )
return false;
}

if ( inflate( &stream, Z_FINISH ) != Z_STREAM_END ) {
qDebug( "Not zstream end!" );
int ret = inflate( &stream, Z_FINISH );
xiaoyifang marked this conversation as resolved.
Show resolved Hide resolved
if ( ret != Z_STREAM_END ) {
qDebug() << "Not zstream end! Stream total_in:" << stream.total_in << "total_out:" << stream.total_out
<< "msg:" << ( stream.msg ? stream.msg : "none" );

data.clear();

inflateEnd( &stream );
int endRet = inflateEnd( &stream );
if ( endRet != Z_OK ) {
qDebug() << "inflateEnd failed after inflate! msg:" << ( stream.msg ? stream.msg : "none" );
}

return false;
}

inflateEnd( &stream );
ret = inflateEnd( &stream );
if ( ret != Z_OK ) {
qDebug() << "inflateEnd failed! msg:" << ( stream.msg ? stream.msg : "none" );

data.clear();

return false;
}

return true;
}
Expand Down
Loading