我正在从我的nodejs服务上的Google存储下载,我有一个实用程序模块,如下所示:
'use strict';
const BPromise = require('bluebird');
const logger = require('../../setup/logger');
module.exports = () => {
let GCloudStorage = {};
GCloudStorage.getStorage = () => {
return require('@google-cloud/storage')();
};
/**
* @param bucketName
* @param filePath
* @param destination the local disk destination
*/
GCloudStorage.downloadFile = (bucketName, filePath, destination) => {
return new BPromise((resolve, reject) => {
const storage = GCloudStorage.getStorage();
logger.info('Downloading file %s in bucket %s to local path: %s', filePath, bucketName, destination);
const file = storage.bucket(bucketName).file(filePath);
const config = {
destination: destination,
validation: false
};
file.download(config)
.then(() => {
logger.debug('Downloaded gs://%s/%s to %s', bucketName, filePath, destination);
resolve(destination);
})
.catch((err) => {
reject(err);
});
});
};
return GCloudStorage;
};
然后在我的业务代码上,我像这样使用它:
let promises = [];
images.map(image => {
promises.push(storageUtil.downloadFile(config.userFolder, image.image, path.resolve(`./reports/${reportId}/${image.name.replace(/[^a-zA-Z0-9-_\.]/g, '')}`)));
});
return BPromise.all(promises);
此过程运行时,该服务会增加其内存使用量,并且在其生命周期内不会对其进行收集。
我知道这可能是代码中的nodejs问题,但是我可以做些什么吗?