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:
:
pdf:
pdf:
combine (file1,file2);
[1]: /img/bVbbqr9