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

  • SEARCH
  • Home
  • 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 6596185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:02:31+00:00 2026-05-25T18:02:31+00:00

After searching, I have failed to find out an easily understandable explaination as to

  • 0

After searching, I have failed to find out an easily understandable explaination as to why an extra 4 bytes added on when using BlockCopy method (as shown here, here, here, here)

The documentation says:

As its name suggests, the BlockCopy method copies a block of bytes as
a whole, rather than copying one byte at a time. Therefore, if src and
dst reference the same array, and the range from srcOffset + count -1
overlaps the range from dstOffset + count – 1, the values of the
overlapping bytes are not overwritten before they are copied to the
destination. In the following example, the values of bytes 0-16 in an
array named arr are copied to bytes 12-28. Despite the overlapping
range, the values of the source bytes are successfully copied.

However I don’t really understand this clearly, and hoped someone would be kind enough to explain it differently (or post a link to a resource that explains this), and why the requirement exists to add these extra 4 bytes.

For clarity here is the code I am referring to:

As part of compress method:

byte[] gzBuffer = new byte[compressed.Length + 4];
System.Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length);
System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4);

As part of decompress method:

ms.Write(gzBuffer, 4, gzBuffer.Length - 4);
  • 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-25T18:02:32+00:00Added an answer on May 25, 2026 at 6:02 pm

    It’s not about BlockCopy itself – it’s about length-prefixing some data, that’s all. You’ve found a bit of code that has been copied widely without being particularly well documented.

    It’s often useful when reading a “message” to know how long that message is before you start reading it – it means you don’t need delimiters, or to hope that the end of the stream means the end of the data. This code just compresses the data, then writes the compressed length before the compressed data.

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

Sidebar

Related Questions

I have got a big problem. After searching through the internet, I didn't find
After searching the other questions none have answered the specific issue I have. We
After searching through some existing libraries for JSON, I have finally ended up with
hi i need to have a graph in my html page after searching for
After much searching and googling I am coming back to the well. I have
I am a powershell novice. After days of searching.... I have put together a
After searching I dd not find anything about glassfish3.1 and CORS Is it possible
I have a nested loop that I would like to break out of. After
After searching lot on the internet we have found following code to get only
I'm not sure that this is a bug since after searching I can't find

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.