Skip to content

Stream buffering in cupertino_http StreamedRequest #997

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

Open
Vovcharaa opened this issue Jul 30, 2023 · 2 comments
Open

Stream buffering in cupertino_http StreamedRequest #997

Vovcharaa opened this issue Jul 30, 2023 · 2 comments
Assignees
Labels
needs-info Additional information needed from the issue author package:cupertino_http Issues related to package:cupertino_http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@Vovcharaa
Copy link

Related #974
StreamQueue is buffering everything it can consume before sending it to the remote.
This still prevents tracking upload progress or sending large files.

ncb.NSInputStream _streamToNSInputStream(Stream<List<int>> stream) {
const maxReadAheadSize = 4096;
final queue = StreamQueue(stream);
final port = ReceivePort();

static Future<(bool, Stream<List<int>>)> _hasData(
Stream<List<int>> stream) async {
final queue = StreamQueue(stream);
while (await queue.hasNext && (await queue.peek).isEmpty) {
await queue.next;
}
return (await queue.hasNext, queue.rest);
}

@Vovcharaa Vovcharaa added package:cupertino_http Issues related to package:cupertino_http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jul 30, 2023
@Vovcharaa
Copy link
Author

@brianquinlan Perhaps, I misunderstood how StreamController(sync: true) is working.
I want to be able to send data into the StreamingRequest sink with knowledge of how much of the data is sent to the server. But I can't track progress if something is buffering my data before it is sent to the server.
When I am sending chunks of data with an artificial delay between them, I can see these chunks on the server as they are sent. So streaming request is definitely working, but not as I expected it will be.
Is it actually possible to track uploading progress in StreamedRequest?

@brianquinlan
Copy link
Collaborator

From #974:
Could you include the stream that you are sending? AFAIK, _hasData is only buffering the first non-empty List in the stream.

_streamToNSInputStream is only providing data when requested to by the Apple's client implementation and is, in my experience, providing less data than requested.

I don't think that you can accurately track uploading progress using StreamedRequest unless the request is "large" and the input stream emits List<int> whose size is significantly less than the total request size.

How much data are you sending on how many List<int>s are in your Stream?

@brianquinlan brianquinlan added the needs-info Additional information needed from the issue author label May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-info Additional information needed from the issue author package:cupertino_http Issues related to package:cupertino_http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants