1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-30 22:29:56 +00:00

Ensures final few bytes of a CAS file aren't dropped.

This commit is contained in:
Thomas Harte 2017-12-23 19:54:42 -05:00
parent 0a079b0f94
commit cbba6a5595

View File

@ -52,12 +52,18 @@ CAS::CAS(const char *file_name) {
// Add a new chunk for the new incoming data.
active_file->chunks.emplace_back();
// Keep going until another header arrives.
// Keep going until another header arrives or the file ends.
while(std::memcmp(lookahead, header_signature, sizeof(header_signature)) && !file.eof()) {
active_file->chunks.back().push_back(lookahead[0]);
get_next(file, lookahead, 1);
}
// If the file ended, flush the lookahead.
if(file.eof()) {
for(int index = 0; index < 8; index++)
active_file->chunks.back().push_back(lookahead[index]);
}
switch(active_file->type) {
case Block::ASCII:
// ASCII files have as many chunks as necessary, the final one being back filled