This commit is contained in:
2026-05-13 19:58:16 +03:00
commit f5adeb292b
78 changed files with 12024 additions and 0 deletions

31
lib/datafile.js Normal file
View File

@@ -0,0 +1,31 @@
const fs = require('fs')
const os = require('os')
const { Transform } = require('stream')
module.exports = function(filename='data.json', onFinish=()=>{}) {
//
// Create an object to string transform
// stream
//
var stream = new Transform({
writableObjectMode: true,
transform(chunk, encoding, callback) {
this.push(JSON.stringify(chunk))
this.push(os.EOL)
return callback()
}
})
//
// Pipe that to the file write
// stream and set up an onFinish
// handler
//
stream.pipe(
fs.createWriteStream(filename).on('finish', onFinish)
)
//
// Return the new write stream
//
return stream
}