const stream = require('stream')
const fs = require('fs')
const html = "<h1> Hello Wordl </h1>
// read file from string and write file
const stream = new Stream()
stream.pipe = function (dest) {
dest.write(html)
return dest
}
stream.pipe(createWriteStream(resolve(process.cwd(), 'index.html'), 'utf8'))
// read file from directory and write file
fs.createReadStream('testing.html')
.pipe(createWriteStream(resolve(process.cwd(), 'index.html'), 'utf8'))
const readFile: InstanceType<typeof stream.Readable> = new stream.Readable({
read() {
return true
}
})
readFile
.pipe(fs.createWriteStream(`${process.env.IMG_DIR}/${Date.now().toString()}-${file.originalname}`))
.on('finish', Promise.resolve)
.on('error', Promise.reject)