Add initial support for gzipped database.

May contain bugs. Still testing.