| 87 | } |
| 88 | |
| 89 | void BinaryFileReader::ReadUntilEof() |
| 90 | { |
| 91 | std::wstring line; |
| 92 | while (std::getline(m_wifstream, line)) |
| 93 | AddLine(Str(line)); |
| 94 | |
| 95 | if (m_wifstream.eof()) |
| 96 | { |
| 97 | m_wifstream.clear(); // clear EOF condition |
| 98 | |
| 99 | // resync to end of file, even if the file shrunk |
| 100 | auto lastReadPosition = m_wifstream.tellg(); |
| 101 | m_wifstream.seekg(0, m_wifstream.end); |
| 102 | auto length = m_wifstream.tellg(); |
| 103 | if (length > lastReadPosition) |
| 104 | m_wifstream.seekg(lastReadPosition); |
| 105 | else if (length != lastReadPosition) |
| 106 | AddInternal(stringbuilder() << "file shrank, resynced at offset " << length); |
| 107 | } |
| 108 | else |
| 109 | { |
| 110 | // Some error other then EOF occured |
| 111 | AddInternal("Stopped tailing " + Str(m_filename).str()); |
| 112 | m_end = true; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | void BinaryFileReader::AddLine(const std::string& line) |
| 117 | { |