0

I am not sure what the Windows command "copy /b ..." exactly does, so my questions are: Can this be done with Node.js? How?

Could you please give me an example or at least point me to the right direction?

For e. g.: "copy /b file1+file2 destinationFile"

Thank you.

Kaspi
  • 2,894
  • 3
  • 18
  • 28

1 Answers1

4

copy is an internal command in Windows. copy /b file1+file2 destinationFile creates destinationFile with contents of file1 followed by file2 including extra characters like EOF due to /b.

Here is how to do it in node.js :

fs = require('fs');

file1=fs.createReadStream('./file1',{ flags: 'r',  encoding: "binary",});
file2=fs.createReadStream('./file2',{ flags: 'r',  encoding: "binary",});

dest=fs.createWriteStream('./destinationFile',{ flags: 'w',  encoding: "binary",});

file1.pipe(dest, { end: false });
file2.pipe(dest, { end: false });
user568109
  • 43,824
  • 15
  • 87
  • 118