-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(unzip): try to repair ZIP archives with extra comment length (#138)
Fixes #121
- Loading branch information
Showing
4 changed files
with
114 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const tmp = require('tmp'); | ||
|
||
const runAce = require('../runAceJS'); | ||
|
||
tmp.setGracefulCleanup(); | ||
|
||
let outdir; | ||
let tmpdir; | ||
let reportPath; | ||
|
||
beforeEach(() => { | ||
outdir = tmp.dirSync({ prefix: 'ace_out_', unsafeCleanup: true }); | ||
tmpdir = tmp.dirSync({ prefix: 'ace_tmp_', unsafeCleanup: true }); | ||
reportPath = path.join(outdir.name, 'report.json'); | ||
}); | ||
|
||
afterEach(() => { | ||
outdir.removeCallback(); | ||
tmpdir.removeCallback(); | ||
}); | ||
|
||
|
||
function ace(epub, options = {}) { | ||
return runAce(epub, Object.assign({ | ||
outdir: outdir.name, | ||
tmp: tmpdir.name, | ||
}, options)) | ||
.then(() => { | ||
expect(fs.existsSync(reportPath)).toBeTruthy(); | ||
return JSON.parse(fs.readFileSync(reportPath, 'utf8')); | ||
}) | ||
.catch(err => console.log(err)); | ||
} | ||
|
||
test('well-formed EPUB archive is processed', async () => { | ||
const report = await ace(path.join(__dirname, '../data/base-epub-30.epub')); | ||
expect(report['earl:result']).toBeDefined(); | ||
}); | ||
|
||
test('an EPUB archive with an extra comment length is repaired', async () => { | ||
const report = await ace(path.join(__dirname, '../data/zip-invalid-comment-length.epub')); | ||
expect(report['earl:result']).toBeDefined(); | ||
}); | ||
|
||
test('an EPUB archive beyond repair is rejected', async () => { | ||
const report = await ace(path.join(__dirname, '../data/zip-invalid.epub')); | ||
expect(report).toBeUndefined(); | ||
}); |
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 @@ | ||
hello |