helensy / base64-to-image

Decode base64 to image and save the image to disk.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Method call is async but return is synced

i-khan opened this issue · comments

is this fixed yet? I used the library and found the same problem.

change https://github.com/helensy/base64-to-image/blob/master/index.js#L42 to use writeFileSync then

const transformImage = async (base64Str, key) => {
  let imgObj = {'fileName': key, 'type':'png'};
    console.log("writing " + key);
    await base64ToImage(base64Str,'./tools/images/output/',imgObj);
}

let imgKeys = Object.keys(images);
imgKeys.forEach(key => {
  transformImage(images[key], key);
});

working for me. A real solution might employ a promise or callback. I will not bother to submit a PR given that the last change here was 7 years ago...