1717from .abc import AbstractStreamWriter
1818from .helpers import (
1919 _SENTINEL ,
20+ DEFAULT_CHUNK_SIZE ,
2021 content_disposition_header ,
2122 guess_filename ,
2223 parse_mimetype ,
4344)
4445
4546TOO_LARGE_BYTES_BODY : Final [int ] = 2 ** 20 # 1 MB
46- READ_SIZE : Final [int ] = 2 ** 18 # 256 KiB
4747_CLOSE_FUTURES : set [asyncio .Future [None ]] = set ()
4848
4949
@@ -491,7 +491,7 @@ def _read_and_available_len(
491491
492492 Args:
493493 remaining_content_len: Optional limit on how many bytes to read in this operation.
494- If None, READ_SIZE will be used as the default chunk size.
494+ If None, DEFAULT_CHUNK_SIZE will be used as the default chunk size.
495495
496496 Returns:
497497 A tuple containing:
@@ -506,7 +506,11 @@ def _read_and_available_len(
506506 self ._set_or_restore_start_position ()
507507 size = self .size # Call size only once since it does I/O
508508 return size , self ._value .read (
509- min (READ_SIZE , size or READ_SIZE , remaining_content_len or READ_SIZE )
509+ min (
510+ DEFAULT_CHUNK_SIZE ,
511+ size or DEFAULT_CHUNK_SIZE ,
512+ remaining_content_len or DEFAULT_CHUNK_SIZE ,
513+ )
510514 )
511515
512516 def _read (self , remaining_content_len : int | None ) -> bytes :
@@ -515,7 +519,7 @@ def _read(self, remaining_content_len: int | None) -> bytes:
515519
516520 Args:
517521 remaining_content_len: Optional maximum number of bytes to read.
518- If None, READ_SIZE will be used as the default chunk size.
522+ If None, DEFAULT_CHUNK_SIZE will be used as the default chunk size.
519523
520524 Returns:
521525 A chunk of bytes read from the file object, respecting the
@@ -525,7 +529,7 @@ def _read(self, remaining_content_len: int | None) -> bytes:
525529 the initial _read_and_available_len call has been made.
526530
527531 """
528- return self ._value .read (remaining_content_len or READ_SIZE ) # type: ignore[no-any-return]
532+ return self ._value .read (remaining_content_len or DEFAULT_CHUNK_SIZE ) # type: ignore[no-any-return]
529533
530534 @property
531535 def size (self ) -> int | None :
@@ -628,9 +632,9 @@ async def write_with_length(
628632 None ,
629633 self ._read ,
630634 (
631- min (READ_SIZE , remaining_content_len )
635+ min (DEFAULT_CHUNK_SIZE , remaining_content_len )
632636 if remaining_content_len is not None
633- else READ_SIZE
637+ else DEFAULT_CHUNK_SIZE
634638 ),
635639 )
636640
@@ -756,7 +760,7 @@ def _read_and_available_len(
756760
757761 Args:
758762 remaining_content_len: Optional limit on how many bytes to read in this operation.
759- If None, READ_SIZE will be used as the default chunk size.
763+ If None, DEFAULT_CHUNK_SIZE will be used as the default chunk size.
760764
761765 Returns:
762766 A tuple containing:
@@ -775,7 +779,11 @@ def _read_and_available_len(
775779 self ._set_or_restore_start_position ()
776780 size = self .size
777781 chunk = self ._value .read (
778- min (READ_SIZE , size or READ_SIZE , remaining_content_len or READ_SIZE )
782+ min (
783+ DEFAULT_CHUNK_SIZE ,
784+ size or DEFAULT_CHUNK_SIZE ,
785+ remaining_content_len or DEFAULT_CHUNK_SIZE ,
786+ )
779787 )
780788 return size , chunk .encode (self ._encoding ) if self ._encoding else chunk .encode ()
781789
@@ -785,7 +793,7 @@ def _read(self, remaining_content_len: int | None) -> bytes:
785793
786794 Args:
787795 remaining_content_len: Optional maximum number of bytes to read.
788- If None, READ_SIZE will be used as the default chunk size.
796+ If None, DEFAULT_CHUNK_SIZE will be used as the default chunk size.
789797
790798 Returns:
791799 A chunk of bytes read from the file object and encoded using the payload's
@@ -797,7 +805,7 @@ def _read(self, remaining_content_len: int | None) -> bytes:
797805 the specified encoding (or UTF-8 if none was provided).
798806
799807 """
800- chunk = self ._value .read (remaining_content_len or READ_SIZE )
808+ chunk = self ._value .read (remaining_content_len or DEFAULT_CHUNK_SIZE )
801809 return chunk .encode (self ._encoding ) if self ._encoding else chunk .encode ()
802810
803811 def decode (self , encoding : str = "utf-8" , errors : str = "strict" ) -> str :
@@ -881,7 +889,7 @@ async def write_with_length(
881889 self ._set_or_restore_start_position ()
882890 loop_count = 0
883891 remaining_bytes = content_length
884- while chunk := self ._value .read (READ_SIZE ):
892+ while chunk := self ._value .read (DEFAULT_CHUNK_SIZE ):
885893 if loop_count > 0 :
886894 # Avoid blocking the event loop
887895 # if they pass a large BytesIO object
0 commit comments