We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 9 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
您想要客户端以流的形式下载文件吗? 怎么样download-curl 的惰性接口?
可能适合您的需求(或稍作调整)。
You want client-side downloading of files as a stream? How about download-curl's lazy interface?
Might be fine for your needs (or with a little tweaking).
一般来说,存在与延迟解析某些内容和验证相关的常见问题。当您收到包含“Content-Length”标头的 HTTP 响应时,您必须检查在连接关闭之前是否会读取所有数据。这意味着您不能说该响应有效,直到您读到最后。您的映射必须等待,然后处理整个结果。
为了避免您的库可能不那么严格,只检查标头的正确性和可能的数据的第一部分(如果分块或压缩)并返回长度小于或等于“Content-Length”的主体。或者您可以使用自己的块流,它返回成功或失败作为最后一个块。
另一种方法是在读取数据时牺牲 CPU 来处理响应(例如在 monad 内部),并且当下次读取没有有效数据时,您将中止之前的所有计算。
我建议也看看 http-monad 。从未使用过它,但我希望通过 monad 接口它可以实现最后一种方法。
In general there is common problem related with parsing something lazily with validation. When you receives HTTP response which contains "Content-Length" header you have to check that you'll read all that data before connection will be closed. That means that you can't say that response is valid until you'll read till the very end. And your mapping will have to wait and then process the whole result.
To avoid that your library may be less strict and check only header correctness and probably first part of data (in case chunked or compressed) and return body with length less or equal to "Content-Length". Or you may use your own chunk-stream which returns Success or Fail as the last chunk.
Another approach is to sacrifice your CPU for processing response as you read it (ex. inside monad) and when there is no valid data for next read you abort all your previous calculation.
I'd suggest to look at http-monad also. Never used it, but I hope that with monad interface it implements that last approach.