Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3872568
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:56:24+00:00 2026-05-19T21:56:24+00:00

I’m no expert on the formats, but I’m guessing it’s possible for certain input

  • 0

I’m no expert on the formats, but I’m guessing it’s possible for certain input data for the compressed data to actually be longer, due to formatting overheads.

I’m OK with this but what I’m not OK with is the documented behaviour of the count parameter to GZipStream/DeflateStream.Write(): “The maximum number of compressed bytes to write.” The usual practice (unless compressing in chunks) is to pass in the length of the input data:

public static byte[] Compress(byte[] data)
{
    using (var compressed = new IO.MemoryStream(data.Length))
    {
        using (var compressor = new IO.Compression.DeflateStream(compressed, IO.Compression.CompressionMode.Compress))
            compressor.Write(data, 0, data.Length);
        return compressed.ToArray();
    }
}

In the edge case I’m talking about, the write statement won’t write out the whole compressed data stream, just the first data.Length bytes of it. I could just double the buffer size but for large data sets that’s a bit wasteful, and anyway I don’t like the guesswork.

Is there a better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T21:56:24+00:00Added an answer on May 19, 2026 at 9:56 pm

    I am pretty sure that it is a mistake in the documentation. Documentation in earlier versions reads "The number of bytes compressed.", which is consistent with how all other streams work.

    The same change was made to the documentation of the Read method, where it makes sense, but I think that the change was made by mistake to the documentation of the Write method. Someone corrected the documentation of the Read method, and thought that the same correction would apply to the Write method also.

    The normal behavior for the Read method of a stream is that it can return less data than requested, and the method returns the number of bytes actually placed in the buffer. The Write method on the other hand always writes all the data specified. It wouldn’t make any sense for the method to write less data in any implementation. As the method doesn’t have a return value, it could not return the number of bytes written.

    The count specified is not the size of the output, it’s the size of the data that you send into the method. If the output is larger than the input, it will still all be written to the stream.

    Edit:

    I added a comment about this to the community content of the documentation of the method in MSDN Library. Let’s see if Microsoft follows up on that…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I want use html5's new tag to play a wav file (currently only supported
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.