just a file
That's all folks!
const fs = require('fs'); | |
const wrapStream = require('./wrap-stream'); | |
fs.createReadStream('some-file.txt') // file contents: 'just a file' | |
.pipe(wrapStream('## Below you will find the contents of some-file.txt:\n\n```\n', '\n```\n\nThat\'s all folks!') | |
.pipe('output.md') | |
; |
function wrapStream(prefix, suffix) { | |
let once = false; | |
return new Transform({ | |
objectMode: true, | |
transform(chunk, _, callback) { | |
if (!once) { | |
once = true; | |
callback(null, `${prefix}${chunk}`); | |
} | |
else { | |
callback(null, chunk); | |
} | |
}, | |
flush(callback) { | |
callback(null, suffix); | |
} | |
}); | |
} | |
module.exports = wrapStream; |