Created
May 8, 2016 15:18
-
-
Save eiyaya/58f70cb447d1f18b1fc05f57e69c2dd9 to your computer and use it in GitHub Desktop.
convert pipe to promise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const fs = require('fs'); | |
const co = require('co'); | |
const unzip = require('unzip'); | |
const promisePipe = require("promisepipe"); | |
/* | |
fs.createReadStream('t.zip') | |
.pipe(unzip.Extract({ path: 'output' }).on('close',function (){ | |
console.log('done'); | |
})); | |
*/ | |
co(function*(){ | |
let result = yield promisePipe( | |
fs.createReadStream('t.zip'), | |
unzip.Extract({ path: 'output' }) | |
) | |
var data = fs.readFileSync('output/xx.txt'); | |
console.log(data); | |
}) | |
/* | |
co(function*(){ | |
var result = yield x(); | |
}) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment