admin管理员组文章数量:1400149
I have a file stream that I want to pass in a method named transformRead(), this one accepts a readStream and a writeStream, but I don't know how to create the temporary write stream... do I have to use a file ? I just want a kind of pipe() from rs to ws, then ws is gzipped and sent to response.
// Get file stream
var rs = store.getReadStream(fileId);
var ws = ?????;
// Execute transformation
store.transformRead(rs, ws, fileId);
var accept = req.headers['accept-encoding'] || '';
// Compress data if supported by the client
if (accept.match(/\bdeflate\b/)) {
res.writeHead(200, {
'Content-Encoding': 'deflate',
'Content-Type': file.type
});
ws.pipe(zlib.createDeflate()).pipe(res);
} else if (accept.match(/\bgzip\b/)) {
res.writeHead(200, {
'Content-Encoding': 'gzip',
'Content-Type': file.type
});
ws.pipe(zlib.createGzip()).pipe(res);
} else {
res.writeHead(200, {});
ws.pipe(res);
}
I have a file stream that I want to pass in a method named transformRead(), this one accepts a readStream and a writeStream, but I don't know how to create the temporary write stream... do I have to use a file ? I just want a kind of pipe() from rs to ws, then ws is gzipped and sent to response.
// Get file stream
var rs = store.getReadStream(fileId);
var ws = ?????;
// Execute transformation
store.transformRead(rs, ws, fileId);
var accept = req.headers['accept-encoding'] || '';
// Compress data if supported by the client
if (accept.match(/\bdeflate\b/)) {
res.writeHead(200, {
'Content-Encoding': 'deflate',
'Content-Type': file.type
});
ws.pipe(zlib.createDeflate()).pipe(res);
} else if (accept.match(/\bgzip\b/)) {
res.writeHead(200, {
'Content-Encoding': 'gzip',
'Content-Type': file.type
});
ws.pipe(zlib.createGzip()).pipe(res);
} else {
res.writeHead(200, {});
ws.pipe(res);
}
Share
Improve this question
asked Aug 1, 2015 at 7:05
Karl.SKarl.S
2,4021 gold badge29 silver badges33 bronze badges
2 Answers
Reset to default 5Finally, someone told me about using stream.PassThrough();
So the simplest and "native" solution is :
var ws = new stream.PassThrough();
Use through2 to easily create transform (read/write) stream
本文标签: javascriptHow to create a temporary write streamStack Overflow
版权声明:本文标题:javascript - How to create a temporary write stream? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744133461a2592282.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论