forked from cvat-ai/cvat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunzip_imgs.worker.js
44 lines (41 loc) · 1.55 KB
/
unzip_imgs.worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2023 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT
// eslint-disable-next-line @typescript-eslint/no-var-requires
const JSZip = require('jszip');
onmessage = (e) => {
const zip = new JSZip();
if (e.data) {
const {
start, end, block, dimension, dimension2D,
} = e.data;
zip.loadAsync(block).then((_zip) => {
let index = start;
_zip.forEach((relativePath) => {
const fileIndex = index++;
if (fileIndex <= end) {
_zip.file(relativePath)
.async('blob')
.then((fileData) => {
if (dimension === dimension2D) {
createImageBitmap(fileData).then((img) => {
postMessage({
fileName: relativePath,
index: fileIndex,
data: img,
});
});
} else {
postMessage({
fileName: relativePath,
index: fileIndex,
data: fileData,
});
}
});
}
});
}).catch((error) => postMessage({ error }));
}
};