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

The Archive Base Latest Questions

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

I have a class in a dll which parses a file and returns a

  • 0

I have a class in a dll which parses a file and returns a Stream which represents an FAT image (or any other)

My problem is when there is any other image the class creates about 3702 (on average) null bytes at the beginning of the stream.

So I have to edit the stream first and then save it to a file.

I have a code already but it works slow.

[Note : fts is the returned FileStream.]

BufferedStream bfs = new BufferedStream(fts);
BinaryReader bbr = new BinaryReader(bfs);
byte[] all_bytes = bbr.ReadBytes((int)fts.Length);

List<byte> nls = new List<byte>();
int index = 0;

foreach (byte bbrs in all_bytes)
{
    if (bbrs == 0x00)
    {
        index++;
        nls.Add(bbrs);
    }
    else
    {
        break;
    }
}

byte[] nulls = new byte[nls.Count];
nulls = nls.ToArray();

//File.WriteAllBytes(outputDir + "Nulls.bin", nulls);
long siz = fts.Length - index;
byte[] file = new byte[siz];

bbr.BaseStream.Position = index;
file = bbr.ReadBytes((int)siz);

bbr.Close();
bfs.Close();
fts.Close();

bfs = null;
fts = null;

fts = new FileStream(outputDir + "Image.bin", FileMode.Create, FileAccess.Write);
bfs = new BufferedStream(fts);

bfs.Write(file, 0, (int)siz);

bfs.Close();
fts.Close();

Now, my question is :

How can I remove the nulls more efficiently and faster than the above code?

  • 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-31T16:58:03+00:00Added an answer on May 31, 2026 at 4:58 pm

    Instead of pushing bytes onto a List you could simply loop through your stream until you find the first non-null byte and then just copy the array from there using Array.Copy.

    I would think about something like this (untested code):

    int index = 0;
    int currByte = 0;
    
    while ((currByte = bbrs.ReadByte()) == 0x00)
    {
        index++;
    }
    
    // now currByte and everything to the end of the stream are the bytes you want.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a Class Library (called as GNGEngine.dll) which performs some image processing
I have a dll called Test.dll in which I have a class called ABC
I have a DLL which contains a class with static members . I use
I have a dll which I disassemble in Reflector, I then generate a class.
I have an unmanaged dll with a class MyClass in it. Now is there
Consider I have built DAL.dll which is a class library containing an Entity Framework
I have a class inside a DLL ( Database.dll ) which has a static
I have written a class library in C# (mydll.dll) which accesses a third party
I have a class, Task, and it has a property TaskLibrary which is dll
I have a DLL which exports a few functions. The source file contains a

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.