Skip to content

Commit

Permalink
feat(Write Binary File Node): add option to append to a file (#4386)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joffcom committed Oct 24, 2022
1 parent 1d9d02b commit 4b13b33
Showing 1 changed file with 20 additions and 1 deletion.
Expand Up @@ -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',
},
],
},
],
};

Expand All @@ -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];

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4b13b33

Please sign in to comment.