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

how to safety close file stream #407

Open
MisterChangRay opened this issue Feb 3, 2024 · 6 comments
Open

how to safety close file stream #407

MisterChangRay opened this issue Feb 3, 2024 · 6 comments

Comments

@MisterChangRay
Copy link

i wanna write a file download server.

as Response code as following

        return Response(
          200,
          body: File(file.path!).openRead(),
          headers: headers,
        );

as u see, i send file as stream for return;

but, i has a proplem, on browser download large file , if user cancel download process, the file has never be closed!

so, how to get the socket error for close the file stream?

@MisterChangRay
Copy link
Author

MisterChangRay commented Feb 3, 2024

i saw the code in file shelf_io.dart at line 254

  return httpResponse
      .addStream(response.read())
      .then((_) => httpResponse.close());

this then call be stream read end, if exception has occur, the call not be execute.

and i search on google, find the HttpResonse has a done method, this method has called by any case;

so , can expose the httpResonse.done method?

@kevmoo
Copy link
Member

kevmoo commented Feb 3, 2024

@MisterChangRay – ooo...this might be a bug, honestly!

@MisterChangRay
Copy link
Author

@MisterChangRay – ooo...this might be a bug, honestly!

can fixed the bug in next version?

@MisterChangRay
Copy link
Author

@kevmoo

@wengxianxun
Copy link

i need too, tk

@pedia
Copy link

pedia commented Mar 21, 2024

I think #399 is same issue.

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

No branches or pull requests

4 participants