X-Git-Url: https://git.pterodactylus.net/?p=ecparse.git;a=blobdiff_plain;f=CollectionReader.cpp;fp=CollectionReader.cpp;h=f58e5bc7e2fae72df140313f52a09fc3f9f84a2d;hp=4aa51732bfb5e18f45d1f45beed6fb8785b271fe;hb=ee4c05de3061d1d7abfd1710823442cbc0cfbf46;hpb=88e69cc8c710fa06616219bcf347c4e9b89550d3 diff --git a/CollectionReader.cpp b/CollectionReader.cpp index 4aa5173..f58e5bc 100644 --- a/CollectionReader.cpp +++ b/CollectionReader.cpp @@ -71,6 +71,18 @@ ED2KLink* CollectionReader::getNextLink() { return NULL; } +bool CollectionReader::ensureBufferCapacity(size_t byteCount) { + while (!readerInput->isEOF() && (growingBuffer.getRemaining() < byteCount)) { + GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] only %d bytes remaning, need at least %d, reading more bytes.\n", __FILE__, __LINE__, growingBuffer.getRemaining(), byteCount); + readMoreBytes(); + } + if (readerInput->isEOF() && (growingBuffer.getRemaining() < byteCount)) { + GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] need %d more bytes, but file is EOF.\n", __FILE__, __LINE__, (byteCount - growingBuffer.getRemaining())); + return false; + } + return true; +} + void CollectionReader::readMoreBytes() { char buffer[1024]; size_t readBytes;