mbtiles: corrected reading logic, added writing logic ; added recurive directory searching