Page 1 of 1

Adding bytes to start of file

Posted: Tue Jun 18, 2024 9:43 am
by matalog
I'm working with an old file format, .tap. It requires the header to have information on the length of the contents of the data following it. Should I be creating the file content, then storing that in a file, then using the contents of the file to read into a new file as I generate the header? Is there a way to INSERT bytes into a file that will move the other contents up by the amount of bytes inserted?

I will also have to get a binary XOR of all of the bytes in the file for the checksum, is there a quick way to do that, or should I be thinking about some thing like:

Code: Select all

x.a=Byte0 ! Byte1
ctr=2
Repeat
x= x ! Byte(ctr)
ctr=ctr+1
Until ctr= Length of Bytes

Re: Adding bytes to start of file

Posted: Tue Jun 18, 2024 9:59 am
by wilbert
If you need to store the length as a number but don't know it in advance, you can store it as 0 initially and when you know the right value use FileSeek to the position where the length value is stored and overwrite the 0 with the correct value.
matalog wrote: Tue Jun 18, 2024 9:43 am I will also have to get a binary XOR of all of the bytes in the file for the checksum, is there a quick way to do that
It depends on what you call quick.
From what I read online ( https://sinclair.wiki.zxnet.co.uk/wiki/TAP_format ) the format is from the 80s.
I suppose the files are so short that any method will be fast enough.

Re: Adding bytes to start of file

Posted: Tue Jun 18, 2024 11:50 am
by jacdelad
From what I read from wilberts link, the header is always 19 bytes long with each information always in the same place. I would create a structure for it, write the header and the data. Either fill the header with the real information beforehand or afterwards and write the header again.

Re: Adding bytes to start of file

Posted: Tue Jun 18, 2024 9:35 pm
by matalog
You're right guys, of course. I should be using a placeholder.

I don't program enough unfortunately. Thanks for the help :-).