[HELP] A weird issue when downloading files

Hello Geminauts,

I have a weird issue that came up when coding stuff on Asuka (my client) 
and maybe you can help. I?m adding support for opening whatever mime type 
a Gemini server is serving me.

The logic I implemented so far is:
- serve text/* in the client as usual
- serve the other mime types by downloading content to a temporary file 
and opening it with xdg-open, open...

In order to download the served content I first check the header as 
string, get its size as bytes, re-fetch the whole ?page? as bytes, reverse 
the bytes array, truncate it with the header length and finally reverse it 
again before writing it to a file.

My issue is I have to add an offset of 5 bytes to the truncation for the 
files to be readable and I have no idea why. I tested this offset on 
several servers that are serving images, tarballs...  and it looks consistent.

Does it ring a bell by any chance? Or maybe I?m doing all of this completely wrong.

---

Next in thread (2 of 3): 🗣️ Sean Conner (sean (a) conman.org)

View entire thread.