diff --git a/index.js b/index.js index 11af127..6e6be8e 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,18 @@ var isgeocsv = require('detect-geocsv'); var invalid = require('./lib/invalid'); var fs = require('fs'); var bf = require('buffer'); +var semver = require('semver'); + +if (semver.major(process.version) > 0) { + function zlib_gunzip(buffer,zlib_opts,callback) { + zlib.gunzip(buffer, zlib_opts, callback); + } +} else { + // node v0.10 does not support options passed to zlib.gunzip + function zlib_gunzip(buffer,zlib_opts,callback) { + zlib.gunzip(buffer, callback); + } +} module.exports.sniff = sniff; module.exports.waft = waft; @@ -76,8 +88,7 @@ function sniff(buffer, callback) { return callback(null, 'csv'); } - zlib.gunzip(buffer, {finishFlush: zlib.Z_SYNC_FLUSH}, function (err, output) { - if (err) return callback(invalid('Unknown filetype')); + function returnOutput(output,callback) { //check for tm2z if (output.toString('ascii', 257, 262) === 'ustar') return callback(null, 'tm2z'); //check for serial tiles @@ -92,6 +103,12 @@ function sniff(buffer, callback) { //default to unknown return callback(invalid('Unknown filetype')); + } + + var zlib_opts = {finishFlush: zlib.Z_SYNC_FLUSH }; + zlib_gunzip(buffer, zlib_opts, function (err, output) { + if (err) return callback(invalid('Unknown filetype')); + returnOutput(output,callback); }); } diff --git a/package.json b/package.json index 4b079bf..edc6fbb 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ }, "dependencies": { "detect-geocsv": "0.1.0", - "buffer": "^3.2.2" + "buffer": "^3.2.2", + "semver": "~5.3.0" }, "devDependencies": { "tape": "3.0.x",