Comparing version 5.7.1 to 5.8.0
@@ -0,1 +1,6 @@ | ||
## 5.8.0 | ||
* `tilelive.copy()` operations that stop doing any processing for 60s will error. This timeout interval is configurable. | ||
* `tilelive.copy()` callers can provide a transform stream which will receive each tile read from the source on its way to the destination. | ||
## 5.7.1 | ||
@@ -2,0 +7,0 @@ |
@@ -316,2 +316,7 @@ var tilelive = exports; | ||
// if (options.transform && (!options.transform._write || !options.transform._read)) { | ||
if (options.transform && !(options.transform instanceof stream.Transform)) { | ||
return callback(new Error('You must provide a valid transform stream')); | ||
} | ||
var prog = progress({ | ||
@@ -345,3 +350,4 @@ objectMode: true, | ||
if (err) return callback(err); | ||
copy(src, dst, options, function(err) { | ||
copy(src, dst, options, function(err) { | ||
if (err) return callback(err); | ||
@@ -357,55 +363,47 @@ if (options.close) closingTime(src, dst, function(err) { | ||
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); | ||
// sinkStream represents a copy to a non-tilelive stream | ||
var sinkStream = !dst && opts.outStream; | ||
// Copy | ||
var get = tilelive.createReadStream(src, opts); | ||
var put = tilelive.createWriteStream(dst, {retry:opts.retry}); | ||
var put = sinkStream ? | ||
options.outStream : tilelive.createWriteStream(dst, {retry:opts.retry}); | ||
var hasErrored = false; | ||
function handleError(err) { | ||
if (!hasErrored) callback(err); | ||
hasErrored = true; | ||
var sentCallback = false; | ||
function done(err) { | ||
if (!sentCallback) { | ||
clearInterval(timeout); | ||
callback(err); | ||
} | ||
sentCallback = true; | ||
} | ||
get.on('error', handleError); | ||
put.on('error', handleError); | ||
var previous; | ||
var timeout = setInterval(function() { | ||
if (prog.progress.transferred === previous) { | ||
done(new Error('Copy operation timed out')); | ||
pipeline.unpipe(prog); | ||
prog.end(); | ||
clearInterval(timeout); | ||
} | ||
previous = prog.progress.transferred; | ||
}, opts.timeout || 60000); | ||
get.on('error', done); | ||
put.on('error', done); | ||
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); | ||
} | ||
if (options.progress) | ||
prog.on('progress', function(p) { options.progress(get.stats, p); }); | ||
put.on('stop', callback); | ||
} | ||
var doneEvent = sinkStream ? 'finish' : 'stop'; | ||
function out(options, callback) { | ||
var get = tilelive.createReadStream(src, options); | ||
var put = options.outStream; | ||
var hasErrored = false; | ||
function handleError(err) { | ||
if (!hasErrored) callback(err); | ||
hasErrored = true; | ||
} | ||
get.on('error', handleError); | ||
put.on('error', handleError); | ||
get.on('length', prog.setLength); | ||
if (options.progress) prog.on('progress', function(p) { options.progress(get.stats, p); }); | ||
if (options.outStream === process.stdout || | ||
options.outStream === process.stderr) prog.on('end', callback); | ||
else put.on('finish', callback); | ||
options.outStream === process.stderr) prog.on('end', done); | ||
else | ||
put.on(doneEvent, done); | ||
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); | ||
} | ||
var pipeline = opts.type === 'list' ? opts.listStream.pipe(get) : get; | ||
if (options.transform) pipeline = pipeline.pipe(options.transform); | ||
if (sinkStream) pipeline = pipeline.pipe(tilelive.serialize()); | ||
pipeline.pipe(prog).pipe(put); | ||
} | ||
@@ -412,0 +410,0 @@ |
{ | ||
"name": "tilelive", | ||
"version": "5.7.1", | ||
"version": "5.8.0", | ||
"main": "./lib/tilelive.js", | ||
@@ -5,0 +5,0 @@ "description": "API for various map tile backends", |
64576
1142