Exemple #1
0
 co(function* () {
     client.useBucket(bucketName);
     var result = yield client.list({
         'max-keys': 5
     });
     cb(result.objects, undefined);
 }).catch(function (err) {
	co(function*() {
		var result = yield client.list(ossOptions);
		if (result.objects === undefined) {
			ee.emit('listEmpty');
		}
		else {
			ee.emit('listSuccess', result);
			var downloaded = 0, total = result.objects.length;
			//监听内部事件
			ee.on('_download', function(index) {
				var object = result.objects[index];
				co(function*() {
					yield client.get(object.name, path + '/' + getBaseName(object.name));
					downloaded++;
					//触发外部事件
					ee.emit('objectSuccess', object.name, path + '/' + getBaseName(object.name), downloaded, total);
					//触发下一个
					if (downloaded < total) {
						ee.emit('_download', downloaded);
					}
					else {
						ee.emit('downloadComplete');
					}
				}).catch(function(e) {
					downloaded++;
					ee.emit('objectError', e, downloaded, total);
					if (downloaded < total) {
						ee.emit('_download', downloaded);
					}
					else {
						ee.emit('downloadComplete');
					}
				});
			});
			//触发第一次下载
			process.nextTick(function() {
				ee.emit('_download',downloaded);
			});
		}
	}).catch(function(e) {