| 392 | } |
| 393 | |
| 394 | void ConvertStream(FILE* fin, FILE* fout) { |
| 395 | const int BUFFER_SIZE = 1024 * 1024; |
| 396 | std::string buffer(BUFFER_SIZE, '\0'); |
| 397 | ConverterStream stream(converter); |
| 398 | |
| 399 | while (!feof(fin)) { |
| 400 | size_t length = fread(&buffer[0], sizeof(char), buffer.size(), fin); |
| 401 | if (length == 0) { |
| 402 | break; |
| 403 | } |
| 404 | measurement.inputBytes += length; |
| 405 | WarnIfStreamChunkContainsVariationSelector(buffer.data(), length); |
| 406 | |
| 407 | const auto convertStart = std::chrono::steady_clock::now(); |
| 408 | const bool isFinalChunk = length < buffer.size() && feof(fin); |
| 409 | const std::string converted = |
| 410 | isFinalChunk ? stream.Finish({buffer.data(), length}) |
| 411 | : stream.ConvertChunk({buffer.data(), length}); |
| 412 | measurement.convertMs += DurationToMilliseconds( |
| 413 | std::chrono::steady_clock::now() - convertStart); |
| 414 | measurement.outputBytes += converted.size(); |
| 415 | const auto writeStart = std::chrono::steady_clock::now(); |
| 416 | fputs(converted.c_str(), fout); |
| 417 | if (!noFlush) { |
| 418 | fflush(fout); |
| 419 | } |
| 420 | measurement.writeMs += DurationToMilliseconds( |
| 421 | std::chrono::steady_clock::now() - writeStart); |
| 422 | if (isFinalChunk) { |
| 423 | return; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | const auto convertStart = std::chrono::steady_clock::now(); |
| 428 | const std::string& converted = stream.Finish(); |
| 429 | measurement.convertMs += DurationToMilliseconds( |
| 430 | std::chrono::steady_clock::now() - convertStart); |
| 431 | measurement.outputBytes += converted.size(); |
| 432 | const auto writeStart = std::chrono::steady_clock::now(); |
| 433 | fputs(converted.c_str(), fout); |
| 434 | if (!noFlush) { |
| 435 | fflush(fout); |
| 436 | } |
| 437 | measurement.writeMs += DurationToMilliseconds( |
| 438 | std::chrono::steady_clock::now() - writeStart); |
| 439 | } |
| 440 | |
| 441 | void ConvertLineByLine() { |
| 442 | PrintInteractiveStdinHint(); |
no test coverage detected