Class: Pool

pool~Pool(sizeopt, createWorkeropt)

Pool for workers to decode chunks of the images.

Constructor

new Pool(sizeopt, createWorkeropt)

Parameters:
Name Type Attributes Description
size Number <optional>

The size of the pool. Defaults to the number of CPUs available. When this parameter is null or 0, then the decoding will be done in the main thread.

createWorker function <optional>

A function that creates the decoder worker. Defaults to a worker with all decoders that ship with geotiff.js. The createWorker() function is expected to return a Worker compatible with Web Workers. For code that runs in Node, web-worker is a good choice.

A worker that uses a custom lzw decoder would look like this my-custom-worker.js file:

import { addDecoder, getDecoder } from 'geotiff';
addDecoder(5, () => import ('./my-custom-lzw').then((m) => m.default));
self.addEventListener('message', async (e) => {
  const { id, fileDirectory, buffer } = e.data;
  const decoder = await getDecoder(fileDirectory);
  const decoded = await decoder.decode(fileDirectory, buffer);
  self.postMessage({ decoded, id }, [decoded]);
});

The way the above code is built into a worker by the createWorker() function depends on the used bundler. For most bundlers, something like this will work:

function createWorker() {
  return new Worker(new URL('./my-custom-worker.js', import.meta.url));
}
Source:

Methods

(async) decode(buffer) → {Promise.<ArrayBuffer>}

Decode the given block of bytes with the set compression method.

Parameters:
Name Type Description
buffer ArrayBuffer

the array buffer of bytes to decode.

Source:
Returns:

the decoded result as a Promise

Type
Promise.<ArrayBuffer>