0
私は、 は現在、私はhttpリクエストモジュールへのパイプアーカイブファイルの場所を返すと、それからreadstream作成しています読めるストリームを返すために私の機能をリファクタリングしたい
:ファイルシステムに書き込まずにnode.jsにアーカイブされた読み込み可能なストリームを返すにはどうしたらいいですか?
const filepath = yield archive.archiveFilesAsTargz('path', 'name.tar.gz');
fs.createReadStream(filepath).pipe(request(options)).then(body =>{
console.log(body);
});
私は」流れをm個のシークは、次のとおりです。
- のようにディレクトリの場所を取得し、それ
- はストリームとしてアーカイブを取得し、(それを解決する)それを返すアーカイブ
- 機能やパイプ読み取りSを呼び出します次のよう
私の機能を要求するtreamは次のとおりです。
exports.archiveFilesAsTargz = function (dest, archivedName) {
return new Promise((resolve, reject)=> {
const name = slugify(archivedName);
const filePath = path.join(dest, name + '.tar.gz');
const output = fs.createWriteStream(filePath);
const archive = archiver('tar', {
gzip: true
});
archive.pipe(output);
archive.directory(dest, name).finalize();
output.on('close',()=> resolve(filePath));
archive.on('error' ,(err) => reject(err));
});
};