@argdown/node
Version:
Async Argdown application for node.js
29 lines • 916 B
JavaScript
import axios from "axios";
import { promises as fs } from "fs";
import path from "path";
import process from "process";
export const imageUtils = {
getImage: async (imagePath, baseDir = "") => {
let buffer;
if (imagePath.startsWith("https:")) {
buffer = await imageUtils.getRemoteImage(imagePath);
}
else {
try {
const resolvedPath = path.resolve(baseDir || process.cwd(), imagePath);
buffer = await fs.readFile(resolvedPath);
}
catch (err) {
buffer = await imageUtils.getRemoteImage(imagePath);
}
}
return buffer;
},
getRemoteImage: async (path) => {
const response = await axios.get(path, {
responseType: "arraybuffer"
});
return Buffer.from(response.data, "binary");
}
};
//# sourceMappingURL=utils.js.map