Skip to content

Commit

Permalink
added archiver asapach#105
Browse files Browse the repository at this point in the history
  • Loading branch information
asapach committed Aug 4, 2018
1 parent 7f6e744 commit 33ed01a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"web"
],
"dependencies": {
"archiver": "^2.1.1",
"connect-multiparty": "^2.0.0",
"express": "^3.21.2",
"lodash": "^2.4.2",
Expand Down Expand Up @@ -67,6 +68,6 @@
},
"license": "MIT",
"engines": {
"node": ">=0.12"
"node": ">=6"
}
}
15 changes: 15 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var rangeParser = require('range-parser'),
express = require('express'),
multipart = require('connect-multiparty'),
fs = require('fs'),
archiver = require('archiver'),
store = require('./store'),
progress = require('./progressbar'),
stats = require('./stats'),
Expand Down Expand Up @@ -181,4 +182,18 @@ api.all('/torrents/:infoHash/files/:path([^"]+)', findTorrent, function (req, re
pump(file.createReadStream(range), res);
});

api.get('/torrents/:infoHash/archive/:path([^"]+)', findTorrent, function (req, res) {
var torrent = req.torrent;

res.setHeader('Content-Type', 'application/zip');
req.connection.setTimeout(3600000);

var archive = archiver('zip');
torrent.files.forEach(function (f) {
archive.append(f.createReadStream(), { name: f.path });
});

pump(archive, res);
});

module.exports = api;

0 comments on commit 33ed01a

Please sign in to comment.