# Problems converting String to Buffer

**URL:** <https://discourse.nodered.org/t/problems-converting-string-to-buffer/19256>\
**Category:** General\
**Created:** [17 December 2019 12:57 UTC](https://discourse.nodered.org/t/problems-converting-string-to-buffer/19256 "2019-12-17T12:57:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paloky](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paloky/32/30371_2.png) [@paloky](https://discourse.nodered.org/u/paloky)\
**Post date:** [17 December 2019 12:57 UTC](https://discourse.nodered.org/t/problems-converting-string-to-buffer/19256/1 "2019-12-17T12:57:26Z")

</div>

Hi.  
I have problems converting String to Buffer array.  
I receive a TCP (in string mode) with this hexadecimal values "7e f4 0d 00 02 f9 ce f8 5d 14 00 00 7e".  
If I config TCP to "stream of Buffer" or "Single Buffer" I can't make the TCP connection. Only works using "stream of Strings"

When I try to convert the TCP string to a Buffer, this add extra values to array and change others.  
"7E **EF BF BD** 0D 00 02 **EF BF BD EF BF BD EF BF BD** 5D 14 00 00 7E"

I using this command to make the conversion:

var b = Buffer(msg.payload, 16);

How can I convert correctly the input string to byte array or buffer?  
Or How can I get a TCP buffer directly??

Thanks.

---

<div class="post-metadata">

**Author:** ![paloky](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paloky/32/30371_2.png) [@paloky](https://discourse.nodered.org/u/paloky)\
**Post date:** [17 December 2019 14:34 UTC](https://discourse.nodered.org/t/problems-converting-string-to-buffer/19256/2 "2019-12-17T14:34:52Z")

</div>

Hi guys.  
Finaly I solved the problem.  
I configure the TCP with "Stream of Base64 String" output, and next, I use the next funciction to decode to Buffer:  
var data = msg.payload;  
var buff = new Buffer(data, 'base64');

Now, I receive the payload correctly.
