mapbox / mapbox-file-sniff

Detects the type of spatial files
14 stars 12 forks source link

Mapbox File Sniff Build Status

Node module that returns a spatial filetype and protocol.

File types:

Protocols (matching tilelive protocols):

Install

With npm:

npm install @mapbox/mapbox-file-sniff

Usage

var sniffer = require('@mapbox/mapbox-file-sniff');

Javascript

fromBuffer(Buffer) - Sniff a file from a buffer.

var buffer = fs.readFileSync('path/to/data/file.geojson');
sniffer.fromBuffer(buffer, function(err, info) {
    if (err) throw err;
    console.log(info);
    // {
    //   protocol: 'omnivore:',
    //   type: 'geojson'
    // }
});

fromFile(String) - Sniff a file from a file path.

var file = './path/to/data/file.geojson';
sniffer.fromFile(file, function(err, info) {
    if (err) throw err;
    console.log(info);
    // {
    //   protocol: 'omnivore:',
    //   type: 'geojson'
    // }
});

CLI

$ mapbox-file-sniff path/to/data/file.geojson
# {"protocol":"omnivore:","type":"geojson"}
$ mapbox-file-sniff path/to/data/file.geojson --type
# geojson
$ mapbox-file-sniff path/to/data/file.geojson --protocol
# omnivore:

Tests

Full test suite:

npm test