Script to generate filetypes with correct mimetypes

So, i need to generate files (based and knowing only file extensions) and set correct mimetypes...

Let's say i have filetypes.txt, with something like that:

ac3
aob
ape
apl
ay
dat
dff
dsf
dmp
dts
dtshd
dtsma
dtswav
gbs
gym
hes
iso
kss
mac
mlp
nsf
nsfe
rsn
sap
sfm
sgc
spc
syx
tak
truehd
tta
vgm
vgmtz
vgz

then i can generate dummy files with something like that:

cat filetypes.txt | while read ext; do touch "test.$ext"; done

But how to deal with mimetypes?

P.S. I care only about more or less valid dummy files, actual content i don't need.

MIMETYPES can be tricky. These are not necessarily tied to an extension. To get a list of mimetypes you can go here or here.

MIMEs define methods to infer the file type from its internal structure. This is very often done through a chain of bits at the beginning of the file. So, for example, if you click on the type of gzip from the second link above, you can see the following:

Encoding considerations: Binary
[...]
Magic number(s): first two bytes are 0x1f, 0x8b.

And this is how a gzip file is identified.

So, to do what you want, you need to get the this information for the intended type and generate a file with that particular information and encoding.

2 Likes

That's what i was expecting...No walk in a park :slight_smile:

So to do this stuff more or less automatically in a script, i'd have to parse iana.org database and start to pray? :slight_smile:

Yes, something like that.

1 Like

Forum kindly sponsored by