| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 362c307 commit 8b53f3c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -546,10 +546,11 @@ static void InternalModuleReadFile(const FunctionCallbackInfo<Value>& args) { | |||
| 546 | 546 | return; | |
| 547 | 547 | } | |
| 548 | 548 | ||
| 549 | + const size_t kBlockSize = 32 << 10; | ||
| 549 | 550 | std::vector<char> chars; | |
| 550 | 551 | int64_t offset = 0; | |
| 551 | - for (;;) { | ||
| 552 | - const size_t kBlockSize = 32 << 10; | ||
| 552 | + ssize_t numchars; | ||
| 553 | + do { | ||
| 553 | 554 | const size_t start = chars.size(); | |
| 554 | 555 | chars.resize(start + kBlockSize); | |
| 555 | 556 | ||
@@ -558,32 +559,27 @@ static void InternalModuleReadFile(const FunctionCallbackInfo<Value>& args) { | |||
| 558 | 559 | buf.len = kBlockSize; | |
| 559 | 560 | ||
| 560 | 561 | uv_fs_t read_req; | |
| 561 | - const ssize_t numchars = | ||
| 562 | - uv_fs_read(loop, &read_req, fd, &buf, 1, offset, nullptr); | ||
| 562 | + numchars = uv_fs_read(loop, &read_req, fd, &buf, 1, offset, nullptr); | ||
| 563 | 563 | uv_fs_req_cleanup(&read_req); | |
| 564 | 564 | ||
| 565 | 565 | CHECK_GE(numchars, 0); | |
| 566 | - if (static_cast<size_t>(numchars) < kBlockSize) { | ||
| 567 | - chars.resize(start + numchars); | ||
| 568 | - break; | ||
| 569 | - } | ||
| 570 | 566 | offset += numchars; | |
| 571 | - } | ||
| 567 | + } while (static_cast<size_t>(numchars) == kBlockSize); | ||
| 572 | 568 | ||
| 573 | 569 | uv_fs_t close_req; | |
| 574 | 570 | CHECK_EQ(0, uv_fs_close(loop, &close_req, fd, nullptr)); | |
| 575 | 571 | uv_fs_req_cleanup(&close_req); | |
| 576 | 572 | ||
| 577 | 573 | size_t start = 0; | |
| 578 | - if (chars.size() >= 3 && 0 == memcmp(&chars[0], "\xEF\xBB\xBF", 3)) { | ||
| 574 | + if (offset >= 3 && 0 == memcmp(&chars[0], "\xEF\xBB\xBF", 3)) { | ||
| 579 | 575 | start = 3; // Skip UTF-8 BOM. | |
| 580 | 576 | } | |
| 581 | 577 | ||
| 582 | 578 | Local<String> chars_string = | |
| 583 | 579 | String::NewFromUtf8(env->isolate(), | |
| 584 | 580 | &chars[start], | |
| 585 | 581 | String::kNormalString, | |
| 586 | - chars.size() - start); | ||
| 582 | + offset - start); | ||
| 587 | 583 | args.GetReturnValue().Set(chars_string); | |
| 588 | 584 | } | |
| 589 | 585 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments