Node.js implements file merging

requirements:

Code:

const fs = require("fs");
function combine(file1,file2) {
    var size = 0;
    fs.stat(file1,function (err,stat) {
        if(stat.isFile()){
            size = stat.size;
            console.log(size);
            let WSoptions = {
                start: size,
                flags: "r+"
            }
            let WStream = fs.createWriteStream(file1,WSoptions)
            let readStream = fs.createReadStream(file2);
            readStream.pipe(WStream)
        }
    })
}
const file1 = "result.pdf";
const file2 = "wendangceshi.pdf";

the function of the above code is to merge the file1 and file2 files into the file1 file.
problem:
the problem found so far is that for two pdf files, the merged file has only the contents of the file2 file, but the size of the merged file is the sum of the two file sizes. As for text files (txt files), you can merge the contents normally. Please don"t hesitate to give us your advice and explain why.
text before merging:
clipboard.png
:
clipboard.png

pdf:

clipboard.png

clipboard.png

pdf:

clipboard.png

clipboard.png

combine (file1,file2);



  [1]: /img/bVbbqr9
Mar.14,2021

pdf is a complex file format that doesn't merge the two streams together. You can't combine the flow of two pictures into a composite picture, can you?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3ffb4-2bd24.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3ffb4-2bd24.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?