// that aren't yet in memory, so this is necessary.
ulong bufferLength = bufferSize();
+
while(data.size() - replace > bufferLength)
bufferLength += bufferSize();
buffer = aboutToOverwrite;
+ // In case we've already reached the end of file...
+
+ buffer.resize(bytesRead);
+
// Ok, here's the main loop. We want to loop until the read fails, which
// means that we hit the end of the file.
- while(bytesRead != 0) {
+ while(!buffer.isEmpty()) {
// Seek to the current read position and read the data that we're about
// to overwrite. Appropriately increment the readPosition.
// writePosition.
seek(writePosition);
- fwrite(buffer.data(), sizeof(char), bufferLength, d->file);
- writePosition += bufferLength;
+ fwrite(buffer.data(), sizeof(char), buffer.size(), d->file);
+ writePosition += buffer.size();
// Make the current buffer the data that we read in the beginning.