Skip to content

Reading binary files with multiple headers

Jarrod

Asked Oct 28, 2005, 1:33 PM EDT1 answer
Share
LinkedInX

Hello,

I'm trying to read data from a binary file with multiple resources that each have their own header, containing the distance to the next resource header as well as a uInt32 that needs to be read. My question is this: is it possible to read data from each resource header, keeping in mind that since this is a file type in general, and the distance to the next resource will be different for each file or resource that the user opens.

Thanks in advance.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    So far I have structs representing the data, but how would I implement something like this so that it updates 'nOffset' every time it reads the struct, and reads until the end of the file?

    [StructLayout(LayoutKind.Sequential, Pack=1)]

    public struct keyBiffRes

    {

    public string sResName;

    public ushort usResType;

    public uint uBifResId;

    public static keyBiffRes Read(BinaryReader readKey, int nOffset)

    {

    keyBiffRes stKeyBiffRes = new keyBiffRes();

    readKey.BaseStream.Position = nOffset;

    stKeyBiffRes.sResName = new String(readKey.ReadChars(16));

    stKeyBiffRes.usResType = readKey.ReadUInt16();

    stKeyBiffRes.uBifResId = readKey.ReadUInt32();

    return stKeyBiffRes;

    }

    }

    Thanks in advance.

    0