Convert string to buffer

I was playing around with better-sftp contrib node and needed to convert my data (string) to a buffer.

And I couldn't immediately think of how to do that (sans coding)

Best I came up with was to put two Base64 nodes back to back and convert to base64 and then decode back to a buffer.

Any other ways?

Knowing your aversion to Function nodes :stuck_out_tongue_winking_eye: there is always node-red-contrib-buffer-parser - it includes a "buffer maker" node.

chrome_plPSKCw54A

[
    {
        "id": "e9afa1b55fbb814c",
        "type": "buffer-maker",
        "z": "4cad319b1add5007",
        "name": "",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "name": "item1",
                "type": "string",
                "length": -1,
                "dataType": "msg",
                "data": "payload"
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "x": 1894,
        "y": 480,
        "wires": [
            [
                "1f2c64d1ec10e525"
            ]
        ]
    },
    {
        "id": "1dc4a8bae838a5b1",
        "type": "inject",
        "z": "4cad319b1add5007",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "hello",
        "payloadType": "str",
        "x": 1730,
        "y": 464,
        "wires": [
            [
                "e9afa1b55fbb814c"
            ]
        ]
    },
    {
        "id": "bc217a8f04132d68",
        "type": "inject",
        "z": "4cad319b1add5007",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "bye",
        "payloadType": "str",
        "x": 1730,
        "y": 496,
        "wires": [
            [
                "e9afa1b55fbb814c"
            ]
        ]
    },
    {
        "id": "1f2c64d1ec10e525",
        "type": "debug",
        "z": "4cad319b1add5007",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 2074,
        "y": 480,
        "wires": []
    }
]

However, if you want to avoid a contrib node, let me know & I will share the 1 line of JS :laughing:

I think I'm coming around to thing of a feature request to get the change node to have conversion options in it

e.g. number <> string, string <> buffer/array

Or maybe I just need to do a PR on the better-sftp node to handle string input and convert internally :slight_smile:

One day I must introduce to to a wonderful low-code programming environment designed for people not to have to learn the worst programming language of all time :slight_smile:

1 Like

:rofl: Obviously, you never had the joy of LISP, Prolog, C and IBM370 assembly!

2 Likes

And now I need that shelf category for my own thread! :slight_smile:

1 Like

Come on folks - answer the OP - are there any no-code alternatives using core nodes? :slight_smile:

Well, might not be what you want to hear but a 1 line function node becomes no-code once it has been written and put into a sub-flow.

As for the shelf - that's what you get when you diss people's languages :grinning:

core no - there is this :point_down:...

... and there is protobuf

and lastly there is this: a function node msg.payload = Buffer.from(msg.payload) :joy:

1 Like

I needed this again and I finally came up with a core node solution :slight_smile:

image

image

image

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.