Rework module structure
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { stream } = require("mhysa");
|
||||
const Mhysa = require("mhysa");
|
||||
|
||||
const sourceFile1 = path.join(process.cwd(), "package.json");
|
||||
const sourceFile2 = path.join(process.cwd(), "README.md");
|
||||
@@ -12,10 +12,8 @@ if (!fs.existsSync(outputDir)) {
|
||||
}
|
||||
|
||||
// Concat two source files together into one
|
||||
stream
|
||||
.concat(
|
||||
fs.createReadStream(sourceFile1),
|
||||
stream.fromArray(["\n"]),
|
||||
fs.createReadStream(sourceFile2),
|
||||
)
|
||||
.pipe(fs.createWriteStream(outputFile));
|
||||
Mhysa.concat(
|
||||
fs.createReadStream(sourceFile1),
|
||||
Mhysa.fromArray(["\n"]),
|
||||
fs.createReadStream(sourceFile2),
|
||||
).pipe(fs.createWriteStream(outputFile));
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
const { sleep, once, delay, stream } = require("mhysa");
|
||||
const {
|
||||
utils: { sleep, delay, once },
|
||||
...Mhysa
|
||||
} = require("mhysa");
|
||||
|
||||
async function main() {
|
||||
const collector = stream
|
||||
.concat(
|
||||
stream.fromArray(["a\n", "b\n", "c\n"]),
|
||||
stream.fromArray(["d", "e"]).pipe(stream.join("-")),
|
||||
)
|
||||
.pipe(stream.split("\n"))
|
||||
const collector = Mhysa.concat(
|
||||
Mhysa.fromArray(["a\n", "b\n", "c\n"]),
|
||||
Mhysa.fromArray(["d", "e"]).pipe(Mhysa.join("-")),
|
||||
)
|
||||
.pipe(Mhysa.split("\n"))
|
||||
.pipe(
|
||||
stream.flatMap(async s => {
|
||||
Mhysa.flatMap(async s => {
|
||||
await sleep(100);
|
||||
return delay([s, s.toUpperCase()], 100);
|
||||
}),
|
||||
)
|
||||
.pipe(stream.collect({ objectMode: true }));
|
||||
.pipe(Mhysa.collect({ objectMode: true }));
|
||||
|
||||
const collected = await once(collector, "data");
|
||||
console.log(collected); // [ 'a', 'A', 'b', 'B', 'c', 'C', 'd-e', 'D-E' ] (after 6 * 100 ms)
|
||||
|
||||
Reference in New Issue
Block a user