From a29d0bbe7df985ad4e93a9fcf38fc414ec66c2f7 Mon Sep 17 00:00:00 2001 From: Jonathan Bennetts Date: Wed, 19 Oct 2022 16:53:06 +0100 Subject: [PATCH] feat(Write Binary File Node): add option to append to file --- .../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 c6cb87e152761..6d3d4ba3c2c0f 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