| 656 | return { |
| 657 | __proto__: null, |
| 658 | next() { |
| 659 | if (done || remaining === 0) { |
| 660 | if (!done) { |
| 661 | done = true; |
| 662 | cleanup(); |
| 663 | } |
| 664 | return { done: true, value: undefined }; |
| 665 | } |
| 666 | const toRead = remaining > 0 ? |
| 667 | MathMin(readSize, remaining) : readSize; |
| 668 | const buf = Buffer.allocUnsafe(toRead); |
| 669 | let bytesRead; |
| 670 | try { |
| 671 | bytesRead = binding.read(fd, buf, 0, toRead, pos) || 0; |
| 672 | } catch (err) { |
| 673 | done = true; |
| 674 | cleanup(); |
| 675 | throw err; |
| 676 | } |
| 677 | if (bytesRead === 0) { |
| 678 | done = true; |
| 679 | cleanup(); |
| 680 | return { done: true, value: undefined }; |
| 681 | } |
| 682 | if (pos >= 0) pos += bytesRead; |
| 683 | if (remaining > 0) remaining -= bytesRead; |
| 684 | const chunk = bytesRead < toRead ? |
| 685 | buf.subarray(0, bytesRead) : buf; |
| 686 | return { done: false, value: [chunk] }; |
| 687 | }, |
| 688 | return() { |
| 689 | if (!done) { |
| 690 | done = true; |