Commit 804e8a3
[s3] Add range_chunk_size param to read using multiple GET requests (#887)
* Add range_chunk_size parameter for S3 reading optimization
This commit adds a new `range_chunk_size` parameter to the S3 reader that allows
reading large files in smaller chunks. This is useful when you only need to read
small portions of large S3 files, as it prevents S3-compatible storage systems
from queueing up the entire file internally.
Key changes:
- Added range_chunk_size parameter to smart_open.s3.open() and related classes
- Modified _SeekableRawReader to support chunked reading with proper boundary handling
- Added comprehensive test coverage including adversarial testing for retry logic
- Improved error handling for edge cases (negative offsets, empty files, etc.)
When range_chunk_size is None (default), behavior is unchanged - single request
for the whole file to minimize per-request costs on S3.
* Update help.txt
* Doc update
:house: Remote-Dev: homespace
* Lint violations
:house: Remote-Dev: homespace
* Possible help text fix?
:house: Remote-Dev: homespace
* Switch to bytearray for accumulating bytes
:house: Remote-Dev: homespace
* Refactoring based on one suggested by @ddelange
🏠 Remote-Dev: homespace
* Delete whitespace
🏠 Remote-Dev: homespace
* Introduce close(), closed and simplify read()
* Simplify _open_body
* Further simplify _open_body and amend docstring
* Avoid calling _open_body when end of file is reached
* Ensure expected_position is always defined
* Ensure proper handling of InvalidRange
* Account for negative seek on empty file
* Amend docstring
* Typo
* Don't request beyond known content length
---------
Co-authored-by: Max Bolingbroke <maxb@anthropic.com>1 parent 7a36a8f commit 804e8a3
3 files changed
Lines changed: 391 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
236 | 251 | | |
237 | 252 | | |
238 | 253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
320 | 321 | | |
321 | 322 | | |
322 | 323 | | |
| 324 | + | |
323 | 325 | | |
324 | 326 | | |
325 | 327 | | |
| |||
366 | 368 | | |
367 | 369 | | |
368 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
369 | 386 | | |
370 | 387 | | |
371 | 388 | | |
| |||
397 | 414 | | |
398 | 415 | | |
399 | 416 | | |
| 417 | + | |
400 | 418 | | |
401 | 419 | | |
402 | 420 | | |
| |||
462 | 480 | | |
463 | 481 | | |
464 | 482 | | |
| 483 | + | |
465 | 484 | | |
466 | 485 | | |
467 | 486 | | |
468 | 487 | | |
469 | 488 | | |
| 489 | + | |
470 | 490 | | |
471 | 491 | | |
472 | 492 | | |
| |||
536 | 556 | | |
537 | 557 | | |
538 | 558 | | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
539 | 563 | | |
540 | 564 | | |
541 | 565 | | |
542 | 566 | | |
543 | 567 | | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
544 | 576 | | |
545 | 577 | | |
546 | 578 | | |
| |||
620 | 652 | | |
621 | 653 | | |
622 | 654 | | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
628 | 662 | | |
629 | 663 | | |
630 | 664 | | |
| |||
639 | 673 | | |
640 | 674 | | |
641 | 675 | | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
665 | 715 | | |
666 | | - | |
| 716 | + | |
667 | 717 | | |
668 | 718 | | |
669 | 719 | | |
| |||
710 | 760 | | |
711 | 761 | | |
712 | 762 | | |
| 763 | + | |
713 | 764 | | |
714 | 765 | | |
715 | 766 | | |
| |||
721 | 772 | | |
722 | 773 | | |
723 | 774 | | |
| 775 | + | |
724 | 776 | | |
725 | 777 | | |
726 | 778 | | |
| |||
0 commit comments