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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:40:32+00:00 2026-05-18T06:40:32+00:00

I have a binary file which I am reading to a collection of byte

  • 0

I have a binary file which I am reading to a collection of byte arrays.

The file contains multiple (arbitrary number) of records. Essentially a block of bytes. Each record is of arbitrary length.

The header of the file provides the offsets of each of the records.

record 0: offset 2892
record 1: offset 4849
....
record 98: offset 328932
record 99: offset 338498

I have written code to do loop and read in each record to it’s byte array. Looking at difference in offsets gives me the record size. A seek to the offset and then a call to ReadBytes() reads the record into its array.

My current incomplete solution won’t work for the last record. How would you read that last record into an array (remember it is of arbitrary length).

As for why? Each record is encrypted and needs to be decrypted separately. I am writing code which will read in each record into a byte array. Decrypt it and then write all the record back to a file.

Code added at request:

    //recordOffsets contain byte location of each record start.  All headers (other than universal header) are contained within record 0.
    recordBlocks = new List<RecordBlock>();

    //store all recordOffsets.  Record0 offset will be used to load rest of headers.  Remaining are used to parse text of eBook.
    for (int i = 0; i < standardHeader.numRecs; i++)
    {
        RecordBlock r = new RecordBlock();
        r.offset = bookReader.ReadInt32(EndianReader.Endian.BigEndian);
        r.number = bookReader.ReadInt32(EndianReader.Endian.BigEndian);
        recordBlocks.Add(r);
    }

    foreach (RecordBlock r in recordBlocks)
    {
        if (r.number  == recordBlocks.Count)
        {
            ///deal with last record
        }
        else
        {
            r.size = recordBlocks[(r.number) + 1].offset - r.offset;   
        }
        bookReader.Seek(r.offset, SeekOrigin.Begin);
        r.data = bookReader.ReadBytes(r.size);            
    }
  • 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-18T06:40:33+00:00Added an answer on May 18, 2026 at 6:40 am

    You could use the Length property from the FileInfo Class to determine the total number of bytes, so that you can calculate the amount of bytes of the last record as well.
    So you can keep most of your current logic.

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

Sidebar

Related Questions

I have a binary file which contains image.i have to jump on different locations
I have binary data in a file that I can read into a byte
I'm reading from a binary data file which is written by invoking the following
I have a large (3Gb) binary file of doubles which I access (more or
I am having following issue with reading binary file in C. I have read
I have a set of zip files which contains several ieee-be encoded binary and
Let's say we have a binary file that contains 2 bytes that form an
I have a binary file which is simple a list of signed 32 bit
I have a binary file that I have to parse and I'm using Python.
I have a binary file - Windows static library (*.lib). Is there a simple

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.