Skip to content

feat: support stream uploads to Synapse#428

Merged
SgtPooki merged 3 commits intofilecoin-project:masterfrom
shrirajpawar4:feat/support-stream-to-syanapse
May 4, 2026
Merged

feat: support stream uploads to Synapse#428
SgtPooki merged 3 commits intofilecoin-project:masterfrom
shrirajpawar4:feat/support-stream-to-syanapse

Conversation

@shrirajpawar4
Copy link
Copy Markdown
Contributor

@shrirajpawar4 shrirajpawar4 commented Apr 30, 2026

Summary

addresses part of #325.

Adds ReadableStream<Uint8Array> support to the shared Synapse upload helpers so callers with pre-generated CAR files can stream upload data without first loading the whole CAR into memory.

Changes

  • Add SynapseUploadData = Uint8Array | ReadableStream<Uint8Array>
  • Update uploadToSynapse() and executeUpload() to accept SynapseUploadData
  • Pass upload data directly through to synapse.storage.upload() without buffering
  • Export the new upload data type from the public upload/type surface
  • Add unit coverage proving stream objects are forwarded unchanged
  • Update the CAR upload example to show streaming from disk with Readable.toWeb(createReadStream(...))

Notes

This intentionally does not implement true CAR creation streaming from #288, and it does not add byte-level progress callbacks from #326. This PR only covers uploading an already-created CAR as a stream. Will create separet PR for #326

Testing

pnpm run typecheck
pnpm exec vitest run --project unit src/test/unit/synapse-service.test.ts src/test/unit/upload-validation.test.ts
pnpm test

Full pnpm test passed locally:

- 37 test files passed
- 372 tests passed
- 11 skipped

@FilOzzy FilOzzy added team/filecoin-pin "Filecoin Pin" project is a stakeholder for this work. team/fs-wg FOC working group is a stakeholder for this work, and thus wants to track it on their project board. labels Apr 30, 2026
@FilOzzy FilOzzy added this to FOC Apr 30, 2026
@github-project-automation github-project-automation Bot moved this to 📌 Triage in FOC Apr 30, 2026
Comment thread src/core/payments/README.md Outdated
@rvagg
Copy link
Copy Markdown
Member

rvagg commented Apr 30, 2026

This looks pretty good, tightly scoped and solves the specific issue.

There's one additional thing you could do with this @shrirajpawar4, you look in src/import/import.ts you'll see we await readFile(options.filePath) for filecoin-pin import; we should be streaming that out. And I think the change is pretty simple there, we stat() separately and we even read the root CID from the CAR separately (using a stream).

@rvagg
Copy link
Copy Markdown
Member

rvagg commented Apr 30, 2026

@shrirajpawar4 have a look at #287 which was a draft of a previous attempt and it does a few more things. I think the code might have moved on from that PR but it had a bit more, including streaming the temp car for add operations which you can do as well, and there's some minor changes to the docs in there but as per my comment we can't over-promise because we still cache things on disk and add is still bad in the browser because it makes a temp CAR in memory before streaming it out. So don't overpromise like the original text in there.
Also watch mocks when readFile is replaced with createReadStream, I think we need to add stat in there.

But, if you'd prefer to land this one first and do a follow-up with the second batch we can do that; this is a decent start but it shouldn't be hard to go a bit further.

@shrirajpawar4
Copy link
Copy Markdown
Contributor Author

Thanks @rvagg . I applied the README suggestion and updated filecoin-pin import to stream the CAR file from disk instead of reading it fully into memory before upload.

I kept the broader add / server / action streaming work out of this PR so this can stay focused on #325; I can handle that as a follow up after this lands.

@BigLep BigLep moved this from 📌 Triage to 🔎 Awaiting review in FOC May 1, 2026
Copy link
Copy Markdown
Collaborator

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

short and sweet, nice PR. Just a few things to touch up and i'm good with it.

Comment thread src/core/payments/README.md
Comment thread src/import/import.ts Outdated
Comment thread src/test/mocks/synapse-mocks.ts Outdated
@github-project-automation github-project-automation Bot moved this from 🔎 Awaiting review to ⌨️ In Progress in FOC May 1, 2026
@shrirajpawar4
Copy link
Copy Markdown
Contributor Author

@SgtPooki made changes ser.

@HavenCTO
Copy link
Copy Markdown

HavenCTO commented May 2, 2026

Approve this unblocks the streaming contract we need, thanks for the implementation!

Copy link
Copy Markdown
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

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

lgtm but we'll just have to make sure t he linked issue stays open so we can track the other part of t his

@shrirajpawar4 shrirajpawar4 requested a review from SgtPooki May 4, 2026 09:49
@shrirajpawar4
Copy link
Copy Markdown
Contributor Author

@rvagg yes works, will close out the issue in next PR.

@BigLep BigLep moved this from ⌨️ In Progress to ✔️ Approved by reviewer in FOC May 4, 2026
@SgtPooki SgtPooki merged commit 63ab93c into filecoin-project:master May 4, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from ✔️ Approved by reviewer to 🎉 Done in FOC May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team/filecoin-pin "Filecoin Pin" project is a stakeholder for this work. team/fs-wg FOC working group is a stakeholder for this work, and thus wants to track it on their project board.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants