EpcTools
An event based multi-threaded C++ development framework.
ebzip2.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2009-2019 Brian Waters
3 * Copyright (c) 2019 Sprint
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 
18 #ifndef __ebzip2_h_included
19 #define __ebzip2_h_included
20 
21 #include "estring.h"
22 #include "eerror.h"
23 #include "bzlib.h"
24 
26 DECLARE_ERROR_ADVANCED4(EBZip2Error_ReadOpen);
27 DECLARE_ERROR_ADVANCED4(EBZip2Error_WriteOpen);
28 DECLARE_ERROR_ADVANCED2(EBZip2Error_Bzip2ReadInit);
29 DECLARE_ERROR_ADVANCED2(EBZip2Error_Bzip2WriteInit);
30 DECLARE_ERROR_ADVANCED2(EBZip2Error_Bzip2Read);
31 DECLARE_ERROR_ADVANCED2(EBZip2Error_Bzip2Write);
33 
45 class EBzip2
46 {
47 public:
49  enum Operation
50  {
51  bz2opNone,
52  bz2opRead,
53  bz2opWrite
54  };
56 
58  EBzip2();
60  ~EBzip2();
61 
63  EString &setFileName(cpStr filename)
64  {
65  m_filename = filename;
66  return m_filename;
67  }
69  EString &getFileName() { return m_filename; }
70 
72  cChar setTerminator(cChar c)
73  {
74  m_term = c;
75  return getTerminator();
76  }
78  cChar getTerminator() { return m_term; }
79 
81  Int getLastError() { return m_bzerror; }
83  static cpStr getErrorDesc(Int e);
84 
86  ULongLong getBytesIn() { return m_bytesin; }
88  ULongLong getBytesOut() { return m_bytesout; }
89 
91  Bool isOpen() { return m_fh ? True : False; }
92 
94  Void readOpen(cpStr filename);
96  Void writeOpen(cpStr filename);
98  Void close();
100  Int read(pUChar pbuf, Int length);
102  Int readLine(pStr pbuf, Int length);
104  Int write(pUChar pbuf, Int length);
105 
106 private:
107  EString m_filename;
108  FILE *m_fh;
109  BZFILE *m_bfh;
110  Char m_term;
111 
112  Int m_bzerror;
113  Operation m_operation;
114  ULongLong m_bytesin;
115  ULongLong m_bytesout;
116  Int m_len;
117  Int m_ofs;
118  UChar m_buf[65536];
119 };
120 
121 #endif // #define __ebzip2_h_included
EBzip2::getTerminator
cChar getTerminator()
Gets the line terminator used by readLine().
Definition: ebzip2.h:78
eerror.h
Defines base class for exceptions and declaration helper macros.
EBzip2::getBytesOut
ULongLong getBytesOut()
The number of compressed bytes associated with the file written.
Definition: ebzip2.h:88
DECLARE_ERROR_ADVANCED2
#define DECLARE_ERROR_ADVANCED2(__e__)
Declares exception class derived from EError with an Int as a constructor parameter and developer def...
Definition: eerror.h:67
EBzip2::getErrorDesc
static cpStr getErrorDesc(Int e)
Gets the description of the specified error value.
Definition: ebzip2.cpp:223
True
#define True
True.
Definition: ebase.h:25
EBzip2::getBytesIn
ULongLong getBytesIn()
The number of uncompressed bytes associated with the file written.
Definition: ebzip2.h:86
EBzip2
Definition: ebzip2.h:45
DECLARE_ERROR_ADVANCED4
#define DECLARE_ERROR_ADVANCED4(__e__)
Declares exception class derived from EError with an const char* as a constructor parameter and devel...
Definition: eerror.h:83
False
#define False
False.
Definition: ebase.h:27
EBzip2::~EBzip2
~EBzip2()
Class destructor.
Definition: ebzip2.cpp:81
EBzip2::readLine
Int readLine(pStr pbuf, Int length)
Read a decompressed line terminated by the supplied terminator.
Definition: ebzip2.cpp:180
EBzip2::write
Int write(pUChar pbuf, Int length)
Write the specified number of decompressed bytes.
Definition: ebzip2.cpp:218
EBzip2::isOpen
Bool isOpen()
True - the file is open, False - the file is closed.
Definition: ebzip2.h:91
EBzip2::setFileName
EString & setFileName(cpStr filename)
Sets the file name that to be operated on.
Definition: ebzip2.h:63
EBzip2::close
Void close()
Close the file.
Definition: ebzip2.cpp:111
EBzip2::EBzip2
EBzip2()
Class constructor.
Definition: ebzip2.cpp:70
EBzip2::read
Int read(pUChar pbuf, Int length)
Read a specified number of decompressed bytes.
Definition: ebzip2.cpp:151
EBzip2::getLastError
Int getLastError()
Gets the last error value that occurred.
Definition: ebzip2.h:81
EBzip2::setTerminator
cChar setTerminator(cChar c)
Sets the line terminator used by readLine().
Definition: ebzip2.h:72
EString
String class.
Definition: estring.h:30
EBzip2::getFileName
EString & getFileName()
Gets the file name that to be operated on.
Definition: ebzip2.h:69
EBzip2::writeOpen
Void writeOpen(cpStr filename)
Open the file for writing.
Definition: ebzip2.cpp:106
estring.h
Encapsulates and extends a std::string object.
EBzip2::readOpen
Void readOpen(cpStr filename)
Open the file for reading.
Definition: ebzip2.cpp:86