tornado
tornado copied to clipboard
Add StreamingMultipartFormDataParser.
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.
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:
- Non-empty bytes chunk --> Common case.
- Empty bytes chunk --> Implies a match.
-
None--> Implies not enough data (partial match)
If this class were implemented properly, this could avoid some spurious copies.