mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-12-18 11:28:51 +08:00
4523ce9f7d
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@526 d0cd1f9f-072b-0410-8dd7-cf729c803f20
37 lines
847 B
C++
37 lines
847 B
C++
// Copyright 2008 Google Inc.
|
|
// All Rights Reserved.
|
|
// Author: ahmadab@google.com (Ahmad Abdulkader)
|
|
//
|
|
// input_file_buffer.h: Declarations of a class for an object that
|
|
// represents an input file buffer.
|
|
|
|
#include <string>
|
|
#include "input_file_buffer.h"
|
|
|
|
namespace tesseract {
|
|
// default and only contsructor
|
|
InputFileBuffer::InputFileBuffer(const string &file_name)
|
|
: file_name_(file_name) {
|
|
fp_ = NULL;
|
|
}
|
|
|
|
// virtual destructor
|
|
InputFileBuffer::~InputFileBuffer() {
|
|
if (fp_ != NULL) {
|
|
fclose(fp_);
|
|
}
|
|
}
|
|
|
|
// Read the specified number of bytes to the specified input buffer
|
|
int InputFileBuffer::Read(void *buffer, int bytes_to_read) {
|
|
// open the file if necessary
|
|
if (fp_ == NULL) {
|
|
fp_ = fopen(file_name_.c_str(), "rb");
|
|
if (fp_ == NULL) {
|
|
return 0;
|
|
}
|
|
}
|
|
return fread(buffer, 1, bytes_to_read, fp_);
|
|
}
|
|
}
|