@loaders.gl/compression 4.0.0-beta.3 → 4.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/dist.dev.js +6 -160
  2. package/package.json +4 -4
package/dist/dist.dev.js CHANGED
@@ -4670,10 +4670,7 @@ var __exports__ = (() => {
4670
4670
  var window_ = globals.window || globals.self || globals.global || {};
4671
4671
  var global_ = globals.global || globals.self || globals.window || {};
4672
4672
  var document_ = globals.document || {};
4673
- var isBrowser = (
4674
- // @ts-ignore process does not exist on browser
4675
- Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser)
4676
- );
4673
+ var isBrowser = Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser);
4677
4674
  var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
4678
4675
  var nodeVersion = matches && parseFloat(matches[1]) || 0;
4679
4676
 
@@ -4711,10 +4708,7 @@ var __exports__ = (() => {
4711
4708
  var window_2 = globals2.window || globals2.self || globals2.global || {};
4712
4709
  var global_2 = globals2.global || globals2.self || globals2.window || {};
4713
4710
  var document_2 = globals2.document || {};
4714
- var isBrowser2 = (
4715
- // @ts-ignore process.browser
4716
- typeof process !== "object" || String(process) !== "[object process]" || process.browser
4717
- );
4711
+ var isBrowser2 = typeof process !== "object" || String(process) !== "[object process]" || process.browser;
4718
4712
  var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
4719
4713
  var matches2 = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
4720
4714
  var nodeVersion2 = matches2 && parseFloat(matches2[1]) || 0;
@@ -4722,7 +4716,6 @@ var __exports__ = (() => {
4722
4716
  // ../worker-utils/src/lib/worker-farm/worker-job.ts
4723
4717
  var WorkerJob = class {
4724
4718
  isRunning = true;
4725
- /** Promise that resolves when Job is done */
4726
4719
  _resolve = () => {
4727
4720
  };
4728
4721
  _reject = () => {
@@ -4735,29 +4728,18 @@ var __exports__ = (() => {
4735
4728
  this._reject = reject;
4736
4729
  });
4737
4730
  }
4738
- /**
4739
- * Send a message to the job's worker thread
4740
- * @param data any data structure, ideally consisting mostly of transferrable objects
4741
- */
4742
4731
  postMessage(type, payload) {
4743
4732
  this.workerThread.postMessage({
4744
4733
  source: "loaders.gl",
4745
- // Lets worker ignore unrelated messages
4746
4734
  type,
4747
4735
  payload
4748
4736
  });
4749
4737
  }
4750
- /**
4751
- * Call to resolve the `result` Promise with the supplied value
4752
- */
4753
4738
  done(value) {
4754
4739
  assert(this.isRunning);
4755
4740
  this.isRunning = false;
4756
4741
  this._resolve(value);
4757
4742
  }
4758
- /**
4759
- * Call to reject the `result` Promise with the supplied error
4760
- */
4761
4743
  error(error) {
4762
4744
  assert(this.isRunning);
4763
4745
  this.isRunning = false;
@@ -4868,7 +4850,6 @@ var __exports__ = (() => {
4868
4850
  var WorkerThread = class {
4869
4851
  terminated = false;
4870
4852
  _loadableURL = "";
4871
- /** Checks if workers are supported on this platform */
4872
4853
  static isSupported() {
4873
4854
  return typeof Worker !== "undefined" && isBrowser2 || typeof Worker2 !== "undefined" && !isBrowser2;
4874
4855
  }
@@ -4886,10 +4867,6 @@ var __exports__ = (() => {
4886
4867
  this.onError = (error) => console.log(error);
4887
4868
  this.worker = isBrowser2 ? this._createBrowserWorker() : this._createNodeWorker();
4888
4869
  }
4889
- /**
4890
- * Terminate this worker thread
4891
- * @note Can free up significant memory
4892
- */
4893
4870
  destroy() {
4894
4871
  this.onMessage = NOOP;
4895
4872
  this.onError = NOOP;
@@ -4899,20 +4876,10 @@ var __exports__ = (() => {
4899
4876
  get isRunning() {
4900
4877
  return Boolean(this.onMessage);
4901
4878
  }
4902
- /**
4903
- * Send a message to this worker thread
4904
- * @param data any data structure, ideally consisting mostly of transferrable objects
4905
- * @param transferList If not supplied, calculated automatically by traversing data
4906
- */
4907
4879
  postMessage(data, transferList) {
4908
4880
  transferList = transferList || getTransferList(data);
4909
4881
  this.worker.postMessage(data, transferList);
4910
4882
  }
4911
- // PRIVATE
4912
- /**
4913
- * Generate a standard Error from an ErrorEvent
4914
- * @param event
4915
- */
4916
4883
  _getErrorFromErrorEvent(event) {
4917
4884
  let message = "Failed to load ";
4918
4885
  message += `worker ${this.name} from ${this.url}. `;
@@ -4924,9 +4891,6 @@ var __exports__ = (() => {
4924
4891
  }
4925
4892
  return new Error(message);
4926
4893
  }
4927
- /**
4928
- * Creates a worker thread on the browser
4929
- */
4930
4894
  _createBrowserWorker() {
4931
4895
  this._loadableURL = getLoadableWorkerURL({
4932
4896
  source: this.source,
@@ -4949,10 +4913,6 @@ var __exports__ = (() => {
4949
4913
  worker.onmessageerror = (event) => console.error(event);
4950
4914
  return worker;
4951
4915
  }
4952
- /**
4953
- * Creates a worker thread in node.js
4954
- * @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
4955
- */
4956
4916
  _createNodeWorker() {
4957
4917
  let worker;
4958
4918
  if (this.url) {
@@ -4983,7 +4943,6 @@ var __exports__ = (() => {
4983
4943
  // ../worker-utils/src/lib/worker-farm/worker-pool.ts
4984
4944
  var WorkerPool = class {
4985
4945
  name = "unnamed";
4986
- // | Function;
4987
4946
  maxConcurrency = 1;
4988
4947
  maxMobileConcurrency = 1;
4989
4948
  onDebug = () => {
@@ -4994,23 +4953,14 @@ var __exports__ = (() => {
4994
4953
  idleQueue = [];
4995
4954
  count = 0;
4996
4955
  isDestroyed = false;
4997
- /** Checks if workers are supported on this platform */
4998
4956
  static isSupported() {
4999
4957
  return WorkerThread.isSupported();
5000
4958
  }
5001
- /**
5002
- * @param processor - worker function
5003
- * @param maxConcurrency - max count of workers
5004
- */
5005
4959
  constructor(props) {
5006
4960
  this.source = props.source;
5007
4961
  this.url = props.url;
5008
4962
  this.setProps(props);
5009
4963
  }
5010
- /**
5011
- * Terminates all workers in the pool
5012
- * @note Can free up significant memory
5013
- */
5014
4964
  destroy() {
5015
4965
  this.idleQueue.forEach((worker) => worker.destroy());
5016
4966
  this.isDestroyed = true;
@@ -5049,11 +4999,6 @@ var __exports__ = (() => {
5049
4999
  this._startQueuedJob();
5050
5000
  return await startPromise;
5051
5001
  }
5052
- // PRIVATE
5053
- /**
5054
- * Starts first queued job if worker is available or can be created
5055
- * Called when job is started and whenever a worker returns to the idleQueue
5056
- */
5057
5002
  async _startQueuedJob() {
5058
5003
  if (!this.jobQueue.length) {
5059
5004
  return;
@@ -5083,23 +5028,8 @@ var __exports__ = (() => {
5083
5028
  }
5084
5029
  }
5085
5030
  }
5086
- /**
5087
- * Returns a worker to the idle queue
5088
- * Destroys the worker if
5089
- * - pool is destroyed
5090
- * - if this pool doesn't reuse workers
5091
- * - if maxConcurrency has been lowered
5092
- * @param worker
5093
- */
5094
5031
  returnWorkerToQueue(worker) {
5095
- const shouldDestroyWorker = (
5096
- // Workers on Node.js prevent the process from exiting.
5097
- // Until we figure out how to close them before exit, we always destroy them
5098
- !isBrowser2 || // If the pool is destroyed, there is no reason to keep the worker around
5099
- this.isDestroyed || // If the app has disabled worker reuse, any completed workers should be destroyed
5100
- !this.reuseWorkers || // If concurrency has been lowered, this worker might be surplus to requirements
5101
- this.count > this._getMaxConcurrency()
5102
- );
5032
+ const shouldDestroyWorker = !isBrowser2 || this.isDestroyed || !this.reuseWorkers || this.count > this._getMaxConcurrency();
5103
5033
  if (shouldDestroyWorker) {
5104
5034
  worker.destroy();
5105
5035
  this.count--;
@@ -5110,9 +5040,6 @@ var __exports__ = (() => {
5110
5040
  this._startQueuedJob();
5111
5041
  }
5112
5042
  }
5113
- /**
5114
- * Returns idle worker or creates new worker if maxConcurrency has not been reached
5115
- */
5116
5043
  _getAvailableWorker() {
5117
5044
  if (this.idleQueue.length > 0) {
5118
5045
  return this.idleQueue.shift() || null;
@@ -5143,18 +5070,14 @@ var __exports__ = (() => {
5143
5070
  };
5144
5071
  var WorkerFarm = class {
5145
5072
  workerPools = /* @__PURE__ */ new Map();
5146
- // singleton
5147
- /** Checks if workers are supported on this platform */
5148
5073
  static isSupported() {
5149
5074
  return WorkerThread.isSupported();
5150
5075
  }
5151
- /** Get the singleton instance of the global worker farm */
5152
5076
  static getWorkerFarm(props = {}) {
5153
5077
  WorkerFarm._workerFarm = WorkerFarm._workerFarm || new WorkerFarm({});
5154
5078
  WorkerFarm._workerFarm.setProps(props);
5155
5079
  return WorkerFarm._workerFarm;
5156
5080
  }
5157
- /** get global instance with WorkerFarm.getWorkerFarm() */
5158
5081
  constructor(props) {
5159
5082
  this.props = {
5160
5083
  ...DEFAULT_PROPS
@@ -5162,20 +5085,12 @@ var __exports__ = (() => {
5162
5085
  this.setProps(props);
5163
5086
  this.workerPools = /* @__PURE__ */ new Map();
5164
5087
  }
5165
- /**
5166
- * Terminate all workers in the farm
5167
- * @note Can free up significant memory
5168
- */
5169
5088
  destroy() {
5170
5089
  for (const workerPool of this.workerPools.values()) {
5171
5090
  workerPool.destroy();
5172
5091
  }
5173
5092
  this.workerPools = /* @__PURE__ */ new Map();
5174
5093
  }
5175
- /**
5176
- * Set props used when initializing worker pools
5177
- * @param props
5178
- */
5179
5094
  setProps(props) {
5180
5095
  this.props = {
5181
5096
  ...this.props,
@@ -5185,15 +5100,6 @@ var __exports__ = (() => {
5185
5100
  workerPool.setProps(this._getWorkerPoolProps());
5186
5101
  }
5187
5102
  }
5188
- /**
5189
- * Returns a worker pool for the specified worker
5190
- * @param options - only used first time for a specific worker name
5191
- * @param options.name - the name of the worker - used to identify worker pool
5192
- * @param options.url -
5193
- * @param options.source -
5194
- * @example
5195
- * const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
5196
- */
5197
5103
  getWorkerPool(options) {
5198
5104
  const {
5199
5105
  name,
@@ -5265,11 +5171,7 @@ var __exports__ = (() => {
5265
5171
  }
5266
5172
  const workerPool = workerFarm.getWorkerPool(workerPoolProps);
5267
5173
  const jobName = options.jobName || worker.name;
5268
- const job = await workerPool.startJob(
5269
- jobName,
5270
- // eslint-disable-next-line
5271
- onMessage.bind(null, context)
5272
- );
5174
+ const job = await workerPool.startJob(jobName, onMessage.bind(null, context));
5273
5175
  const transferableOptions = getTransferListForWriter(options);
5274
5176
  job.postMessage("process", {
5275
5177
  input: data,
@@ -5390,39 +5292,31 @@ var __exports__ = (() => {
5390
5292
  this.compressBatches = this.compressBatches.bind(this);
5391
5293
  this.decompressBatches = this.decompressBatches.bind(this);
5392
5294
  }
5393
- /** Preloads any dynamic libraries. May enable sync functions */
5394
5295
  async preload() {
5395
5296
  return;
5396
5297
  }
5397
- /** Asynchronously compress data */
5398
5298
  async compress(input) {
5399
5299
  await this.preload();
5400
5300
  return this.compressSync(input);
5401
5301
  }
5402
- /** Asynchronously decompress data */
5403
5302
  async decompress(input, size) {
5404
5303
  await this.preload();
5405
5304
  return this.decompressSync(input, size);
5406
5305
  }
5407
- /** Synchronously compress data */
5408
5306
  compressSync(input) {
5409
5307
  throw new Error(`${this.name}: sync compression not supported`);
5410
5308
  }
5411
- /** Synchronously compress data */
5412
5309
  decompressSync(input, size) {
5413
5310
  throw new Error(`${this.name}: sync decompression not supported`);
5414
5311
  }
5415
- /** Compress batches */
5416
5312
  async *compressBatches(asyncIterator) {
5417
5313
  const input = await this.concatenate(asyncIterator);
5418
5314
  yield this.compress(input);
5419
5315
  }
5420
- /** Decompress batches */
5421
5316
  async *decompressBatches(asyncIterator) {
5422
5317
  const input = await this.concatenate(asyncIterator);
5423
5318
  yield this.decompress(input);
5424
5319
  }
5425
- // HELPERS
5426
5320
  concatenate(asyncIterator) {
5427
5321
  return concatenateArrayBuffersAsync(asyncIterator);
5428
5322
  }
@@ -5547,26 +5441,16 @@ var __exports__ = (() => {
5547
5441
  this._chunks = [];
5548
5442
  return chunks;
5549
5443
  }
5550
- // TODO - For some reason we don't get the error message from pako in _onEnd?
5551
5444
  _getError(code = 0) {
5552
5445
  const MESSAGES = {
5553
- /* Z_NEED_DICT 2 */
5554
5446
  2: "need dictionary",
5555
- /* Z_STREAM_END 1 */
5556
5447
  1: "stream end",
5557
- /* Z_OK 0 */
5558
5448
  0: "",
5559
- /* Z_ERRNO (-1) */
5560
5449
  "-1": "file error",
5561
- /* Z_STREAM_ERROR (-2) */
5562
5450
  "-2": "stream error",
5563
- /* Z_DATA_ERROR (-3) */
5564
5451
  "-3": "data error",
5565
- /* Z_MEM_ERROR (-4) */
5566
5452
  "-4": "insufficient memory",
5567
- /* Z_BUF_ERROR (-5) */
5568
5453
  "-5": "buffer error",
5569
- /* Z_VERSION_ERROR (-6) */
5570
5454
  "-6": "incompatible version"
5571
5455
  };
5572
5456
  return `${this.name}: ${MESSAGES[code]}`;
@@ -6350,10 +6234,7 @@ var __exports__ = (() => {
6350
6234
  initializeCompoundDictionaryCopy(s, -address - 1, s.copyLength);
6351
6235
  s.runningState = 14;
6352
6236
  } else {
6353
- let dictionaryData = (
6354
- /** @type{!Int8Array} */
6355
- data
6356
- );
6237
+ let dictionaryData = data;
6357
6238
  let wordLength = s.copyLength;
6358
6239
  if (wordLength > 31) {
6359
6240
  throw "Invalid backward reference";
@@ -7333,10 +7214,7 @@ var __exports__ = (() => {
7333
7214
  let s = new State();
7334
7215
  initState(s, new InputStream(bytes));
7335
7216
  if (options) {
7336
- let customDictionary = (
7337
- /** @type {?Int8Array} */
7338
- options["customDictionary"]
7339
- );
7217
+ let customDictionary = options["customDictionary"];
7340
7218
  if (customDictionary)
7341
7219
  attachDictionaryChunk(s, customDictionary);
7342
7220
  }
@@ -7393,10 +7271,6 @@ var __exports__ = (() => {
7393
7271
  super(options);
7394
7272
  this.options = options;
7395
7273
  }
7396
- /**
7397
- * brotli is an injectable dependency due to big size
7398
- * @param options
7399
- */
7400
7274
  async preload() {
7401
7275
  brotli = brotli || this.options?.modules?.brotli;
7402
7276
  if (!brotli) {
@@ -7491,12 +7365,6 @@ var __exports__ = (() => {
7491
7365
  const inputArray = new Uint8Array(input);
7492
7366
  return lz4js.compress(inputArray).buffer;
7493
7367
  }
7494
- /**
7495
- * Decompresses an ArrayBuffer containing an Lz4 frame. maxSize is optional; if not
7496
- * provided, a maximum size will be determined by examining the data. The
7497
- * returned ArrayBuffer will always be perfectly sized.
7498
- * If data provided without magic number we will parse it as block
7499
- */
7500
7368
  decompressSync(data, maxSize) {
7501
7369
  try {
7502
7370
  const isMagicNumberExists = this.checkMagicNumber(data);
@@ -7516,15 +7384,6 @@ var __exports__ = (() => {
7516
7384
  throw this.improveError(error);
7517
7385
  }
7518
7386
  }
7519
- /**
7520
- * Decode lz4 file as block
7521
- * Solution taken from here
7522
- * https://github.com/pierrec/node-lz4/blob/0dac687262403fd34f905b963da7220692f2a4a1/lib/binding.js#L25
7523
- * @param input
7524
- * @param output
7525
- * @param startIndex
7526
- * @param endIndex
7527
- */
7528
7387
  decodeBlock(data, output, startIndex, endIndex) {
7529
7388
  startIndex = startIndex || 0;
7530
7389
  endIndex = endIndex || data.length - startIndex;
@@ -7564,10 +7423,6 @@ var __exports__ = (() => {
7564
7423
  }
7565
7424
  return uncompressedSize;
7566
7425
  }
7567
- /**
7568
- * Compare file magic with lz4 magic number
7569
- * @param input
7570
- */
7571
7426
  checkMagicNumber(data) {
7572
7427
  const magic = new Uint32Array(data.slice(0, 4));
7573
7428
  return magic[0] === LZ4_MAGIC_NUMBER;
@@ -7582,10 +7437,6 @@ var __exports__ = (() => {
7582
7437
  extensions = [];
7583
7438
  contentEncodings = [];
7584
7439
  isSupported = true;
7585
- /**
7586
- * zstd-codec is an injectable dependency due to big size
7587
- * @param options
7588
- */
7589
7440
  constructor(options) {
7590
7441
  super(options);
7591
7442
  this.options = options;
@@ -7618,11 +7469,6 @@ var __exports__ = (() => {
7618
7469
  extensions = [];
7619
7470
  contentEncodings = [];
7620
7471
  isSupported = false;
7621
- // !isBrowser;
7622
- /**
7623
- * lzo is an injectable dependency due to big size
7624
- * @param options
7625
- */
7626
7472
  constructor(options) {
7627
7473
  super(options);
7628
7474
  this.options = options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/compression",
3
- "version": "4.0.0-beta.3",
3
+ "version": "4.0.0-beta.4",
4
4
  "description": "Decompression and compression plugins for loaders.gl",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -47,8 +47,8 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@babel/runtime": "^7.3.1",
50
- "@loaders.gl/loader-utils": "4.0.0-beta.3",
51
- "@loaders.gl/worker-utils": "4.0.0-beta.3",
50
+ "@loaders.gl/loader-utils": "4.0.0-beta.4",
51
+ "@loaders.gl/worker-utils": "4.0.0-beta.4",
52
52
  "@types/brotli": "^1.3.0",
53
53
  "@types/pako": "^1.0.1",
54
54
  "fflate": "0.7.4",
@@ -66,5 +66,5 @@
66
66
  "lz4js": "^0.2.0",
67
67
  "zstd-codec": "^0.1"
68
68
  },
69
- "gitHead": "7ba9621cc51c7a26c407086ac86171f35b8712af"
69
+ "gitHead": "848c20b474532d301f2c3f8d4e1fb9bf262b86d4"
70
70
  }