summaryrefslogtreecommitdiff
path: root/poppler/FlateEncoder.h
blob: 1e79c2cfdfbe690dafb081bd64383e5a438747a5 (plain)
1
2
3
4
5
6
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//========================================================================
//
// FlateEncoder.h
//
// Copyright (C) 2016, William Bader <williambader@hotmail.com>
// Copyright (C) 2018, 2019 Albert Astals Cid <aacid@kde.org>
//
// This file is under the GPLv2 or later license
//
//========================================================================

#ifndef FLATEENCODE_H
#define FLATEENCODE_H

#include "poppler-config.h"
#include <cstdio>
#include <cstdlib>
#include <cstddef>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <cstring>
#include <cctype>
#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);
  ~FlateEncoder();
  StreamKind getKind() const override { return strWeird; }
  void reset() override;
  int getChar() override
    { return (outBufPtr >= outBufEnd && !fillBuf()) ? EOF : (*outBufPtr++ & 0xff); }
  int lookChar() override
    { return (outBufPtr >= outBufEnd && !fillBuf()) ? EOF : (*outBufPtr & 0xff); }
  GooString *getPSFilter(int psLevel, const char *indent) override { return nullptr; }
  bool isBinary(bool last = true) override { return true; }
  bool isEncoder() override { return true; }

private:

  static const int inBufSize = 16384;
  static const int outBufSize = inBufSize;
  unsigned char inBuf[ inBufSize ];
  unsigned char outBuf[ outBufSize ];
  unsigned char *outBufPtr;
  unsigned char *outBufEnd;
  bool inBufEof;
  bool outBufEof;
  z_stream zlib_stream;

  bool fillBuf();
};

#endif