MCPcopy Create free account
hub / github.com/audacity/audacity / zipfileDeflate

Function zipfileDeflate

lib-src/sqlite/shell.c:6864–6900  ·  view source on GitHub ↗

** Buffer aIn (size nIn bytes) contains uncompressed data. This function ** compresses it and sets (*ppOut) to point to a buffer containing the ** compressed data. The caller is responsible for eventually calling ** sqlite3_free() to release buffer (*ppOut). Before returning, (*pnOut) ** is set to the size of buffer (*ppOut) in bytes. ** ** If no error occurs, SQLITE_OK is returned. Otherwise, an

Source from the content-addressed store, hash-verified

6862** case.
6863*/
6864static int zipfileDeflate(
6865 const u8 *aIn, int nIn, /* Input */
6866 u8 **ppOut, int *pnOut, /* Output */
6867 char **pzErr /* OUT: Error message */
6868){
6869 int rc = SQLITE_OK;
6870 sqlite3_int64 nAlloc;
6871 z_stream str;
6872 u8 *aOut;
6873
6874 memset(&str, 0, sizeof(str));
6875 str.next_in = (Bytef*)aIn;
6876 str.avail_in = nIn;
6877 deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
6878
6879 nAlloc = deflateBound(&str, nIn);
6880 aOut = (u8*)sqlite3_malloc64(nAlloc);
6881 if( aOut==0 ){
6882 rc = SQLITE_NOMEM;
6883 }else{
6884 int res;
6885 str.next_out = aOut;
6886 str.avail_out = nAlloc;
6887 res = deflate(&str, Z_FINISH);
6888 if( res==Z_STREAM_END ){
6889 *ppOut = aOut;
6890 *pnOut = (int)str.total_out;
6891 }else{
6892 sqlite3_free(aOut);
6893 *pzErr = sqlite3_mprintf("zipfile: deflate() error");
6894 rc = SQLITE_ERROR;
6895 }
6896 deflateEnd(&str);
6897 }
6898
6899 return rc;
6900}
6901
6902
6903/*

Callers 2

zipfileUpdateFunction · 0.85
zipfileStepFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected