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 9237125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:27:51+00:00 2026-06-18T07:27:51+00:00

The issue is as follows, I am using an HttpWebRequest to request some online

  • 0

The issue is as follows, I am using an HttpWebRequest to request some online data from dmo.gov.uk. The response I am reading using a BinaryReader and writing to a MemoryStream. I have packaged the code being used into a simple test method:

public static byte[] Test(int bufferSize)
{
    var request = (HttpWebRequest)WebRequest.Create("http://www.dmo.gov.uk/xmlData.aspx?rptCode=D3B.2");
    request.Method = "GET";
    request.Credentials = CredentialCache.DefaultCredentials;

    var buffer = new byte[bufferSize];
    using (var httpResponse = (HttpWebResponse)request.GetResponse())
    {
        using (var ms = new MemoryStream())
        {
            using (var reader = new BinaryReader(httpResponse.GetResponseStream()))
            {
                int bytesRead;
                while ((bytesRead = reader.Read(buffer, 0, bufferSize)) > 0)
                {
                    ms.Write(buffer, 0, bytesRead);
                }
            }
            return ms.GetBuffer();
        }
    }
}

My real-life code uses a buffer size of 2048 bytes usually, however I noticed today that this file has a huge amount of empty bytes (\0) at the end which bloats the file size. As a test I tried increasing the buffer size to near-on the file size I expected (I was expecting ~80Kb so made the buffer size 79000) and now I get the right file size. But I’m confused, I expected to get the same file size regardless of the buffer size used to read the data.

The following test:

Console.WriteLine(Test(2048).Length);
Console.WriteLine(Test(79000).Length);
Console.ReadLine();

Yields the follwoing output:

131072
81341

The second figure, using the high buffer size is the exact file size I was expecting (This file changes daily, so expect that size to differ after today’s date). The first figure contains \0 for everything after the file size expected.

What’s going on here?

  • 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-06-18T07:27:52+00:00Added an answer on June 18, 2026 at 7:27 am

    You should change ms.GetBuffer(); to ms.ToArray();.

    GetBuffer will return the entire MemoryStream buffer while ToArray will return all the values inside the MemoryStream.

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

Sidebar

Related Questions

This question follows on from a previous question, that has raised a further issue.
I am using java/oracle. i have below issue. SELECT DISTINCT id_one, status FROM sometable
I've been using buttons for quite some time that are structured as follows: <button
I'm having an issue with using Marshal.PtrToStructure() to extract data out of a pointer
I've developed a .net 3.5 application which uses an HTTPWebRequest to fetch data from
I am using multiprocessing module in python2.7 and found to have some issue with
My issue is as follows. We have dict that has all keys and values
Right now i'm having a problem with sitecore workflow. The issue is as follows:
I am getting a practical issue and the issue can be dascribed as follows.
I'm having some issues to deserialize a Json array that follows this format: [

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.