-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb23b9b
commit 1ece1ca
Showing
30 changed files
with
1,289 additions
and
1,520 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Ignore artifacts: | ||
build | ||
coverage |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,44 @@ | ||
var app = require('express')(); | ||
var archiver = require('archiver'); | ||
var p = require('path'); | ||
var app = require("express")(); | ||
var archiver = require("archiver"); | ||
var p = require("path"); | ||
|
||
app.get('/', function(req, res) { | ||
app.get("/", function (req, res) { | ||
var archive = archiver("zip"); | ||
|
||
var archive = archiver('zip'); | ||
|
||
archive.on('error', function(err) { | ||
res.status(500).send({error: err.message}); | ||
archive.on("error", function (err) { | ||
res.status(500).send({ error: err.message }); | ||
}); | ||
|
||
//on stream closed we can end the request | ||
archive.on('end', function() { | ||
console.log('Archive wrote %d bytes', archive.pointer()); | ||
archive.on("end", function () { | ||
console.log("Archive wrote %d bytes", archive.pointer()); | ||
}); | ||
|
||
//set the archive name | ||
res.attachment('archive-name.zip'); | ||
res.attachment("archive-name.zip"); | ||
|
||
//this is the streaming magic | ||
archive.pipe(res); | ||
|
||
var files = [__dirname + '/fixtures/file1.txt', __dirname + '/fixtures/file2.txt']; | ||
var files = [ | ||
__dirname + "/fixtures/file1.txt", | ||
__dirname + "/fixtures/file2.txt", | ||
]; | ||
|
||
for(var i in files) { | ||
for (var i in files) { | ||
archive.file(files[i], { name: p.basename(files[i]) }); | ||
} | ||
|
||
var directories = [__dirname + '/fixtures/somedir'] | ||
var directories = [__dirname + "/fixtures/somedir"]; | ||
|
||
for(var i in directories) { | ||
archive.directory(directories[i], directories[i].replace(__dirname + '/fixtures', '')); | ||
for (var i in directories) { | ||
archive.directory( | ||
directories[i], | ||
directories[i].replace(__dirname + "/fixtures", ""), | ||
); | ||
} | ||
|
||
archive.finalize(); | ||
|
||
}); | ||
|
||
app.listen(3000); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
var fs = require('fs'); | ||
var fs = require("fs"); | ||
|
||
var archiver = require('archiver'); | ||
var archiver = require("archiver"); | ||
|
||
var output = fs.createWriteStream(__dirname + '/example-output.tar'); | ||
var archive = archiver('tar'); | ||
var output = fs.createWriteStream(__dirname + "/example-output.tar"); | ||
var archive = archiver("tar"); | ||
|
||
output.on('close', function() { | ||
console.log(archive.pointer() + ' total bytes'); | ||
console.log('archiver has been finalized and the output file descriptor has closed.'); | ||
output.on("close", function () { | ||
console.log(archive.pointer() + " total bytes"); | ||
console.log( | ||
"archiver has been finalized and the output file descriptor has closed.", | ||
); | ||
}); | ||
|
||
archive.on('error', function(err) { | ||
archive.on("error", function (err) { | ||
throw err; | ||
}); | ||
|
||
archive.pipe(output); | ||
|
||
var file1 = __dirname + '/fixtures/file1.txt'; | ||
var file2 = __dirname + '/fixtures/file2.txt'; | ||
var file1 = __dirname + "/fixtures/file1.txt"; | ||
var file2 = __dirname + "/fixtures/file2.txt"; | ||
|
||
archive | ||
.append(fs.createReadStream(file1), { name: 'file1.txt' }) | ||
.append(fs.createReadStream(file2), { name: 'file2.txt' }) | ||
.finalize(); | ||
.append(fs.createReadStream(file1), { name: "file1.txt" }) | ||
.append(fs.createReadStream(file2), { name: "file2.txt" }) | ||
.finalize(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
var fs = require('fs'); | ||
var archiver = require('archiver'); | ||
var fs = require("fs"); | ||
var archiver = require("archiver"); | ||
|
||
var output = fs.createWriteStream(__dirname + '/example-output.tar.gz'); | ||
var archive = archiver('tar', { | ||
var output = fs.createWriteStream(__dirname + "/example-output.tar.gz"); | ||
var archive = archiver("tar", { | ||
gzip: true, | ||
gzipOptions: { | ||
level: 1 | ||
} | ||
level: 1, | ||
}, | ||
}); | ||
|
||
output.on('close', function() { | ||
console.log(archive.pointer() + ' total bytes'); | ||
console.log('archiver has been finalized and the output file descriptor has closed.'); | ||
output.on("close", function () { | ||
console.log(archive.pointer() + " total bytes"); | ||
console.log( | ||
"archiver has been finalized and the output file descriptor has closed.", | ||
); | ||
}); | ||
|
||
archive.on('error', function(err) { | ||
archive.on("error", function (err) { | ||
throw err; | ||
}); | ||
|
||
archive.pipe(output); | ||
|
||
var file1 = __dirname + '/fixtures/file1.txt'; | ||
var file2 = __dirname + '/fixtures/file2.txt'; | ||
var file1 = __dirname + "/fixtures/file1.txt"; | ||
var file2 = __dirname + "/fixtures/file2.txt"; | ||
|
||
archive | ||
.append(fs.createReadStream(file1), { name: 'file1.txt' }) | ||
.append(fs.createReadStream(file2), { name: 'file2.txt' }) | ||
.finalize(); | ||
.append(fs.createReadStream(file1), { name: "file1.txt" }) | ||
.append(fs.createReadStream(file2), { name: "file2.txt" }) | ||
.finalize(); |
Oops, something went wrong.