| 62 | } |
| 63 | |
| 64 | int BinFileReader::Count() { |
| 65 | std::ifstream fin(path_, std::ios::in | std::ios::binary); |
| 66 | CHECK(fin.is_open()) << "Cannot create file " << path_; |
| 67 | int count = 0; |
| 68 | while (true) { |
| 69 | size_t len; |
| 70 | char magic[4]; |
| 71 | fin.read(reinterpret_cast<char*>(magic), sizeof(magic)); |
| 72 | if (!fin.good()) break; |
| 73 | if (magic[2] == 1) { |
| 74 | fin.read(reinterpret_cast<char*>(&len), sizeof(len)); |
| 75 | if (!fin.good()) break; |
| 76 | fin.seekg(len, std::ios_base::cur); |
| 77 | if (!fin.good()) break; |
| 78 | } |
| 79 | fin.read(reinterpret_cast<char*>(&len), sizeof(len)); |
| 80 | if (!fin.good()) break; |
| 81 | fin.seekg(len, std::ios_base::cur); |
| 82 | if (!fin.good()) break; |
| 83 | count++; |
| 84 | } |
| 85 | fin.close(); |
| 86 | return count; |
| 87 | } |
| 88 | |
| 89 | void BinFileReader::SeekToFirst() { |
| 90 | bufsize_ = 0; |