marcel
marcel

Reputation: 3272

NodeJS remove appended data from file

This is how I append data to a file:

self.fs.appendFile(targetFilePath, new Buffer(sourceData, 'base64'), function(err) { ... });

How can I remove data from a file that have been appended? This is required if the stream I receive earlier is interrupted and parts have been written.

Is it possible to undo the last append command?

Upvotes: 0

Views: 400

Answers (1)

Amit
Amit

Reputation: 46323

No, you can't undo anything.

You can truncate the file to a known point (length...):

self.fs.truncateSync(targetFilePath, somePoint);

Or you could originally not write what you're unsure of, just aggregate to memory or a temporary file until you're certain.

Upvotes: 2

Related Questions