Write file only when button is triggered

hello guys

I am reading data from an Arduino. This data is being written into a file on the Raspi. The way it works now is that as soon as the Arduino sends anything, the Raspi immediatly writes the file. What I would like to have is that the file is only written, when a button was pushed before. So as long as the button is not pressed, no file will be written, altough data is being sent / received.
On the attached image are the basic nodes (without the buttons). Somehow the button(s) need to interfere with the connection marked in green on the image, but I don't know how to do this. I cannot just insert a button, because in fact I have two buttons and the user has to click one of them before the file should be created.

write

see code below:

[{"id":"182658c8.e32607","type":"file","z":"89d348aa.ccebc8","name":"S0Zaehler","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":790,"y":180,"wires":[[]]}]

You could use a node-red-contrib-queue-gate set to max queue size of 1 and to Keep Newest Message, with default state Closed. Make the button send it a Flush command. The node will buffer within itself the most recent message and when the button sends the flush it will release that last message.

It would be more efficient to put it earlier in flow so it is not wasting its time preparing the data only for it to be thrown away.

thx, I will try this.