Is there a limit for stream length in c#?

2019-05-17 20:07发布

问题:

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?

回答1:

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



回答2:

There is no (sane) limit on stream length.

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



回答3:

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



回答4:

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?



标签: c# stream