mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
Add Zstd compression support for ZIM format
This commit is contained in:
parent
a378acc0df
commit
6e85b27337
|
@ -59,9 +59,9 @@ Then pass `"CONFIG+=chinese_conversion_support"` to `qmake`
|
|||
|
||||
### Building with Zim dictionaries support
|
||||
|
||||
To add Zim and Slob formats support you need at first install lzma-dev package:
|
||||
To add Zim and Slob formats support you need at first install lzma-dev and zstd-dev packages:
|
||||
|
||||
sudo apt-get install liblzma-dev
|
||||
sudo apt-get install liblzma-dev libzstd-dev
|
||||
|
||||
Then pass `"CONFIG+=zim_support"` to `qmake`
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#ifdef MAKE_ZIM_SUPPORT
|
||||
#include "lzma.h"
|
||||
#include "zstd.h"
|
||||
#endif
|
||||
|
||||
#define CHUNK_SIZE 2048
|
||||
|
@ -131,4 +132,46 @@ char buf[CHUNK_SIZE];
|
|||
return str;
|
||||
}
|
||||
|
||||
string decompressZstd( const char *bufptr, unsigned length )
|
||||
{
|
||||
string str;
|
||||
char buf[CHUNK_SIZE];
|
||||
size_t res;
|
||||
// string err;
|
||||
ZSTD_DStream *zds;
|
||||
ZSTD_inBuffer in_buf = { bufptr, length, 0 };
|
||||
ZSTD_outBuffer out_buf = { buf, CHUNK_SIZE, 0 };
|
||||
|
||||
zds = ZSTD_createDStream();
|
||||
if( !zds )
|
||||
return str;
|
||||
|
||||
res = ZSTD_initDStream( zds );
|
||||
if( ZSTD_isError( res ) )
|
||||
{
|
||||
// err = string( ZSTD_getErrorName( res ) );
|
||||
ZSTD_freeDStream( zds );
|
||||
return str;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
out_buf.pos = 0;
|
||||
res = ZSTD_decompressStream( zds, &out_buf, &in_buf );
|
||||
if( ZSTD_isError( res ) )
|
||||
{
|
||||
// err = string( ZSTD_getErrorName( res ) );
|
||||
ZSTD_freeDStream( zds );
|
||||
return string();
|
||||
}
|
||||
|
||||
str.append( buf, out_buf.pos );
|
||||
}
|
||||
while( out_buf.pos >= out_buf.size );
|
||||
|
||||
ZSTD_freeDStream( zds );
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,6 +17,8 @@ string decompressBzip2( const char * bufptr, unsigned length );
|
|||
string decompressLzma2( const char * bufptr, unsigned length,
|
||||
bool raw_decoder = false );
|
||||
|
||||
string decompressZstd( const char * bufptr, unsigned length );
|
||||
|
||||
#endif
|
||||
|
||||
#endif // DECOMPRESS_HH
|
||||
|
|
|
@ -541,7 +541,7 @@ greaterThan(QT_MAJOR_VERSION, 4) {
|
|||
|
||||
CONFIG( zim_support ) {
|
||||
DEFINES += MAKE_ZIM_SUPPORT
|
||||
LIBS += -llzma
|
||||
LIBS += -llzma -lzstd
|
||||
}
|
||||
|
||||
!CONFIG( no_extra_tiff_handler ) {
|
||||
|
|
2049
winlibs/include/zstd.h
Normal file
2049
winlibs/include/zstd.h
Normal file
File diff suppressed because it is too large
Load diff
BIN
winlibs/lib/libzstd.a
Normal file
BIN
winlibs/lib/libzstd.a
Normal file
Binary file not shown.
5
zim.cc
5
zim.cc
|
@ -72,7 +72,7 @@ class ZimFile;
|
|||
|
||||
enum CompressionType
|
||||
{
|
||||
Default = 0, None, Zlib, Bzip2, Lzma2
|
||||
Default = 0, None, Zlib, Bzip2, Lzma2, Zstd
|
||||
};
|
||||
|
||||
/// Zim file header
|
||||
|
@ -350,6 +350,9 @@ string ZimFile::getClusterData( quint32 cluster_nom )
|
|||
else
|
||||
if( compressionType == Lzma2 )
|
||||
decompressedData = decompressLzma2( data.constData(), data.size() );
|
||||
else
|
||||
if( compressionType == Zstd )
|
||||
decompressedData = decompressZstd( data.constData(), data.size() );
|
||||
else
|
||||
return string();
|
||||
|
||||
|
|
Loading…
Reference in a new issue