Skip to content

Commit

Permalink
add pump
Browse files Browse the repository at this point in the history
  • Loading branch information
yocontra committed Jul 12, 2018
1 parent 920dc2c commit 02700fc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
11 changes: 7 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down Expand Up @@ -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",
Expand Down
17 changes: 10 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 02700fc

Please sign in to comment.