strom/samples/concat_files.js

20 lines
625 B
JavaScript
Raw Normal View History

2018-11-26 01:00:37 +00:00
const fs = require("fs");
const path = require("path");
2018-11-29 04:59:24 +00:00
const Mhysa = require("mhysa");
2018-11-26 01:00:37 +00:00
const sourceFile1 = path.join(process.cwd(), "package.json");
const sourceFile2 = path.join(process.cwd(), "README.md");
const outputDir = path.join(process.cwd(), "sample_output");
const outputFile = path.join(outputDir, "concat_files.txt");
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Concat two source files together into one
2018-11-29 04:59:24 +00:00
Mhysa.concat(
fs.createReadStream(sourceFile1),
Mhysa.fromArray(["\n"]),
fs.createReadStream(sourceFile2),
).pipe(fs.createWriteStream(outputFile));