Skip to content

Instantly share code, notes, and snippets.

@JoshuaGross
Created September 27, 2016 17:07
Show Gist options
  • Save JoshuaGross/c758f07c03fa4fc2060a99251fdcc1f8 to your computer and use it in GitHub Desktop.
Save JoshuaGross/c758f07c03fa4fc2060a99251fdcc1f8 to your computer and use it in GitHub Desktop.
Translate Node Buffer into shell-friendly binary echo
console.log('echo -e "' + buf.reduce((s, x) => s + '\\x' + x, '') + '"');

Shell:

echo -e "\x85\x0\x2\x68\x0\x32\x194\x41\x247\x13\x33\x183\x212\x148\x92\x165\x68\x193\x4\x214\x164\x10\x90\x65\x80\x193\x114\x14\x255\x164\x18\x165\x77\x65\x0\x0\x9\x0\x50\x55"

You can then pipe this into a command that expects binary data, like curl:

echo -e ... | curl -X POST --data-binary @- http://foo.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment