1//========================================================================
2//
3// FlateEncoder.h
4//
5// Copyright (C) 2016, William Bader <williambader@hotmail.com>
6// Copyright (C) 2018, 2019, 2021 Albert Astals Cid <aacid@kde.org>
7//
8// This file is under the GPLv2 or later license
9//
10//========================================================================
11
12#ifndef FLATEENCODE_H
13#define FLATEENCODE_H
14
15#include "poppler-config.h"
16#include <cstdio>
17#include <cstdlib>
18#include <cstddef>
19#ifdef HAVE_UNISTD_H
20# include <unistd.h>
21#endif
22#include <cstring>
23#include <cctype>
24#include "goo/gmem.h"
25#include "goo/gfile.h"
26#include "Error.h"
27#include "Object.h"
28#include "Decrypt.h"
29
30#include "Stream.h"
31
32extern "C" {
33#include <zlib.h>
34}
35
36//------------------------------------------------------------------------
37// FlateEncoder
38//------------------------------------------------------------------------
39
40class FlateEncoder : public FilterStream
41{
42public:
43 explicit FlateEncoder(Stream *strA);
44 ~FlateEncoder() override;
45 StreamKind getKind() const override { return strWeird; }
46 void reset() override;
47 int getChar() override { return (outBufPtr >= outBufEnd && !fillBuf()) ? EOF : (*outBufPtr++ & 0xff); }
48 int lookChar() override { return (outBufPtr >= outBufEnd && !fillBuf()) ? EOF : (*outBufPtr & 0xff); }
49 GooString *getPSFilter(int psLevel, const char *indent) override { return nullptr; }
50 bool isBinary(bool last = true) const override { return true; }
51 bool isEncoder() const override { return true; }
52
53private:
54 static const int inBufSize = 16384;
55 static const int outBufSize = inBufSize;
56 unsigned char inBuf[inBufSize];
57 unsigned char outBuf[outBufSize];
58 unsigned char *outBufPtr;
59 unsigned char *outBufEnd;
60 bool inBufEof;
61 bool outBufEof;
62 z_stream zlib_stream;
63
64 bool fillBuf();
65};
66
67#endif
68

source code of poppler/poppler/FlateEncoder.h