tesseract  4.00.00dev
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 128 of file fileio.cpp.

129  : stream_(stream) {
130  fseek(stream_, 0, SEEK_END);
131  filesize_ = ftell(stream_);
132  fseek(stream_, 0, SEEK_SET);
133 }
voidpf stream
Definition: ioapi.h:39
#define SEEK_SET
Definition: ioapi.c:29
#define SEEK_END
Definition: ioapi.c:25

◆ InputBuffer() [2/2]

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

Definition at line 135 of file fileio.cpp.

136  : stream_(stream) {
137  fseek(stream_, 0, SEEK_END);
138  filesize_ = ftell(stream_);
139  fseek(stream_, 0, SEEK_SET);
140 }
voidpf stream
Definition: ioapi.h:39
#define SEEK_SET
Definition: ioapi.c:29
#define SEEK_END
Definition: ioapi.c:25

◆ ~InputBuffer()

tesseract::InputBuffer::~InputBuffer ( )

Definition at line 142 of file fileio.cpp.

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

Member Function Documentation

◆ CloseFile()

bool tesseract::InputBuffer::CloseFile ( )

Definition at line 162 of file fileio.cpp.

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

◆ Read()

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

Definition at line 148 of file fileio.cpp.

148  {
149  char buf[BUFSIZ + 1];
150  int l;
151  while ((l = fread(buf, 1, BUFSIZ, stream_)) > 0) {
152  if (ferror(stream_)) {
153  clearerr(stream_);
154  return false;
155  }
156  buf[l] = 0;
157  out->append(buf);
158  }
159  return true;
160 }
voidpf void * buf
Definition: ioapi.h:39

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