在Haskell中,Lazy ByteString的调用长度会将整个字符串强制到内存中吗? [英] In Haskell, will calling length on a Lazy ByteString force the entire string into memory?

查看:89
本文介绍了在Haskell中,Lazy ByteString的调用长度会将整个字符串强制到内存中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用懒惰的字节读取大量数据流,并且想知道解析它时是否至少有X个字节可用。也就是说,我想知道字节串是否至少有X字节长。



会调用 length 导致整个流得到加载,因此击败了使用懒惰字节串的目的?



如果是,那么后续将是:如何判断它是否至少有X字节没有加载整个流?



编辑:最初我问在阅读文件的上下文,但明白,有更好的方式来确定文件大小。我需要的终极解决方案不应该依赖懒惰的bytestring源代码。


长度。取x


I am reading a large data stream using lazy bytestrings, and want to know if at least X more bytes is available while parsing it. That is, I want to know if the bytestring is at least X bytes long.

Will calling length on it result in the entire stream getting loaded, hence defeating the purpose of using the lazy bytestring?

If yes, then the followup would be: How to tell if it has at least X bytes without loading the entire stream?

EDIT: Originally I asked in the context of reading files but understand that there are better ways to determine filesize. Te ultimate solution I need however should not depend on the lazy bytestring source.

解决方案

Yes.

length . take x.

这篇关于在Haskell中,Lazy ByteString的调用长度会将整个字符串强制到内存中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆