tesseract  4.1.0
tesseract::InputBuffer Class Reference

#include <fileio.h>

Public Member Functions

 InputBuffer (FILE *stream)
 
 InputBuffer (FILE *stream, size_t size)
 
 ~InputBuffer ()
 
bool Read (std::string *out)
 
bool CloseFile ()
 

Detailed Description

Definition at line 55 of file fileio.h.

Constructor & Destructor Documentation

tesseract::InputBuffer::InputBuffer ( FILE *  stream)
explicit

Definition at line 134 of file fileio.cpp.

135  : stream_(stream) {
136  fseek(stream_, 0, SEEK_END);
137  filesize_ = ftell(stream_);
138  fseek(stream_, 0, SEEK_SET);
139 }
tesseract::InputBuffer::InputBuffer ( FILE *  stream,
size_t  size 
)

Definition at line 141 of file fileio.cpp.

142  : stream_(stream) {
143  fseek(stream_, 0, SEEK_END);
144  filesize_ = ftell(stream_);
145  fseek(stream_, 0, SEEK_SET);
146 }
tesseract::InputBuffer::~InputBuffer ( )

Definition at line 148 of file fileio.cpp.

148  {
149  if (stream_ != nullptr) {
150  fclose(stream_);
151  }
152 }

Member Function Documentation

bool tesseract::InputBuffer::CloseFile ( )

Definition at line 168 of file fileio.cpp.

168  {
169  int ret = fclose(stream_);
170  stream_ = nullptr;
171  return ret == 0;
172 }
bool tesseract::InputBuffer::Read ( std::string *  out)

Definition at line 154 of file fileio.cpp.

154  {
155  char buf[BUFSIZ + 1];
156  int l;
157  while ((l = fread(buf, 1, BUFSIZ, stream_)) > 0) {
158  if (ferror(stream_)) {
159  clearerr(stream_);
160  return false;
161  }
162  buf[l] = 0;
163  out->append(buf);
164  }
165  return true;
166 }

The documentation for this class was generated from the following files: