Skip to content

Instantly share code, notes, and snippets.

@jamesknelson
Created April 3, 2019 12:01
Show Gist options
  • Save jamesknelson/3c4661b826a88bf897db5353b25fbae2 to your computer and use it in GitHub Desktop.
Save jamesknelson/3c4661b826a88bf897db5353b25fbae2 to your computer and use it in GitHub Desktop.
const CombinedStream = require('combined-stream2');
function concatStringsAndStreams(strings, ...args) {
let combinedStream = CombinedStream.create()
combinedStream.append(Buffer.from(strings[0], 'utf8'))
for (let i = 0; i < args.length; i++) {
let arg = args[i]
let string = strings[i+1]
if (arg && arg.pipe) {
combinedStream.append(arg)
}
else {
combinedStream.append(Buffer.from(String(arg), 'utf8'))
}
combinedStream.append(Buffer.from(String(string), 'utf8'))
}
return combinedStream
}
module.exports = concatStringsAndStreams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment