Skip to content

Replace form-data with Node streams - #1324

Merged
Benjamin Christopher Simmonds (benibenj) merged 4 commits into
microsoft:mainfrom
jakebailey:remove-form-data
Sep 4, 2026
Merged

Benjamin Christopher Simmonds (benibenj) merged 4 commits into
microsoft:mainfrom
jakebailey:remove-form-data

Conversation

@jakebailey

Copy link
Copy Markdown
Member

This can be replaced with a bit of code in the repo, deleting 8 prod deps.

I though it would be more but no, headers were already being manually constructed, so it's all just boilerplate with Node's streaming. There's more "handle errors in streams" code than actual form code, and then way more testing than actual form and error code.

Comment thread src/multipart.ts Outdated
yield lineBreak;
}

yield `--${boundary}--${lineBreak}`;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still boggles my mind that this is how multipart form-data works

Keep the request lifecycle and released file handles the same as they were
with form-data:

- Do not remove the error listener in runWithStreamError once the operation
  settles. A stream error arriving afterwards was an unhandled 'error' event,
  which terminates the process.
- Create the stream with autoDestroy: false. Readable.from emits 'close' after
  'end', and typed-rest-client ends the request on both, so every successful
  upload called req.end() twice. CombinedStream never emitted 'close'.
- Destroy the parts once the stream is done with them. Both file streams open
  eagerly, so a request that failed before consuming the form kept the package
  locked, which made the temporary directory cleanup in withTemporaryPackage
  fail and hid the original error.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@benibenj
Benjamin Christopher Simmonds (benibenj) merged commit ae9f2b7 into microsoft:main Sep 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants