I had occasion to use exiftool recently, but instead of a callback, I'd rather use promises.
This is what I came up with:
const exif = require('exiftool');
const util = require('util');
const exif_metadata = function (data) {
return new Promise((resolve, reject) => {
exif.metadata(data, (err, metadata) => {
if (err) {
reject(new Error(err));
} else {
resolve(metadata);
}
});
});
};
Worked great!
const fs_readFile = util.promisify(fs.readFile);
Promise.resolve()
.then(() => {
return fs_readFile(path);
})
.then(data => {
return exif_metadata(data);
})
.then(metadata => {
console.log('metadata: %O', metadata);
})
.catch(error => {
res.send(error.toString());
});
No comments:
Post a Comment