macIconForFile
Get the native macOS icon for a specific file extension as a PNG image buffer.
Inspired and based on:
Retrieves icon, exactly the same way as Finder does it, including QuickLook preview generation in case if it's possible, just check out the example at the end of this page. My motivation to write this module was impossiblity to obtain file system's entry icon in Electron, there is simply no method to do that.
Installation
npm install mac-file-icon
Usage
var getIconForFile = ;;
You can always convert Buffer into it's base64 representation:
var getIconForFile = ;;
In case if callback is ommited, Buffer will be returned in synchronous way:
var getIconForFile = ;console;
By default, icon size is set to 32x32, you can adjust it by passing additional argument:
var getIconForFile = ;// icon size 64x64;
Works same way in synchronous calls:
var getIconForFile = ;// icon size 64x64console;
Build it yourself
cd macIconForFilenpm installnode-gyp configurenode-gyp build
However I'm not sure if last two statements are required...
Example
You can try out an example included into the package, that uses Express, Histone and macIconForFile to generate file listing in the browser.
npm install mac-file-iconcd node_modules/mac-file-icon/examplenpm installnode index.js
Then open your web browser and navigate to http://localhost:8080/ (in case if this port number is taken, edit index.js and set another one), you will see something like this: