search through sparse geonames data without downloading the whole archive
var { Transform, pipeline } = require('stream')
var fs = require('fs')
var path = require('path')
var dir = process.argv[2]
var cities = require('sparse-geonames-search')({
read: (file,cb) => fs.readFile(path.join(dir,file),cb)
})
pipeline(
cities.search(process.argv.slice(3).join(' ')),
Transform({
objectMode: true,
transform: (row,enc,next) => next(null, JSON.stringify(row)+'\n')
}),
process.stdout,
(err) => { if (err) console.error(err) }
)
usage: sparse-geonames-search DIR [QUERY...]
Search for records matching QUERY based on the data located in DIR.
var search = require('sparse-geonames-search')
Create a new instance s
from:
opts.read(file, cb)
- read the complete contents offile
, providing the result incb(err, buf)
.
Return a readable stream
of geoname results in objectMode for geonames data matching the string
query
.
Each row
from the stream has these fields:
- row.id
- row.name
- row.longitude
- row.latitude
- row.countryCode
- row.cc2
- row.admin1
- row.admin2
- row.admin3
- row.admin4
- row.population
- row.elevation
Get a record by its id
as cb(err, record)
.
npm install sparse-geonames-search
bsd