moved to spawn -- still needs more error handling...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-01-24 21:09:51 +04:00
parent 69420f1710
commit f34c7eae51

View File

@ -118,7 +118,6 @@ if(window.CEF_dumpJSON != null){
}) })
} }
USE_EXEC = false
// XXX this uses vips... // XXX this uses vips...
window.getVipsField = function(field, source){ window.getVipsField = function(field, source){
if(source in IMAGES){ if(source in IMAGES){
@ -127,28 +126,23 @@ if(window.CEF_dumpJSON != null){
} }
var getter = $.Deferred() var getter = $.Deferred()
// exec... var data = ''
if(USE_EXEC){ var p = proc.spawn('vips', ['im_header_string', field, osPath(source)])
var cmd = 'vips im_header_string "$FIELD" "$IN"' p.stdout.on('data', function(d){
.replace(/\$IN/g, osPath(source)) data += d.toString()
.replace(/\$FIELD/g, field) })
proc.exec(cmd, function(error, stdout, stderr){ p.stdout.on('end', function(){
getter.resolve(stdout.trim()) getter.resolve(data.trim())
}) })
// spawn... /* XXX do we need these???
// NOTE: this should have significantly less overhead than running a shell... p.on('error', function(code){
} else { // XXX
var p = proc.spawn('vips', ['im_header_string', field, osPath(source)]) })
p.stdout.on('data', function(data){ p.on('close', function(code){
getter.resolve(data.toString().trim()) getter.resolve(data)
}) })
/* */
p.on('close', function(code){
getter.resolve(code)
})
*/
}
return getter return getter
} }
@ -318,6 +312,46 @@ if(window.CEF_dumpJSON != null){
factor = 1 factor = 1
} }
var p = proc.spawn('vips', [
'im_shrink',
osPath(source) +':'+ rscale,
preview_path +':'+ compression,
factor,
factor
])
// XXX is this the correct wat to deal with errors???
var error = ''
p.stderr.on('data', function(data){
error += data.toString()
})
//p.stderr.on('end', function(data){
//})
p.on('close', function(code){
// error...
if(code != 0){
deferred.notify(gid, size, 'error', error)
deferred.reject()
// ok...
} else {
// NOTE: the size of the real preview
// generated might different from
// the target size...
deferred.notify(gid, size, 'done')
// update the image structure...
if(!('preview' in img)){
img.preview = {}
}
img.preview[size+'px'] = './' + cache_dir +'/'+ preview_path.split(cache_dir).pop()
// mark image dirty...
imageUpdated(gid)
// we are done...
deferred.resolve()
}
})
/*
var cmd = 'vips im_shrink "$IN:$RSCALE" "$OUT:$COMPRESSION" $FACTOR $FACTOR' var cmd = 'vips im_shrink "$IN:$RSCALE" "$OUT:$COMPRESSION" $FACTOR $FACTOR'
.replace(/\$IN/g, osPath(source)) .replace(/\$IN/g, osPath(source))
.replace(/\$RSCALE/g, rscale) .replace(/\$RSCALE/g, rscale)
@ -348,6 +382,7 @@ if(window.CEF_dumpJSON != null){
deferred.resolve() deferred.resolve()
} }
}) })
*/
}) })
}) })
}(size, target_path, deferred)] }(size, target_path, deferred)]