var co = require('co');
var thunkify = require('thunkify');
var zlib = require('zlib');
var gzip = thunkify(zlib.gzip);//相当于给函数起别名
var unzip = thunkify(zlib.unzip);

co(function *(){
var structs = '123';
var _structs = yield gzip(structs);

_structs = _structs.toString('base64');

var str = yield unzip(new Buffer(_structs, 'base64'));
str = str.toString();

console.log(str); //打印123
})

posted on 2015-11-02 15:20  沉默的土豆  阅读(1296)  评论(0编辑  收藏  举报