[英]Need an use case example for stream response in ChicagoBoss
ChicageBoss controller API has this ChicageBoss控制器API拥有此
{stream, Generator::function(), Acc0} {stream,Generator :: function(),Acc0}
Stream a response to the client using HTTP chunked encoding. 使用HTTP分块编码将响应流式传输到客户端。 For each chunk, the Generator function is passed an accumulator (initally Acc0) and should return either {output, Data, Acc1} or done. 对于每个块,Generator函数将传递一个累加器(最初为Acc0),并且应返回{output,Data,Acc1}或done。
I am wondering what is the use case for this? 我想知道这是什么用例? There are others like Json, output. 还有其他类似Json的输出。 When will this stream
be useful? 当将这种stream
是有用的?
Can someone present an use case in real world? 有人可以在现实世界中提出用例吗?
Serving large files for download might be the most straight-forward use case. 提供大文件供下载可能是最直接的用例。
You could argue that there are also other ways to serve files so that users can download them, but these might have other disadvantages: 您可能会争辩说,还有其他提供文件的方式,以便用户可以下载文件,但是这些方式可能还有其他缺点:
{output, BinaryContent, CustomHeader}
. 对于小文件,您可以读取文件的内容,然后将其返回为{output, BinaryContent, CustomHeader}
。 But that might become tricky if you want to serve large files like disk images. 但是,如果要提供磁盘映像之类的大文件,这可能会变得棘手。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.