pool.d.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. export default Pool;
  2. /**
  3. * @module pool
  4. */
  5. /**
  6. * Pool for workers to decode chunks of the images.
  7. */
  8. declare class Pool {
  9. /**
  10. * @constructor
  11. * @param {Number} [size] The size of the pool. Defaults to the number of CPUs
  12. * available. When this parameter is `null` or 0, then the
  13. * decoding will be done in the main thread.
  14. * @param {function(): Worker} [createWorker] A function that creates the decoder worker.
  15. * Defaults to a worker with all decoders that ship with geotiff.js. The `createWorker()`
  16. * function is expected to return a `Worker` compatible with Web Workers. For code that
  17. * runs in Node, [web-worker](https://www.npmjs.com/package/web-worker) is a good choice.
  18. *
  19. * A worker that uses a custom lzw decoder would look like this `my-custom-worker.js` file:
  20. * ```js
  21. * import { addDecoder, getDecoder } from 'geotiff';
  22. * addDecoder(5, () => import ('./my-custom-lzw').then((m) => m.default));
  23. * self.addEventListener('message', async (e) => {
  24. * const { id, fileDirectory, buffer } = e.data;
  25. * const decoder = await getDecoder(fileDirectory);
  26. * const decoded = await decoder.decode(fileDirectory, buffer);
  27. * self.postMessage({ decoded, id }, [decoded]);
  28. * });
  29. * ```
  30. * The way the above code is built into a worker by the `createWorker()` function
  31. * depends on the used bundler. For most bundlers, something like this will work:
  32. * ```js
  33. * function createWorker() {
  34. * return new Worker(new URL('./my-custom-worker.js', import.meta.url));
  35. * }
  36. * ```
  37. */
  38. constructor(size?: number | undefined, createWorker?: (() => Worker) | undefined);
  39. workers: any[] | null;
  40. _awaitingDecoder: Promise<any> | null;
  41. size: number;
  42. messageId: number;
  43. /**
  44. * Decode the given block of bytes with the set compression method.
  45. * @param {ArrayBuffer} buffer the array buffer of bytes to decode.
  46. * @returns {Promise<ArrayBuffer>} the decoded result as a `Promise`
  47. */
  48. decode(fileDirectory: any, buffer: ArrayBuffer): Promise<ArrayBuffer>;
  49. destroy(): void;
  50. }
  51. //# sourceMappingURL=pool.d.ts.map