I use zlib library to compress data from strings and get compressed data also in strings. I load and unload compressed data using fstream. The problem is that sometimes it happens that when a line is written to a file, it becomes one byte larger and I cannot understand why this happens. I checked a row with compressed data and it has the correct size, and I can get decompressed data from it in program without writing in file. Because in the file it turns out one character more, I can no longer decompress this data. When reading such a line from a file, it is accordingly one character more as shown in a text editor.
There are "Sel" says what string size is 82.
This is example of my function which puts compressed string into file:
std::fstream file(filename, std::ios::out, std::ios::binary);
if (!file.is_open()) {
std::cout << "Unable to open file: " << filename << std::endl;
return;
}
std::stringstream someData;
...puts data in "someData"...
std::string compressedData = Compress_String(someData.str());
std::cout << "Comp string: " << compressedData << std::endl;
std::cout << "Comp size: " << compressedData.size() << std::endl;
file << compressedData;
file.close();