Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Write Binary File Node): add option to append to a file #4386

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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