 fs = require 'fs'
 
 Tile = require './Tile'
+config = require './config'
 
 # https://github.com/mapbox/node-mbtiles has native build dependencies (sqlite3)
 # To maximize mapscii's compatibility, MBTiles support must be manually added via

  null

module.exports = class TileSource
  config:
    persistDownloadedTiles: true

  cache: {}
  modes:
    MBTiles: 1


  _getHTTP: (z, x, y) ->
    promise =
      if config.persistDownloadedTiles and tile = @_getPersited z, x, y
        Promise.resolve tile
      else
        rp
          uri: @source+[z,x,y].join("/")+".pbf"
          encoding: null
        .then (buffer) =>
          @_persistTile z, x, y, buffer if config.persistDownloadedTiles
          buffer

    promise
