LCOV - code coverage report
Current view: top level - common - compression_stream.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 4 4 100.0 %
Date: 2019-06-30 05:20:33 Functions: 2 2 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /** @file compression_stream.h
       2                 :            :  * @brief class wrapper around zlib
       3                 :            :  */
       4                 :            : /* Copyright (C) 2012 Dan Colish
       5                 :            :  * Copyright (C) 2012,2013,2014,2016 Olly Betts
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or modify
       8                 :            :  * it under the terms of the GNU General Public License as published by
       9                 :            :  * the Free Software Foundation; either version 2 of the License, or
      10                 :            :  * (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #ifndef XAPIAN_INCLUDED_COMPRESSION_STREAM_H
      23                 :            : #define XAPIAN_INCLUDED_COMPRESSION_STREAM_H
      24                 :            : 
      25                 :            : #include "internaltypes.h"
      26                 :            : #include <string>
      27                 :            : #include <zlib.h>
      28                 :            : 
      29                 :            : class CompressionStream {
      30                 :            :     int compress_strategy;
      31                 :            : 
      32                 :            :     size_t out_len;
      33                 :            : 
      34                 :            :     char* out;
      35                 :            : 
      36                 :            :     /// Zlib state object for deflating
      37                 :            :     z_stream* deflate_zstream;
      38                 :            : 
      39                 :            :     /// Zlib state object for inflating
      40                 :            :     z_stream* inflate_zstream;
      41                 :            : 
      42                 :            :     /// Allocate the zstream for deflating, if not already allocated.
      43                 :            :     void lazy_alloc_deflate_zstream();
      44                 :            : 
      45                 :            :     /// Allocate the zstream for inflating, if not already allocated.
      46                 :            :     void lazy_alloc_inflate_zstream();
      47                 :            : 
      48                 :            :   public:
      49                 :            :     /* Create a new CompressionStream object.
      50                 :            :      *
      51                 :            :      *  @param compress_strategy_       Z_DEFAULT_STRATEGY,
      52                 :            :      *                                  Z_FILTERED, Z_HUFFMAN_ONLY, or Z_RLE.
      53                 :            :      */
      54                 :     118704 :     explicit CompressionStream(int compress_strategy_ = Z_DEFAULT_STRATEGY)
      55                 :            :         : compress_strategy(compress_strategy_),
      56                 :            :           out_len(0),
      57                 :            :           out(NULL),
      58                 :            :           deflate_zstream(NULL),
      59                 :     118704 :           inflate_zstream(NULL)
      60                 :     118704 :     { }
      61                 :            : 
      62                 :            :     ~CompressionStream();
      63                 :            : 
      64                 :            :     const char* compress(const char* buf, size_t* p_size);
      65                 :            : 
      66                 :     472838 :     void decompress_start() { lazy_alloc_inflate_zstream(); }
      67                 :            : 
      68                 :            :     /** Returns true if this was the final chunk. */
      69                 :            :     bool decompress_chunk(const char* p, int len, std::string& buf);
      70                 :            : };
      71                 :            : 
      72                 :            : #endif // XAPIAN_INCLUDED_COMPRESSION_STREAM_H

Generated by: LCOV version 1.11