In Haskell, will calling length on a Lazy ByteString force the entire string into memory?

Posted by me2 on Stack Overflow See other posts from Stack Overflow or by me2
Published on 2010-03-25T15:54:09Z Indexed on 2010/03/25 16:13 UTC
Read the original article Hit count: 404

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about haskell

Related posts about lazy