-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from apexearth/master
Fix #237 and other issues with .extractEntryTo()
- Loading branch information
Showing
5 changed files
with
131 additions
and
5 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
Binary file not shown.
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,115 @@ | ||
const {expect} = require('chai'); | ||
const Attr = require("../util").FileAttr; | ||
const Zip = require("../adm-zip"); | ||
const pth = require("path"); | ||
const fs = require("fs"); | ||
const rimraf = require("rimraf") | ||
|
||
describe('adm-zip', () => { | ||
|
||
const destination = './test/xxx' | ||
|
||
beforeEach(done => { | ||
rimraf(destination, err => { | ||
if (err) return done(err) | ||
console.log('Cleared directory: ' + destination) | ||
return done() | ||
}) | ||
}) | ||
|
||
it('zip.extractAllTo()', () => { | ||
const zip = new Zip('./test/assets/ultra.zip'); | ||
zip.extractAllTo(destination); | ||
const files = walk(destination) | ||
|
||
expect(files.sort()).to.deep.equal([ | ||
"./test/xxx/attributes_test/asd/New Text Document.txt", | ||
"./test/xxx/attributes_test/blank file.txt", | ||
"./test/xxx/attributes_test/New folder/hidden.txt", | ||
"./test/xxx/attributes_test/New folder/hidden_readonly.txt", | ||
"./test/xxx/attributes_test/New folder/readonly.txt", | ||
"./test/xxx/utes_test/New folder/somefile.txt" | ||
].sort()); | ||
}) | ||
|
||
it('zip.extractEntryTo(entry, destination, false, true)', () => { | ||
const destination = './test/xxx' | ||
const zip = new Zip('./test/assets/ultra.zip'); | ||
var zipEntries = zip.getEntries(); | ||
zipEntries.forEach(e => zip.extractEntryTo(e, destination, false, true)); | ||
|
||
const files = walk(destination) | ||
expect(files.sort()).to.deep.equal([ | ||
"./test/xxx/blank file.txt", | ||
"./test/xxx/hidden.txt", | ||
"./test/xxx/hidden_readonly.txt", | ||
"./test/xxx/New Text Document.txt", | ||
"./test/xxx/readonly.txt", | ||
"./test/xxx/somefile.txt" | ||
].sort()); | ||
}) | ||
|
||
it('zip.extractEntryTo(entry, destination, true, true)', () => { | ||
const destination = './test/xxx' | ||
const zip = new Zip('./test/assets/ultra.zip'); | ||
var zipEntries = zip.getEntries(); | ||
zipEntries.forEach(e => zip.extractEntryTo(e, destination, true, true)); | ||
|
||
const files = walk(destination) | ||
expect(files.sort()).to.deep.equal([ | ||
"./test/xxx/attributes_test/asd/New Text Document.txt", | ||
"./test/xxx/attributes_test/blank file.txt", | ||
"./test/xxx/attributes_test/New folder/hidden.txt", | ||
"./test/xxx/attributes_test/New folder/hidden_readonly.txt", | ||
"./test/xxx/attributes_test/New folder/readonly.txt", | ||
"./test/xxx/utes_test/New folder/somefile.txt" | ||
].sort()); | ||
}) | ||
|
||
it('passes issue-237-Twizzeld test case', () => { | ||
const zip = new Zip('./test/assets/issue-237-Twizzeld.zip'); | ||
const zipEntries = zip.getEntries(); | ||
zipEntries.forEach(function (zipEntry) { | ||
if (!zipEntry.isDirectory) { | ||
zip.extractEntryTo(zipEntry, './', false, true); | ||
// This should create text.txt on the desktop. | ||
// It will actually create two, but the first is overwritten by the second. | ||
} | ||
}); | ||
let text = fs.readFileSync('./text.txt').toString() | ||
expect(text).to.equal('ride em cowboy!') | ||
fs.unlinkSync('./text.txt') | ||
}) | ||
}) | ||
|
||
function walk(dir) { | ||
let results = []; | ||
const list = fs.readdirSync(dir); | ||
list.forEach(function (file) { | ||
file = dir + '/' + file; | ||
const stat = fs.statSync(file); | ||
if (stat && stat.isDirectory()) { | ||
/* Recurse into a subdirectory */ | ||
results = results.concat(walk(file)); | ||
} else { | ||
/* Is a file */ | ||
results.push(file); | ||
} | ||
}); | ||
return results; | ||
} | ||
|
||
function walkD(dir) { | ||
let results = []; | ||
const list = fs.readdirSync(dir); | ||
list.forEach(function (file) { | ||
file = dir + '/' + file; | ||
const stat = fs.statSync(file); | ||
if (stat && stat.isDirectory()) { | ||
/* Recurse into a subdirectory */ | ||
results = results.concat(walk(file)); | ||
results.push(file); | ||
} | ||
}); | ||
return results; | ||
} |