Skip to content

Commit

Permalink
keep support working for node v0.10.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Sep 13, 2016
1 parent 0b46f11 commit cbe9e32
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 19 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
});
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit cbe9e32

Please sign in to comment.