Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the smallest possible file size on disk?

Tags:

c++

I'm trying to find a solution to store a binary file in it's smallest size on disk. I'm reading vehicles VIN and plate number from a database that is 30 Bytes and when I put it in a txt file and save it, its size is 30B, but its size on disk is 4KB, which means if I save 100000 files or more, it would kill storage space.

So my question is that how can I write this 30B to an individual binary file to its smallest size on disk, and what is the smallest possible size of 30B on disk including other info such as file name and permissions?

Note: I do not want to save those text in database, just I want to make separate binary files.

like image 266
Saasaan Avatar asked Oct 30 '25 04:10

Saasaan


2 Answers

the smallest size of a file is always the cluster size of your disk, which is typically 4k. for data like this, having many records in a single file is really the only reasonable solution.

although another possibility would be to store those files in an archive, a zip file for example. under windows you can even access the zip contents pretty similar to ordinary files in explorer.

another creative possibility: store all the data in the filename only. a zero byte file takes only 1024 bytes in the MFT. (assuming NTFS)

edit: reading up on resident files, i found that on the newer 4k sector drives, the MFT entry is actually 4k, too. so it doesn't get smaller than this, whether the data size is 0 or not.

another edit: huge directories, with tens or hundreds of thousands of entries, will become quite unwieldy. don't try to open one in explorer, or be prepared to go drink a coffee while it loads.

like image 128
ths Avatar answered Nov 01 '25 18:11

ths


Most file systems allocate disk space to files in chunks. It is not possible to take less than one chunk, except for possibly a zero-length file.

Google 'Cluster size'

like image 39
Martin James Avatar answered Nov 01 '25 19:11

Martin James