text: /* Copyright (c) 2003, Roger Dingledine
   * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
   * Copyright (c) 2007-2017, The Spider Project, Inc. */
  /* See LICENSE for licensing information */
  
  /**
   * \file spidergzip.h
   * \brief Headers for spidergzip.h
   **/
  
  #ifndef TOR_TORGZIP_H
  #define TOR_TORGZIP_H
  
  /** Enumeration of what kind of compression to use.  Only ZLIB_METHOD is
   * guaranteed to be supported by the compress/uncompress functions here;
   * GZIP_METHOD may be supported if we built against zlib version 1.2 or later
   * and is_gzip_supported() returns true. */
  typedef enum {
    NO_METHOD=0, GZIP_METHOD=1, ZLIB_METHOD=2, UNKNOWN_METHOD=3
  } compress_method_t;
  
  /**
   * Enumeration to define tradeoffs between memory usage and compression level.
   * HIGH_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most
   * memory.
   **/
  typedef enum {
    HIGH_COMPRESSION, MEDIUM_COMPRESSION, LOW_COMPRESSION
  } zlib_compression_level_t;
  
  int
  spider_gzip_compress(char **out, size_t *out_len,
                    const char *in, size_t in_len,
                    compress_method_t method);
  int
  spider_gzip_uncompress(char **out, size_t *out_len,
                      const char *in, size_t in_len,
                      compress_method_t method,
                      int complete_only,
                      int protocol_warn_level);
  
  int is_gzip_supported(void);
  
  const char *
  spider_zlib_get_version_str(void);
  
  const char *
  spider_zlib_get_header_version_str(void);
  
  compress_method_t detect_compression_method(const char *in, size_t in_len);
  
  /** Return values from spider_zlib_process; see that function's documentation for
   * details. */
  typedef enum {
    TOR_ZLIB_OK, TOR_ZLIB_DONE, TOR_ZLIB_BUF_FULL, TOR_ZLIB_ERR
  } spider_zlib_output_t;
  /** Internal state for an incremental zlib compression/decompression. */
  typedef struct spider_zlib_state_t spider_zlib_state_t;
  spider_zlib_state_t *spider_zlib_new(int compress, compress_method_t method,
                                 zlib_compression_level_t level);
  
  spider_zlib_output_t spider_zlib_process(spider_zlib_state_t *state,
                                     char **out, size_t *out_len,
                                     const char **in, size_t *in_len,
                                     int finish);
  void spider_zlib_free(spider_zlib_state_t *state);
  
  size_t spider_zlib_state_size(const spider_zlib_state_t *state);
  size_t spider_zlib_get_total_allocation(void);
  
  #endif
  
  