Is there a limit for stream length in c#?

2019-05-17 19:44发布

I need to read a stream in this way:

using(HttpWebResponse response = (HttpWebResponse)request.getResponse())
{
  using(Stream answer = response.getResponseStream())
  {
    // waiting for a while to read next
  }
}

However, I don't know the stream length. According Fiddler the stream length is greater than 15,000,000 bytes.

Is there a length limit?

标签: c# stream
4条回答
做个烂人
2楼-- · 2019-05-17 20:24

Stream.Length is a long, so its (positive) limit is 2^63. It should be OK for you.

查看更多
你好瞎i
3楼-- · 2019-05-17 20:35

Yes, it's 9,223,372,036,854,775,807 bytes (8,388,608 terrabytes)

查看更多
Explosion°爆炸
4楼-- · 2019-05-17 20:36

I have to read into memory a 2.9 Gbytes encrypted file and decrypt it. During the read into memory ( Using Bouncy Castle ), I get a Stream Length Limit Exception running in 64 bit mode. If I decrypt the file from the encrypted data file to another file, then read it into memory using a FileReader, I do not get the error and end up with the entire file in memory. I really need to decrypt directly into memory as the customer doesn't want PII data to reside on disk at any time, unencrypted. What would cause this Stream Length Exception, then?

查看更多
We Are One
5楼-- · 2019-05-17 20:43

There is no (sane) limit on stream length.

You're looking for the HTTP response's ContentLength property.

查看更多
登录 后发表回答