Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/misc/sqlar.c # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / misc / sqlar.c` 126 lines ยท 3898 bytes Raw Blame History 1 /* 2 ** 2017-12-17 3 ** 4 ** The author disclaims copyright to this source code. In place of 5 ** a legal notice, here is a blessing: 6 ** 7 ** May you do good and not evil. 8 ** May you find forgiveness for yourself and forgive others. 9 ** May you share freely, never taking more than you give. 10 ** 11 ****************************************************************************** 12 ** 13 ** Utility functions sqlar_compress() and sqlar_uncompress(). Useful 14 ** for working with sqlar archives and used by the shell tool's built-in 15 ** sqlar support. 16 */ 17 #include "sqlite3ext.h" 18 SQLITE_EXTENSION_INIT1 19 #include 20 #include 21 22 /* 23 ** Implementation of the "sqlar_compress(X)" SQL function. 24 ** 25 ** If the type of X is SQLITE_BLOB, and compressing that blob using 26 ** zlib utility function compress() yields a smaller blob, return the 27 ** compressed blob. Otherwise, return a copy of X. 28 ** 29 ** SQLar uses the "zlib format" for compressed content. The zlib format 30 ** contains a two-byte identification header and a four-byte checksum at 31 ** the end. This is different from ZIP which uses the raw deflate format. 32 ** 33 ** Future enhancements to SQLar might add support for new compression formats. 34 ** If so, those new formats will be identified by alternative headers in the 35 ** compressed data. 36 */ 37 static void sqlarCompressFunc( 38 sqlite3_context *context, 39 int argc, 40 sqlite3_value **argv 41 ){ 42 assert( argc==1 ); 43 if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){ 44 const Bytef *pData = sqlite3_value_blob(argv[0]); 45 uLong nData = sqlite3_value_bytes(argv[0]); 46 uLongf nOut = compressBound(nData); 47 Bytef *pOut; 48 49 pOut = (Bytef*)sqlite3_malloc64(nOut); 50 if( pOut==0 ){ 51 sqlite3_result_error_nomem(context); 52 return; 53 }else{ 54 if( Z_OK!=compress(pOut, &nOut, pData, nData) ){ 55 sqlite3_result_error(context, "error in compress()", -1); 56 }else if( nOut