tesseract  3.05.02
tesseract::InputBuffer Class Reference

#include <fileio.h>

Public Member Functions

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

Detailed Description

Definition at line 57 of file fileio.h.

Constructor & Destructor Documentation

◆ InputBuffer() [1/2]

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

Definition at line 130 of file fileio.cpp.

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

◆ InputBuffer() [2/2]

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

Definition at line 137 of file fileio.cpp.

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

◆ ~InputBuffer()

tesseract::InputBuffer::~InputBuffer ( )

Definition at line 144 of file fileio.cpp.

144  {
145  if (stream_ != NULL) {
146  fclose(stream_);
147  }
148 }

Member Function Documentation

◆ CloseFile()

bool tesseract::InputBuffer::CloseFile ( )

Definition at line 164 of file fileio.cpp.

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

◆ Read()

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

Definition at line 150 of file fileio.cpp.

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

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