Skip to content

Instantly share code, notes, and snippets.

@stormoz
Created July 25, 2019 13:19
Show Gist options
  • Save stormoz/4c055377eebcdf6613387ef66664620d to your computer and use it in GitHub Desktop.
Save stormoz/4c055377eebcdf6613387ef66664620d to your computer and use it in GitHub Desktop.
read data to stream
import http from 'http';
import axios from 'axios';
http.createServer(async function (req, res) {
const responseStream = await axios({
method: 'get',
url: 'http://blob.file.storage/filepath',
responseType: 'stream'
});
const contentType = responseStream.headers['content-type'];
const contentLength = responseStream.headers['content-length'];
res.writeHead(200, {
'Content-Type': contentType,
'Content-Length': contentLength
});
responseStream.data.pipe.pipe(res);
}).listen(2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment