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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:37:43+00:00 2026-05-24T08:37:43+00:00

I have this resource file which I need to process, wich packs a set

  • 0

I have this resource file which I need to process, wich packs a set of files.

First, the resource file lists all the files contained within, plus some other data, such as in this struct:

struct FileEntry{
     byte Value1;
     char Filename[12];
     byte Value2;
     byte FileOffset[3];
     float whatever;
}

So I would need to read blocks exactly this size.

I am using the Read function from FileStream, but how can I specify the size of the struct?
I used:

int sizeToRead = Marshal.SizeOf(typeof(Header));

and then pass this value to Read, but then I can only read a set of byte[] which I do not know how to convert into the specified values (well I do know how to get the single byte values… but not the rest of them).

Also I need to specify an unsafe context which I don’t know whether it’s correct or not…

It seems to me that reading byte streams is tougher than I thought in .NET 🙂

Thanks!

  • 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-24T08:37:45+00:00Added an answer on May 24, 2026 at 8:37 am

    Assuming this is C#, I wouldn’t create a struct as a FileEntry type. I would replace char[20] with strings and use a BinaryReader – http://msdn.microsoft.com/en-us/library/system.io.binaryreader.aspx to read individual fields. You must read the data in the same order as it was written.

    Something like:

    class FileEntry {
         byte Value1;
         char[] Filename;
         byte Value2;
         byte[] FileOffset;
         float whatever;
    }
    
      using (var reader = new BinaryReader(File.OpenRead("path"))) {
         var entry = new FileEntry {
            Value1 = reader.ReadByte(),
            Filename = reader.ReadChars(12) // would replace this with string
            FileOffset = reader.ReadBytes(3),
            whatever = reader.ReadFloat()           
         };
      }
    

    If you insist having a struct, you should make your struct immutable and create a constructor with arguments for each of your field.

     

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

Sidebar

Related Questions

I have a gwt application which I need to apply custom themes for specific
I have a Web solution which contains two projects ( A and B )
My problem is this : Using MonoDevelop (which is the preferred environment for a
So I'm working with django and file uploads and I need a javascript function
I have a busy set of routines to validate or download the current client
Briefly: I can make a file, save it in the file system and then
I've been asked to choose which is the best option out of three in
Somewhere else , someone states that the Visible Property of a control cannot be
I am creating a Windows service using Apache's procrun, and I'm having difficulty getting

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.