-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathbloscZarrDecompress.js
More file actions
67 lines (64 loc) · 1.96 KB
/
Copy pathbloscZarrDecompress.js
File metadata and controls
67 lines (64 loc) · 1.96 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { runPipeline, InterfaceTypes, WorkerPool } from 'itk-wasm'
import { getSize } from '../IO/dtypeUtils'
const cores = navigator.hardwareConcurrency ? navigator.hardwareConcurrency : 4
const numberOfWorkers = cores + Math.floor(Math.sqrt(cores))
const workerPool = new WorkerPool(numberOfWorkers, runPipeline)
workerPool.terminateWorkers()
/**
* Input:
*
* chunkData: An Array of
*
* {
* data: chunkArrayBuffer,
* metadata: zarrayMetadata
* }
*
* objects.
*
*
* Output:
*
* An Array of decompressed ArrayBuffer chunks.
*/
async function bloscZarrDecompress(chunkData) {
const desiredOutputs = [{ type: InterfaceTypes.BinaryStream }]
const taskArgsArray = []
let dtype = null
for (let index = 0; index < chunkData.length; index++) {
const zarrayMetadata = chunkData[index].metadata
const compressedChunk = chunkData[index].data
dtype = zarrayMetadata.dtype
const nElements = zarrayMetadata.chunks.reduce((a, b) => a * b)
const elementSize = getSize(dtype)
if (!elementSize) throw Error('Unknown dtype in .zarray metadata')
const outputSize = nElements * elementSize
const inputs = [
{
type: InterfaceTypes.BinaryStream,
data: { data: new Uint8Array(compressedChunk) },
},
]
const args = [
'0',
'0',
zarrayMetadata.compressor.cname,
compressedChunk.byteLength.toString(),
'--output-size',
outputSize.toString(),
'--decompress',
'--memory-io',
]
taskArgsArray.push(['BloscZarr', args, desiredOutputs, inputs])
}
const results = await workerPool.runTasks(taskArgsArray).promise
workerPool.terminateWorkers()
const decompressedChunks = []
for (let index = 0; index < results.length; index++) {
// console.log(results[index].stdout)
// console.error(results[index].stderr)
decompressedChunks.push(results[index].outputs[0].data.data.buffer)
}
return decompressedChunks
}
export default bloscZarrDecompress