static void brotli_close(struct stream_encoded *stream) { struct br_enc_data *data = (struct br_enc_data *) stream->data; if (data) { BrotliStateCleanup(&data->br_stream); if (data->fdread != -1) { close(data->fdread); } if (data->need_free) { mem_free_if(data->output); } mem_free(data); stream->data = 0; } }
void QBrotliDecoder::decode() { if (m_pInputDevice == nullptr || m_pOutputDevice == nullptr) { emit onError("IO devices not set."); return; } if (!m_pInputDevice->isReadable()) { emit onError("Input not readable."); return; } if (!m_pOutputDevice->isWritable()) { emit onError("Output not writeable."); return; } BrotliState state; qint64 totalsize=-1; if (!m_pInputDevice->isSequential()) totalsize = m_pInputDevice->size(); BrotliStateInit(&state); int finish = 0; BrotliResult r; BrotliInput input = initInput(m_pInputDevice); BrotliOutput output = initOutput(m_pOutputDevice); for (;;) { r = BrotliDecompressStreaming(input,output,finish,&state); if (r==0) { //error emit onError("Decoding error."); break; } else if (r==1) { //done break; } if (totalsize!=-1) emit onProgress((double)m_pInputDevice->pos()/(double)totalsize); if (m_pInputDevice->atEnd()) finish=1; } emit onProgress(1.0); emit onDone(); BrotliStateCleanup(&state); }