Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StreamingMultipartFormDataParser. #3228

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

eulersIDcrisis
Copy link

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.

Still need to fix the tests and also improve Awaitable vs. None interface.
@eulersIDcrisis eulersIDcrisis marked this pull request as ready for review February 25, 2023 19:46
@bdarnell bdarnell added the web label Apr 8, 2023
@eulersIDcrisis
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants