From 02700fca8800e5a8e35f4251f3899507ad0c1dbc Mon Sep 17 00:00:00 2001 From: contra Date: Thu, 12 Jul 2018 15:31:05 -0400 Subject: [PATCH] add pump --- dist/index.js | 11 +++++++---- package.json | 3 ++- src/index.js | 17 ++++++++++------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/dist/index.js b/dist/index.js index b81842a..19f172c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -48,6 +48,10 @@ var _once = require('once'); var _once2 = _interopRequireDefault(_once); +var _pump = require('pump'); + +var _pump2 = _interopRequireDefault(_pump); + var _defaultConfig = require('./defaultConfig'); var _defaultConfig2 = _interopRequireDefault(_defaultConfig); @@ -107,12 +111,11 @@ function processFilePath(context, file, cb) { var srcStream = _superagent2.default.get((0, _urlJoin2.default)(options.http, file.path)).buffer(false); var count = 0; - (0, _shp2json2.default)(srcStream).pipe(_JSONStream2.default.parse('features.*')).pipe(_through2Asyncmap2.default.obj(function (feat, done) { + (0, _pump2.default)((0, _shp2json2.default)(srcStream), _JSONStream2.default.parse('features.*'), _through2Asyncmap2.default.obj(function (feat, done) { ++count; context.onBoundary(file.type, feat, done); - })).once('error', function (err) { - return cb(err); - }).once('finish', function () { + }), function (err) { + if (err) return cb(err); debug(' -- ' + _chalk2.default.cyan('Parsed ' + file.path + ' and inserted ' + count + ' boundaries')); cb(); }); diff --git a/package.json b/package.json index f7c0c23..1c6873f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "census-boundaries", - "version": "2.0.4", + "version": "2.0.5", "description": "Downloads and converts US Census TIGER data representing all boundaries in the United States", "main": "dist/index.js", "keywords": [ @@ -59,6 +59,7 @@ "meow": "^4.0.0", "once": "^1.3.3", "plural": "^1.0.0", + "pump": "^3.0.0", "shp2json": "^1.2.1", "superagent": "^3.8.2", "through2-asyncmap": "^1.1.0", diff --git a/src/index.js b/src/index.js index c35c52a..a97ddf8 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,7 @@ import map from 'through2-asyncmap' import plural from 'plural' import clone from 'lodash.clone' import once from 'once' +import pump from 'pump' import config from './defaultConfig' import getFTP from './getFTP' import _debug from 'debug' @@ -51,17 +52,19 @@ function processFilePath(context, file, cb) { const { ftp, options } = context const srcStream = request.get(join(options.http, file.path)).buffer(false) let count = 0 - toJSON(srcStream) - .pipe(JSONStream.parse('features.*')) - .pipe(map.obj((feat, done) => { + pump( + toJSON(srcStream), + JSONStream.parse('features.*'), + map.obj((feat, done) => { ++count context.onBoundary(file.type, feat, done) - })) - .once('error', (err) => cb(err)) - .once('finish', () => { + }), + (err) => { + if (err) return cb(err) debug(` -- ${chalk.cyan(`Parsed ${file.path} and inserted ${count} boundaries`)}`) cb() - }) + } + ) } function fetchObjectFiles({ ftp, options }, object, cb) {