Skip to content

Instantly share code, notes, and snippets.

@BananaAcid
Last active August 27, 2018 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BananaAcid/6c15120ed62828c7bce42af9977af10e to your computer and use it in GitHub Desktop.
Save BananaAcid/6c15120ed62828c7bce42af9977af10e to your computer and use it in GitHub Desktop.
murmurhash-native with electron & babel (anything works, but murmurhash)
{
"presets": [
"electron"
]
}
#!/env/bash
echo same for OSX / WIN !
echo install basics
npm i electron babel-core babel-preset-electron
echo should fix native modules -- https://github.com/royaltm/node-murmurhash-native/issues/13#issuecomment-412664883
echo but only for current OS - does not work with electrons cross building
npm i electron-rebuild
node_modules/.bin/electron-rebuild
echo run
node_modules/electron/dist/electron index.js
// some exerpt from a current project
import fs from 'fs';
import path from 'path';
import murmur from 'murmurhash-native/stream';
console.log('app should have started...');
let hasher = murmur.createHash('murmurhash32', {seed: 478932, encoding: 'hex', endianness: 'platform'});
let filepath = path.resolve('./', 'app.mjs');
(async () => {// pipe through the hasher (little memory foot print)
let hash = await new Promise( resolve => {
let data = '';
fs.createReadStream(filepath)
.pipe(hasher) // create hash string
.on('data', d => data += d.toString()) // collect stream text from pipe->hash
.on('error', () => resolve(null)) // do not throw an error on error (so no reject)
.on('end', () => resolve(data)); // return info
});
console.log('hash %s of file %s', hash, filepath);
})();
console.log('fin.');
require('babel-core/register')({
extensions: ['.js', '.mjs'],
});
module.exports = require('./app.mjs');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment