> Any application state that can be recorded in a pile-of-files can also be recorded in an SQLite database with a simple key/value schema like this:
CREATE TABLE files(filename TEXT PRIMARY KEY, content BLOB);
> If the content is compressed, then such an SQLite Archive database is the same size (±1%) as an equivalent ZIP archive, and it has the advantage of being able to update individual "files" without rewriting the entire document.Also look at the related post which suggests doing precisely that - storing images inside SQLite blobs: https://www.sqlite.org/affcase1.html
- Direcory structure
- Zip file
- Tar file
- Sqlite db
Out of these, sqlite is the most compact, by far (also the fastest)
Having a single file per very large image (for mobile) makes transferring them to the phone over USB around ten times as fast. I wish I’d done it years ago.
If you can spread your data among many files, you probably should. Not everybody can.
1: https://github.com/mapbox/mbtiles-spec 2: https://wiki.openstreetmap.org/wiki/MBTiles
And reading and writing can be even faster than if they were stored directly in the filesystem, https://www.sqlite.org/fasterthanfs.html
Even if you can in theory save some time with small files with sqlite, you would be back to read/write IO and userspace/kernel byte buffer switching.
And it probably wouldn't be faster than something like a mmaped file anyway (unless the SQLite Db is also mmaped).
https://www.sqlite.org/src/doc/trunk/src/test_onefile.c
https://www.sqlite.org/vfs.html
IIRC, during one of his talks D. Richard Hipp mentions this actually being done for real.