exiftool.js icon indicating copy to clipboard operation
exiftool.js copied to clipboard

async/await version

Open vsimko opened this issue 7 years ago • 1 comments

Here is a async/await wrapper for the getExifFromLocalFileUsingNodeFs function. What do you think, is it worth including to the README.md file ?

/**
 * @param path
 * @returns {Promise}
 */
async function extractExif(path) {
  return new Promise((resolve, reject) => {
    exiftool.getExifFromLocalFileUsingNodeFs(fs, path, (error, exif) => {
      error
        ? reject(error)
        : resolve(Object.assign({file: path}, exif))
    });
  })
}

.. then inside your async code, you can write:

// inside an async function...
const exif = await extractExif('/path/to/my/file1.jpg')

vsimko avatar Sep 25 '17 22:09 vsimko

Promises are new to me (I don't write much JS) but looks good. Feel free to add to README.md. Thanks!

mattburns avatar Sep 25 '17 22:09 mattburns