From 4b13b3398dce5338f46c80867d6e4c8c685f6c22 Mon Sep 17 00:00:00 2001 From: Jonathan Bennetts Date: Mon, 24 Oct 2022 10:41:43 +0100 Subject: [PATCH] feat(Write Binary File Node): add option to append to a file (#4386) --- .../WriteBinaryFile/WriteBinaryFile.node.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/WriteBinaryFile/WriteBinaryFile.node.ts b/packages/nodes-base/nodes/WriteBinaryFile/WriteBinaryFile.node.ts index c6cb87e152..6d3d4ba3c2 100644 --- a/packages/nodes-base/nodes/WriteBinaryFile/WriteBinaryFile.node.ts +++ b/packages/nodes-base/nodes/WriteBinaryFile/WriteBinaryFile.node.ts @@ -42,6 +42,22 @@ export class WriteBinaryFile implements INodeType { description: 'Name of the binary property which contains the data for the file to be written', }, + { + displayName: 'Options', + name: 'options', + type: 'collection', + placeholder: 'Add Option', + default: {}, + options: [ + { + displayName: 'Append', + name: 'append', + type: 'boolean', + default: false, + description: 'Whether to append to an existing file', + }, + ], + }, ], }; @@ -57,6 +73,9 @@ export class WriteBinaryFile implements INodeType { const dataPropertyName = this.getNodeParameter('dataPropertyName', itemIndex) as string; const fileName = this.getNodeParameter('fileName', itemIndex) as string; + const options = this.getNodeParameter('options', 0, {}) as IDataObject; + + const flag = options.append ? 'a' : 'w'; item = items[itemIndex]; @@ -90,7 +109,7 @@ export class WriteBinaryFile implements INodeType { ); // Write the file to disk - await fsWriteFile(fileName, binaryDataBuffer, 'binary'); + await fsWriteFile(fileName, binaryDataBuffer, { encoding: 'binary', flag }); if (item.binary !== undefined) { // Create a shallow copy of the binary data so that the old