tornado icon indicating copy to clipboard operation
tornado copied to clipboard

Add StreamingMultipartFormDataParser.

Open eulersIDcrisis opened this issue 3 years ago • 1 comments

Add a basic multipart/form-data parser to tornado that can stream to files instead of in-memory as the existing call to: tornado.httputil.parse_multipart_form_data does.

eulersIDcrisis avatar Feb 05 '23 21:02 eulersIDcrisis

One way this PR could be improved is if tornado offered an API of sorts that permitted partial searching as data comes in. For example, something like this (some details omitted):

class BufferedStream:
    def __init__(self):
        self._chunks = deque()

    def append(chunk: bytes):
        self._chunks.append(chunk)

    def read_next_until(self, match: bytes) -> Optional[bytes]:
        # 

Calls to read_next_until() could return either:

  1. Non-empty bytes chunk --> Common case.
  2. Empty bytes chunk --> Implies a match.
  3. None --> Implies not enough data (partial match)

If this class were implemented properly, this could avoid some spurious copies.

eulersIDcrisis avatar May 04 '24 05:05 eulersIDcrisis