2012-12-03 51 views
0

嗨,我是黑莓10平臺的新手。我正在開發一個應用程序來解壓縮使用GZip壓縮的文件。我正在尋找解壓縮與GZip壓縮的文件夾。GZip in Blackberry 10

回答

1

我有同樣的問題,我通過添加下面的方法

gUncompress(const QByteArray &data) 
{ 
    qDebug()<<"Reached Guncompress"; 
    qDebug()<<"size="<<data.size(); 
    if (data.size() <= 4) { 
     qWarning("gUncompress: Input data is truncated"); 
     return QByteArray(); 
    } 

    QByteArray result; 

    int ret; 
    z_stream strm; 
    static const int CHUNK_SIZE = 1024; 
    char out[CHUNK_SIZE]; 

    /* allocate inflate state */ 
    strm.zalloc = Z_NULL; 
    strm.zfree = Z_NULL; 
    strm.opaque = Z_NULL; 
    strm.avail_in = data.size(); 
    strm.next_in = (Bytef*)(data.data()); 

    ret = inflateInit2(&strm, 15 + 32); // gzip decoding 
    if (ret != Z_OK) 
     return QByteArray(); 

    // run inflate() 
    do { 
     strm.avail_out = CHUNK_SIZE; 
     strm.next_out = (Bytef*)(out); 

     ret = inflate(&strm, Z_NO_FLUSH); 
     Q_ASSERT(ret != Z_STREAM_ERROR); // state not clobbered 

     switch (ret) { 
     case Z_NEED_DICT: 
      ret = Z_DATA_ERROR;  // and fall through 
     case Z_DATA_ERROR: 
     case Z_MEM_ERROR: 
      (void)inflateEnd(&strm); 
      return QByteArray(); 
     } 

     result.append(out, CHUNK_SIZE - strm.avail_out); 
    } while (strm.avail_out == 0); 

    // clean up and return 
    inflateEnd(&strm); 
    return result; 
} 

我認爲這將解決您的問題解決了這個問題