repair compatibility of Buffer with js browser client

js web client does not have the Buffer object, original code would cause "undefined" error in browser,
added extra condition to check the existence of Buffer object,
works well after modification, passed original test suite,
also wonder if there's a better way to check the existence of the Buffer object.