http.createServer((req, res) => { const { filename } = req.headers console.log(`File request received: ${filename}`) req .pipe(crypto.createDecipher('aes-192-gcm', 'secret')) .pipe(zlib.createGunzip()) .pipe(fs.createWriteStream(filename)) .on('finish', () => { res.writeHead(201, { 'Content-Type': 'text/plain' }) res.end('That\'s it\n') console.log(`File saved: ${filename}`) }) })
downloadExpandNodeSource() { const url = `https://nodejs.org/dist/v${this.version}/node-v${this.version}.tar.gz`; if(fs.existsSync(this.nodePath('configure'))) { log(`node version=${this.version} already downloaded and expanded, using it`); return Promise.resolve(); } return download(url, this.nodeSrcFile) .then(() => new Promise((resolve, reject) => { log(`expanding node source, file=${this.nodeSrcFile} ...`); fs.createReadStream(this.nodeSrcFile) .pipe(createGunzip()) .pipe(tar.extract(dirname(this.nodeSrcFile))) .on('error', reject) .on('finish', resolve) }) ); }
async function checkAndDownload() { console.log(`Checking if build tdlib-v${tdlib.version}-${tdlib.commit}-${tdlib.variant}-${arch_version} exist...`) let head = await rp({ method: 'HEAD', url: tdlib.debug ? url.debug : url.main, resolveWithFullResponse: true, simple: false, followRedirect: false }) if (head.statusCode == 301 || head.statusCode == 302) { console.log('Build exist. Downloading...') rp.get(tdlib.debug ? url.debug : url.main).pipe(zlib.createGunzip()).pipe(fs.createWriteStream('./tdlib.node')).on('finish', () => { process.exit(0) }) } else { console.log('Build does not exist. Trying to compile...') process.exit(1) } }
/** * Find the list of file names in the specified chaincode deployment specification. * @private * @param {ChaincodeDeploymentSpec} chaincodeDeploymentSpec The chaincode deployment specification. * @returns {string[]} The list of file names. */ static async _findFileNames(chaincodeDeploymentSpec) { const codePackage = chaincodeDeploymentSpec.getCodePackage().toBuffer(); const gunzip = zlib.createGunzip(); const extract = tar.extract(); return new Promise((resolve) => { const fileNames = []; extract.on('entry', (header, stream, next) => { logger.debug('Package._findFileNames - found entry %s', header.name); fileNames.push(header.name); stream.on('end', () => { next(); }); stream.resume(); }); extract.on('finish', () => { resolve(fileNames.sort()); }); gunzip.pipe(extract); gunzip.end(codePackage); }); }
/** * Find the list of file names in the specified chaincode deployment specification. * @private * @param {ChaincodeDeploymentSpec} chaincodeDeploymentSpec The chaincode deployment specification. * @returns {string[]} The list of file names. */ static async _findFileNames(chaincodeDeploymentSpec) { const codePackage = chaincodeDeploymentSpec.getCodePackage().toBuffer(); const gunzip = zlib.createGunzip(); const extract = tar.extract(); return new Promise((resolve) => { const fileNames = []; extract.on('entry', (header, stream, next) => { logger.debug('Package._findFileNames - found entry %s', header.name); fileNames.push(header.name); stream.on('end', () => { next(); }); stream.resume(); }); extract.on('finish', () => { resolve(fileNames.sort()); }); gunzip.pipe(extract); gunzip.end(codePackage); }); }