royaltm / node-murmurhash-native

MurmurHash native bindings for node
MIT License
48 stars 7 forks source link

murmurhash arguments #9

Closed jssuttles closed 8 years ago

jssuttles commented 8 years ago

var murmurhash = require('murmurhash-native').murmurHash128x86; var stuff = murmurhash(somestring, 'hex').substr(0, 10).toUpperCase(); returns 0000000000

var murmurhash = require('murmurhash-native').murmurHash128x86; var stuff = murmurhash(somestring, 42, 'hex').substr(0, 10).toUpperCase(); returns correctly

var murmur = require('murmurhash-native/stream'); murmur.createHash('murmurHash128x86', {seed: 42, endianness: 'LE'}); is the only way that that works as far as I've tried

these don't work even though they go through most of the stream flow before crashing murmur.createHash('murmurHash128x86') murmur.createHash({type: 'murmurHash128x86', seed: 42}) murmur.createHash('murmurHash128x86', {seed: 42}); murmur.createHash('murmurHash128x86', 42);

as far as I can tell, endianness isn't defined if the first parameter is used as options.

royaltm commented 8 years ago

Could you be more specific exactly what is wrong with those arguments? As you can see here createHash has arguments: (algorithm, options)

If you don't specify endianness in options it is "BE" by default.

murmur.createHash('murmurHash128x86');
MurmurHash {
  _handle: MurmurHash128x86 { endianness: 'BE', total: 0, SERIAL_BYTE_LENGTH: 39 },
  _options: undefined }

Can you please make a gist with an example with "crashing" you mention?

jssuttles commented 8 years ago

So, I tried reproducing a few times and I discovered that it's a combination of murmurhash on nwjs. Here's the script and the error: https://gist.github.com/jssuttles/97135cda67fc56308fbf37b95c2e06af (Sorry about the name, couldn't change it after I made the gist.) The script works on node. However, when you run this script in nwjs, it doesn't work.

royaltm commented 8 years ago

Does nwjs support native node modules? I get DLL load error on windows on require('murmurhash-native/stream');.

royaltm commented 8 years ago

I wasn't familiar with nwjs but quick search revealed this: http://docs.nwjs.io/en/latest/For%20Users/Advanced/Use%20Native%20Node%20Modules/

As stated there: "So far, you have to rebuild each native module with tools above including thoses are indirectly depended modules."

This is not an issue with murmurhash-native. murmurhash-native installs with prebuilt binaries for nodejs. You need to follow the instructions on nwjs docs I've mentioned, specifically (it worked for me):

Assuming you have cd into project directory and you have x64 architecture:

npm install -g nw-gyp
cd node_modules/murmurhash-native/
nw-gyp rebuild --runtime=node-webkit --target=0.15.4 --target_arch=x64 --module_path=../lib/Release
cd ../..
nw .
royaltm commented 8 years ago

Please let me know if it worked for you so I'll update Install section in README to mention nwjs case.

jssuttles commented 8 years ago

I see. I realize now that the only reason I haven't run into this before is because I haven't had any other native modules. Unfortunately, nw-gyp didn't work for me and now I realize that it was only working with those arguments that I posted on Mac and not on Windows. So, I'm going to have to find another module. I think yours was the only one that did crypto update-like hashing for murmurhash, so I'm going to have to see how far down the hashing totem pole I'm going to have to go to find something that works with nwjs. Thanks.

royaltm commented 8 years ago

Why it didn't work? Could you at least send me the nw-gyp error you get while rebuilding module on osx? I think it should work on OSX. It works on my x64 windows box. Unfortunately I am unable to check it out myself on OSX.

jssuttles commented 8 years ago

Alright. It works on win64 and win32 and Mac. I just had to go through the whole process of installing nw-gyp, including getting msbuild on Windows. However, I have to configure the nw-gyp build process to either be 64bit or 32bit. That's not a big limitation for a server, but for nwjs, it means that I have to redo my app build process so that it rebuilds the module configured for the 64bit architecture and for the 32bit architecture. I currently have a windows 64-bit VM build both 32 and 64 bit versions, and it's already tedious without having to find and rebuild any other native modules I might add on. So, not really your problem. Once again, thanks. You can go ahead and close this if you want.

royaltm commented 8 years ago

Ok, thanks for your trouble of confirming all that. Good luck with your app.