-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (28 loc) · 912 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const assert = require('assert')
const Module = require(__dirname + '/dist/easyexif')
let cachedInstance
const instance = Module()
function callWasmBinding(methodName, ...args) {
return new Promise((resolve) => {
if (!cachedInstance) {
instance.onRuntimeInitialized = () => {
cachedInstance = instance
const result = instance[methodName](...args)
resolve(result)
}
} else {
const result = cachedInstance[methodName](...args)
resolve(result)
}
})
}
/**
* extract EXIF meta data from image buffer
* @param {Buffer} buf file buffer
* @returns {object} metadata object
*/
async function exif(buf) {
assert(buf instanceof Buffer, 'first argument must be instance of Buffer')
return callWasmBinding('exif', buf.buffer, buf.buffer.byteLength)
}
module.exports = { exif }