FlateEncoder.h 1.77 KB
Newer Older
1 2 3 4 5
//========================================================================
//
// FlateEncoder.h
//
// Copyright (C) 2016, William Bader <williambader@hotmail.com>
6
// Copyright (C) 2018, 2019 Albert Astals Cid <aacid@kde.org>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
//
// This file is under the GPLv2 or later license
//
//========================================================================

#ifndef FLATEENCODE_H
#define FLATEENCODE_H

#include "poppler-config.h"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#include <ctype.h>
#include "goo/gmem.h"
#include "goo/gfile.h"
#include "Error.h"
#include "Object.h"
#include "Decrypt.h"

#include "Stream.h"

extern "C" {
#include <zlib.h>
}

//------------------------------------------------------------------------
// FlateEncoder
//------------------------------------------------------------------------

class FlateEncoder: public FilterStream {
public:

  FlateEncoder(Stream *strA);
Albert Astals Cid's avatar
Albert Astals Cid committed
44
  ~FlateEncoder();
45
  StreamKind getKind() const override { return strWeird; }
Albert Astals Cid's avatar
Albert Astals Cid committed
46 47
  void reset() override;
  int getChar() override
48
    { return (outBufPtr >= outBufEnd && !fillBuf()) ? EOF : (*outBufPtr++ & 0xff); }
Albert Astals Cid's avatar
Albert Astals Cid committed
49
  int lookChar() override
50
    { return (outBufPtr >= outBufEnd && !fillBuf()) ? EOF : (*outBufPtr & 0xff); }
51
  GooString *getPSFilter(int psLevel, const char *indent) override { return nullptr; }
52 53
  bool isBinary(bool last = true) override { return true; }
  bool isEncoder() override { return true; }
54 55 56 57 58

private:

  static const int inBufSize = 16384;
  static const int outBufSize = inBufSize;
59 60 61 62
  unsigned char inBuf[ inBufSize ];
  unsigned char outBuf[ outBufSize ];
  unsigned char *outBufPtr;
  unsigned char *outBufEnd;
63 64
  bool inBufEof;
  bool outBufEof;
65 66
  z_stream zlib_stream;

67
  bool fillBuf();
68 69 70
};

#endif