-
Notifications
You must be signed in to change notification settings - Fork 14
/
worker.js
39 lines (32 loc) · 861 Bytes
/
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
var st = Date.now()
console.log("loading libunrar.js")
importScripts("./libunrar.js")
var elapt = Date.now() - st
console.log("Time taken to parse/load the lib: ", elapt)
importScripts('rpc.js')
var sender
var proxy = {
unrar: function(data, password){
var cb = sender.progressShow
var rarContent = readRARContent(data.map(function(d){return {name: d.name, content: new Uint8Array(d.content)}}), password, cb)
var transferables = []
var rec = function(entry) {
if(entry.type === 'file') {
transferables.push(entry.fileContent.buffer)
} else if(entry.type === 'dir') {
Object.keys(entry.ls).forEach(function(k){
rec(entry.ls[k])
})
} else {
throw "Unknown type"
}
}
rec(rarContent)
sender.transferables = transferables
return rarContent
}
}
RPC.init(proxy).then(function(s){
s.loaded()
sender = s
})