2016-10-10 02:26:47 -08:00
|
|
|
/*
|
|
|
|
|
* Based on https://github.com/kevva/executable
|
|
|
|
|
* Since this module doesn't expose the function to check stat mode only,
|
|
|
|
|
* his logic is pasted here.
|
|
|
|
|
*
|
|
|
|
|
* Opened an issue and a pull request about it,
|
|
|
|
|
* to maybe switch to module in the future:
|
|
|
|
|
*
|
|
|
|
|
* Issue: https://github.com/kevva/executable/issues/9
|
|
|
|
|
* PR: https://github.com/kevva/executable/pull/10
|
|
|
|
|
*/
|
2016-08-01 14:52:21 -08:00
|
|
|
|
2019-10-02 16:08:40 -08:00
|
|
|
import fs, { Stats } from "fs";
|
2019-09-11 06:36:47 -08:00
|
|
|
|
2019-10-02 16:08:40 -08:00
|
|
|
export function isExecutable(fileStat: Stats): boolean {
|
2016-09-21 06:27:11 -08:00
|
|
|
if (process.platform === 'win32') {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-08-01 14:52:21 -08:00
|
|
|
|
2017-09-10 05:35:10 -08:00
|
|
|
return Boolean(fileStat.mode & 0o0001 || fileStat.mode & 0o0010 || fileStat.mode & 0o0100);
|
2016-08-01 14:52:21 -08:00
|
|
|
}
|
2019-10-02 16:08:40 -08:00
|
|
|
|
|
|
|
|
export function getBase64FileData(filePath: string): Promise<string|null> {
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
|
return fs.readFile(filePath, (err, data) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
// Gracefully fail with a warning
|
|
|
|
|
//eslint-disable-next-line no-console
|
|
|
|
|
console.warn('There was an error reading the file at the local location:', err);
|
|
|
|
|
return resolve(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const base64Data = Buffer.from(data).toString('base64');
|
|
|
|
|
return resolve(base64Data);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|