strom/samples/concat_files.js
2018-11-25 20:00:37 -05:00

22 lines
661 B
JavaScript

const fs = require("fs");
const path = require("path");
const stream = require("mysah/stream");
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
stream
.concat(
fs.createReadStream(sourceFile1),
stream.fromArray(["\n"]),
fs.createReadStream(sourceFile2),
)
.pipe(fs.createWriteStream(outputFile));