tesseract  4.0.0-1-g2a2b
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

◆ InputBuffer() [1/2]

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

Definition at line 129 of file fileio.cpp.

130  : stream_(stream) {
131  fseek(stream_, 0, SEEK_END);
132  filesize_ = ftell(stream_);
133  fseek(stream_, 0, SEEK_SET);
134 }

◆ InputBuffer() [2/2]

tesseract::InputBuffer::InputBuffer ( FILE *  stream,
size_t  size 
)

Definition at line 136 of file fileio.cpp.

137  : stream_(stream) {
138  fseek(stream_, 0, SEEK_END);
139  filesize_ = ftell(stream_);
140  fseek(stream_, 0, SEEK_SET);
141 }

◆ ~InputBuffer()

tesseract::InputBuffer::~InputBuffer ( )

Definition at line 143 of file fileio.cpp.

143  {
144  if (stream_ != nullptr) {
145  fclose(stream_);
146  }
147 }

Member Function Documentation

◆ CloseFile()

bool tesseract::InputBuffer::CloseFile ( )

Definition at line 163 of file fileio.cpp.

163  {
164  int ret = fclose(stream_);
165  stream_ = nullptr;
166  return ret == 0;
167 }

◆ Read()

bool tesseract::InputBuffer::Read ( std::string *  out)

Definition at line 149 of file fileio.cpp.

149  {
150  char buf[BUFSIZ + 1];
151  int l;
152  while ((l = fread(buf, 1, BUFSIZ, stream_)) > 0) {
153  if (ferror(stream_)) {
154  clearerr(stream_);
155  return false;
156  }
157  buf[l] = 0;
158  out->append(buf);
159  }
160  return true;
161 }

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