Last active
August 27, 2018 19:22
-
-
Save BananaAcid/6c15120ed62828c7bce42af9977af10e to your computer and use it in GitHub Desktop.
murmurhash-native with electron & babel (anything works, but murmurhash)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"presets": [ | |
"electron" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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