Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to *.gz data at import #519

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function getFullFileList(peliasConfig, args) {

if (_.isEmpty(files)) {
// no specific files listed, so return all .csv and .geojson files
return glob.sync( args.dirPath + '/**/*.{csv,geojson}' );
return glob.sync( args.dirPath + '/**/*.{csv,geojson,geojson.gz,csv.gz}' );
} else {
// otherwise return the requested files with full path
return files.map(function(file) {
Expand Down
11 changes: 8 additions & 3 deletions lib/streams/recordStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const csvParse = require('csv-parse').parse;
const combinedStream = require('combined-stream');
const through = require('through2');
const split = require('split2');
const zlib = require('zlib');

const logger = require('pelias-logger').get('openaddresses');
const config = require('pelias-config').generate();
Expand All @@ -26,13 +27,13 @@ function getIdPrefix(filename, dirPath) {
// of the directory tree to create the id
if (filename.indexOf(dirPath) !== -1) {
var subpath = _.replace(filename, dirPath, '');
var prefix = _.replace(subpath, /\.(csv|geojson)/, '');
var prefix = _.replace(_.replace(subpath, /\.(csv|geojson)/, ''), /\.gz/, '');
return _.trim(prefix, '/');
}
}

// if the dirPath doesn't contain this file, return the basename without extension
return path.basename(path.basename(filename, '.csv'), '.geojson');
return path.basename(path.basename(path.basename(filename, '.gz'), '.csv'), '.geojson');
}

/**
Expand Down Expand Up @@ -98,7 +99,11 @@ function geojsonStream(stream) {
}

function fileStreamDispatcher(stream, filePath) {
if (filePath.endsWith('.geojson')) {
if (filePath.endsWith('.gz')) {
stream = stream.pipe(zlib.createGunzip());
}

if (/\.geojson(\.gz)?/.test(filePath)) {
return geojsonStream(stream);
}

Expand Down