Changeset View
Changeset View
Standalone View
Standalone View
src/streams.h
Show First 20 Lines • Show All 550 Lines • ▼ Show 20 Lines | |||||
protected: | protected: | ||||
// read data from the source to fill the buffer | // read data from the source to fill the buffer | ||||
bool Fill() { | bool Fill() { | ||||
unsigned int pos = nSrcPos % vchBuf.size(); | unsigned int pos = nSrcPos % vchBuf.size(); | ||||
unsigned int readNow = vchBuf.size() - pos; | unsigned int readNow = vchBuf.size() - pos; | ||||
unsigned int nAvail = vchBuf.size() - (nSrcPos - nReadPos) - nRewind; | unsigned int nAvail = vchBuf.size() - (nSrcPos - nReadPos) - nRewind; | ||||
if (nAvail < readNow) readNow = nAvail; | if (nAvail < readNow) readNow = nAvail; | ||||
if (readNow == 0) return false; | if (readNow == 0) return false; | ||||
size_t read = fread((void *)&vchBuf[pos], 1, readNow, src); | size_t nBytes = fread((void *)&vchBuf[pos], 1, readNow, src); | ||||
if (read == 0) { | if (nBytes == 0) { | ||||
throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
feof(src) ? "CBufferedFile::Fill: end of file" | feof(src) ? "CBufferedFile::Fill: end of file" | ||||
: "CBufferedFile::Fill: fread failed"); | : "CBufferedFile::Fill: fread failed"); | ||||
} else { | } else { | ||||
nSrcPos += read; | nSrcPos += nBytes; | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
public: | public: | ||||
CBufferedFile(FILE *fileIn, uint64_t nBufSize, uint64_t nRewindIn, | CBufferedFile(FILE *fileIn, uint64_t nBufSize, uint64_t nRewindIn, | ||||
int nTypeIn, int nVersionIn) | int nTypeIn, int nVersionIn) | ||||
: nType(nTypeIn), nVersion(nVersionIn), nSrcPos(0), nReadPos(0), | : nType(nTypeIn), nVersion(nVersionIn), nSrcPos(0), nReadPos(0), | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |