Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zip downloads #113

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export function isGzip(contentType: string, url: string): boolean {

export function isZip(contentType: string, url: string): boolean {
return (
contentType === 'application/zip' ||
(contentType === 'application/octet-stream' && /\.zip(\?|$)/.test(url))
contentType === 'application/zip' || /\.zip(\?|$)/.test(url)
);
}

Expand Down
18 changes: 18 additions & 0 deletions test/DownloadManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,24 @@ describe('DownloadManager', () => {
expect(downloadedData).toEqual(simpleData);
});

it('should write a json file within a zip when the response has content type application/x-zip-compressed and the url ends with .zip', async () => {
const simpleData = fs.readJsonSync(
path.join(__dirname, 'fixtures', 'simpleData.json'),
'utf-8'
);
const simpleZip = fs.readFileSync(path.join(__dirname, 'fixtures', 'simpleZip.zip'));
nock('http://example.org')
.get('/data.zip')
.reply(200, simpleZip, { 'content-type': 'application/x-zip-compressed' });
const dataPath = (await downloadManager.downloadDataFile(
'http://example.org/data.zip'
)) as string;
expect(dataPath).toBeString();
expect(fs.existsSync(dataPath));
const downloadedData = fs.readJsonSync(dataPath, 'utf-8');
expect(downloadedData).toEqual(simpleData);
});

it('should write a json file within a zip when the response has content type application/octet-stream and the url ends with .zip followed by a query string', async () => {
const simpleData = fs.readJsonSync(
path.join(__dirname, 'fixtures', 'simpleData.json'),
Expand Down
Loading