Last active
October 4, 2017 06:32
-
-
Save MadLittleMods/72bc11761e05a2658d0be13fa8c27fef to your computer and use it in GitHub Desktop.
Stream .zip of some glob (directory, etc). See .tar.gz equivalent: https://gist.github.com/MadLittleMods/7eedb4001c52acec104e91dbd80618b5
This file contains 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
const Promise = require('bluebird'); | |
const path = require('path'); | |
const glob = Promise.promisify(require('glob')); | |
// Adds res.zip to express | |
require('express-zip'); | |
const express = require('express'); | |
const app = express(); | |
app.get('/logs.zip', function (req, res) { | |
const logDirPath = path.join(process.cwd(), './logs/'); | |
glob(path.join(logDirPath, '**/*'), { nodir: true }) | |
.then((files) => { | |
const fileList = files.map((file) => { | |
return { | |
path: file, | |
name: path.relative(logDirPath, file), | |
}; | |
}); | |
res.zip(fileList, 'logs.zip'); | |
}) | |
.catch((err) => { | |
res | |
.status(500) | |
.set('Content-Type', 'text/plain') | |
.send('Error', err, err.stack); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment