Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use vinyl and vinyl-fs to handle files
- Loading branch information
Showing
4 changed files
with
72 additions
and
195 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
node_modules | ||
test/tmp |
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,122 +1,70 @@ | ||
'use strict'; | ||
|
||
var Decompress = require('../'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var rm = require('rimraf'); | ||
var test = require('ava'); | ||
|
||
test('extract .tar', function (t) { | ||
t.plan(2); | ||
|
||
var decompress = new Decompress() | ||
.src(path.join(__dirname, 'fixtures/test.tar')) | ||
.dest(path.join(__dirname, 'tmp')) | ||
.use(Decompress.tar()); | ||
|
||
decompress.decompress(function (err) { | ||
decompress.run(function (err, files) { | ||
t.assert(!err); | ||
|
||
fs.exists(path.join(decompress.dest(), 'test.jpg'), function (exists) { | ||
t.assert(exists); | ||
|
||
rm(decompress.dest(), function (err) { | ||
t.assert(!err); | ||
}); | ||
}); | ||
t.assert(files[0].path === 'test.jpg'); | ||
}); | ||
}); | ||
|
||
test('extract .tar.bz2', function (t) { | ||
t.plan(2); | ||
|
||
var decompress = new Decompress() | ||
.src(path.join(__dirname, 'fixtures/test.tar.bz2')) | ||
.dest(path.join(__dirname, 'tmp')) | ||
.use(Decompress.tarbz2()); | ||
|
||
decompress.decompress(function (err) { | ||
decompress.run(function (err, files) { | ||
t.assert(!err); | ||
|
||
fs.exists(path.join(decompress.dest(), 'test.jpg'), function (exists) { | ||
t.assert(exists); | ||
|
||
rm(decompress.dest(), function (err) { | ||
t.assert(!err); | ||
}); | ||
}); | ||
t.assert(files[0].path === 'test.jpg'); | ||
}); | ||
}); | ||
|
||
test('extract .tar.gz', function (t) { | ||
t.plan(2); | ||
|
||
var decompress = new Decompress() | ||
.src(path.join(__dirname, 'fixtures/test.tar.gz')) | ||
.dest(path.join(__dirname, 'tmp')) | ||
.use(Decompress.targz()); | ||
|
||
decompress.decompress(function (err) { | ||
decompress.run(function (err, files) { | ||
t.assert(!err); | ||
|
||
fs.exists(path.join(decompress.dest(), 'test.jpg'), function (exists) { | ||
t.assert(exists); | ||
|
||
rm(decompress.dest(), function (err) { | ||
t.assert(!err); | ||
}); | ||
}); | ||
t.assert(files[0].path === 'test.jpg'); | ||
}); | ||
}); | ||
|
||
test('extract .zip', function (t) { | ||
t.plan(2); | ||
|
||
var decompress = new Decompress() | ||
.src(path.join(__dirname, 'fixtures/test.zip')) | ||
.dest(path.join(__dirname, 'tmp')) | ||
.use(Decompress.zip()); | ||
|
||
decompress.decompress(function (err) { | ||
decompress.run(function (err, files) { | ||
t.assert(!err); | ||
|
||
fs.exists(path.join(decompress.dest(), 'test.jpg'), function (exists) { | ||
t.assert(exists); | ||
|
||
rm(decompress.dest(), function (err) { | ||
t.assert(!err); | ||
}); | ||
}); | ||
t.assert(files[0].path === 'test.jpg'); | ||
}); | ||
}); | ||
|
||
test('extract .zip using the strip option', function (t) { | ||
test('extract using the strip option', function (t) { | ||
t.plan(2); | ||
|
||
var decompress = new Decompress() | ||
.src(path.join(__dirname, 'fixtures/test-strip.zip')) | ||
.dest(path.join(__dirname, 'tmp')) | ||
.use(Decompress.zip({ strip: 1 })); | ||
|
||
decompress.decompress(function (err) { | ||
t.assert(!err); | ||
|
||
fs.exists(path.join(decompress.dest(), 'test-strip.jpg'), function (exists) { | ||
t.assert(exists); | ||
|
||
rm(decompress.dest(), function (err) { | ||
t.assert(!err); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
test('extract .zip and set mode on extracted file', function (t) { | ||
var decompress = new Decompress({ mode: 777 }) | ||
.src(path.join(__dirname, 'fixtures/test.zip')) | ||
.dest(path.join(__dirname, 'tmp')) | ||
.use(Decompress.zip()); | ||
|
||
decompress.decompress(function (err) { | ||
decompress.run(function (err, files) { | ||
t.assert(!err); | ||
|
||
fs.stat(path.join(decompress.dest(), 'test.jpg'), function (err, stats) { | ||
t.assert(!err); | ||
t.assert(stats.mode.toString(8) === '100777'); | ||
|
||
rm(decompress.dest(), function (err) { | ||
t.assert(!err); | ||
}); | ||
}); | ||
t.assert(files[0].path === 'test-strip.jpg'); | ||
}); | ||
}); |