Comparing version 5.3.3 to 5.4.0
@@ -0,1 +1,6 @@ | ||
## 5.4.0 | ||
* Expose copy function as an API | ||
* Fix handling of paths with spaces | ||
## 5.3.3 | ||
@@ -2,0 +7,0 @@ |
var tilelive = exports; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var url = require('url'); | ||
var qs = require('querystring'); | ||
var util = require('util'); | ||
@@ -8,2 +10,4 @@ var os = require('os'); | ||
var stream = require('stream'); | ||
var progress = require('progress-stream'); | ||
var queue = require("queue-async"); | ||
@@ -78,3 +82,6 @@ global.tileliveProtocols = global.tileliveProtocols || {}; | ||
if (typeof uri === 'string') uri = url.parse(uri, true); | ||
if (typeof uri === 'string') { | ||
uri = url.parse(uri, true); | ||
uri.pathname = qs.unescape(uri.pathname); | ||
} | ||
@@ -99,2 +106,3 @@ // Handle uris in the format /path/to/dir?id=bar | ||
uri = url.parse(uri); | ||
uri.pathname = qs.unescape(uri.pathname); | ||
@@ -299,2 +307,86 @@ // Attempt to load any modules that may match keyword pattern. | ||
tilelive.copy = function(src, dst, options, callback) { | ||
callback = callback || function() {}; | ||
if (options.type === 'list' && !options.listStream) { | ||
return callback(new Error('You must provide a listStream')); | ||
} | ||
if (!dst && !options.outStream) { | ||
return callback(new Error('You must provide either a dsturi or an output stream')); | ||
} | ||
if (options.concurrency) tilelive.stream.setConcurrency(options.concurrency); | ||
var prog = progress({ | ||
objectMode: true, | ||
time: 100 | ||
}); | ||
// Load source and destination if URIs are strings | ||
var q = queue(); | ||
if (typeof src === 'string') q.defer(function(next) { | ||
var uri = tilelive.auto(src); | ||
tilelive.load(uri, function(err, loaded) { | ||
if (err) return next(err); | ||
src = loaded; | ||
next(); | ||
}); | ||
}); | ||
if (typeof dst === 'string') q.defer(function(next) { | ||
var uri = tilelive.auto(dst); | ||
tilelive.load(uri, function(err, loaded) { | ||
if (err) return next(err); | ||
dst = loaded; | ||
next(); | ||
}); | ||
}); | ||
q.await(function(err) { | ||
if (err) return callback(err); | ||
copy(src, dst, options, callback); | ||
}); | ||
function copy(src, dst, opts, callback) { | ||
// copy to outStream, if present. This is done after the src is loaded | ||
if (!dst && opts.outStream) return out(opts, callback); | ||
// Copy | ||
var get = tilelive.createReadStream(src, opts); | ||
var put = tilelive.createWriteStream(dst); | ||
get.on('error', callback); | ||
put.on('error', callback); | ||
get.on('length', prog.setLength); | ||
if (options.progress) prog.on('progress', function(p) { options.progress(get.stats, p); }); | ||
if (opts.type === 'list') { | ||
var file = opts.listStream; | ||
file.pipe(get).pipe(prog).pipe(put); | ||
} else { | ||
get.pipe(prog).pipe(put); | ||
} | ||
put.on('stop', callback); | ||
} | ||
function out(options, callback) { | ||
var get = tilelive.createReadStream(src, options); | ||
var put = options.outStream; | ||
get.on('error', callback); | ||
put.on('error', callback); | ||
put.on('finish', callback); | ||
get.on('length', prog.setLength); | ||
if (options.progress) prog.on('progress', function(p) { options.progress(get.stats, p); }); | ||
if (options.type === 'list') { | ||
var file = options.listStream; | ||
file.pipe(get).pipe(tilelive.serialize()).pipe(prog).pipe(put); | ||
} else { | ||
get.pipe(tilelive.serialize()).pipe(prog).pipe(put); | ||
} | ||
} | ||
}; | ||
// tilelive implementation of node readable/writable stream. | ||
@@ -301,0 +393,0 @@ tilelive.createReadStream = function(source, options) { |
{ | ||
"name": "tilelive", | ||
"version": "5.3.3", | ||
"version": "5.4.0", | ||
"main": "./lib/tilelive.js", | ||
@@ -36,3 +36,4 @@ "description": "API for various map tile backends", | ||
"progress-stream": "~0.5.x", | ||
"sphericalmercator": "~1.0.1" | ||
"sphericalmercator": "~1.0.1", | ||
"queue-async": "~1.0.7" | ||
}, | ||
@@ -45,3 +46,4 @@ "devDependencies": { | ||
"tilejson": "~0.8.0", | ||
"tilelive-http": "^0.3.0" | ||
"tilelive-http": "^0.3.0", | ||
"concat-stream": "1.4.x" | ||
}, | ||
@@ -48,0 +50,0 @@ "bin": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58576
1041
4
7
2
+ Addedqueue-async@~1.0.7
+ Addedqueue-async@1.0.7(transitive)