@gent-js/gent
Version:
template-based data generator.
28 lines (27 loc) • 922 B
JavaScript
import * as fs from "node:fs";
import * as rfs from "rotating-file-stream";
export async function createFileOutput(nonRotateOutputPath, rotateSize, rotateOutputPathGenerator) {
if (rotateSize === undefined) {
// no file rotation
return fs.createWriteStream(nonRotateOutputPath);
}
else {
// rotate file by size
return rfs.createStream((indexOrDate, indexOrUndefined) => {
if (indexOrDate === null) {
return nonRotateOutputPath;
}
let index;
if (typeof indexOrDate === "number") {
index = indexOrDate;
}
else if (typeof indexOrUndefined === "number") {
index = indexOrUndefined;
}
else {
index = 0;
}
return rotateOutputPathGenerator(index.toString());
}, { size: rotateSize });
}
}