@e-mc/compress 0.11.3 → 0.11.5

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.
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.11.3/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.11.5/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { IModule, ModuleConstructor } from "./index";
@@ -116,9 +116,9 @@ instance.tryImage("/tmp/image.png", "/path/output/compressed.png", options)
116
116
 
117
117
  ## References
118
118
 
119
- - https://www.unpkg.com/@e-mc/types@0.11.3/lib/squared.d.ts
120
- - https://www.unpkg.com/@e-mc/types@0.11.3/lib/compress.d.ts
121
- - https://www.unpkg.com/@e-mc/types@0.11.3/lib/settings.d.ts
119
+ - https://www.unpkg.com/@e-mc/types@0.11.5/lib/squared.d.ts
120
+ - https://www.unpkg.com/@e-mc/types@0.11.5/lib/compress.d.ts
121
+ - https://www.unpkg.com/@e-mc/types@0.11.5/lib/settings.d.ts
122
122
 
123
123
  * https://www.npmjs.com/package/@types/node
124
124
 
package/index.js CHANGED
@@ -616,10 +616,10 @@ class Compress extends module_1 {
616
616
  try {
617
617
  let transform;
618
618
  try {
619
- transform = require(plugin);
619
+ transform = await (0, types_1.importESM)(plugin, true);
620
620
  }
621
621
  catch {
622
- transform = await (0, types_1.importESM)(plugin, true);
622
+ transform = require(plugin);
623
623
  }
624
624
  const out = transform.call(this, options.options, options.mimeType);
625
625
  if (timeout > 0) {
@@ -642,7 +642,7 @@ class Compress extends module_1 {
642
642
  });
643
643
  }
644
644
  set chunkSize(value) {
645
- this[kChunkSize] = !isNaN(value = (0, types_1.alignSize)(value, 1)) ? value : NaN;
645
+ this[kChunkSize] = !isNaN(value = (0, types_1.alignSize)(value, 1)) ? value : undefined;
646
646
  }
647
647
  get chunkSize() {
648
648
  return this[kChunkSize];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/compress",
3
- "version": "0.11.3",
3
+ "version": "0.11.5",
4
4
  "description": "Compress constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -23,8 +23,8 @@
23
23
  "license": "BSD-3-Clause",
24
24
  "homepage": "https://github.com/anpham6/e-mc#readme",
25
25
  "dependencies": {
26
- "@e-mc/module": "0.11.3",
27
- "@e-mc/types": "0.11.3",
26
+ "@e-mc/module": "0.11.5",
27
+ "@e-mc/types": "0.11.5",
28
28
  "wawoff2": "^2.0.1",
29
29
  "woff2sfnt-sfnt2woff": "^1.0.0"
30
30
  }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ const node_worker_threads_1 = require("node:worker_threads");
3
+ const types_1 = require("@e-mc/types");
4
+ const index_1 = require("@e-mc/compress");
5
+ const PORT = node_worker_threads_1.workerData[0];
6
+ node_worker_threads_1.parentPort.on('message', async (value) => {
7
+ try {
8
+ const { plugin, data, options, metadata } = value;
9
+ let transform;
10
+ try {
11
+ transform = await (0, types_1.importESM)(plugin, true);
12
+ }
13
+ catch {
14
+ transform = require(plugin);
15
+ }
16
+ transform(options, metadata)(index_1.asBuffer(data))
17
+ .then(result => {
18
+ try {
19
+ PORT.postMessage(result, [result.buffer]);
20
+ }
21
+ catch {
22
+ PORT.postMessage(result);
23
+ }
24
+ })
25
+ .catch((err) => {
26
+ console.error(err);
27
+ PORT.postMessage(null);
28
+ });
29
+ }
30
+ catch (err) {
31
+ console.error(err);
32
+ PORT.postMessage(null);
33
+ }
34
+ });
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ const node_worker_threads_1 = require("node:worker_threads");
3
+ const { toWoff } = require('woff2sfnt-sfnt2woff');
4
+ const PORT = node_worker_threads_1.workerData[0];
5
+ node_worker_threads_1.parentPort.on('message', (value) => {
6
+ try {
7
+ const data = toWoff(value);
8
+ PORT.postMessage(data, [data.buffer]);
9
+ }
10
+ catch (err) {
11
+ console.error(err);
12
+ PORT.postMessage(null);
13
+ }
14
+ });
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ const node_worker_threads_1 = require("node:worker_threads");
3
+ const fs = require("node:fs");
4
+ const stream = require("node:stream");
5
+ const zlib = require("node:zlib");
6
+ const index_1 = require("@e-mc/compress");
7
+ const PORT = node_worker_threads_1.workerData[0];
8
+ node_worker_threads_1.parentPort.on('message', async (value) => {
9
+ try {
10
+ const { data, options, output } = value;
11
+ const chunks = [];
12
+ let transform = stream.Readable.from(index_1.asBuffer(data)).pipe(zlib.createBrotliCompress(options));
13
+ if (output) {
14
+ transform = transform.pipe(fs.createWriteStream(output));
15
+ }
16
+ else {
17
+ transform.on('data', chunk => {
18
+ chunks.push(chunk);
19
+ });
20
+ }
21
+ transform
22
+ .on('finish', () => {
23
+ if (chunks.length > 0) {
24
+ const result = Buffer.concat(chunks);
25
+ PORT.postMessage(result, [result.buffer]);
26
+ }
27
+ else {
28
+ PORT.postMessage(output || null);
29
+ }
30
+ })
31
+ .on('error', (err) => {
32
+ transform.destroy();
33
+ throw err;
34
+ });
35
+ }
36
+ catch (err) {
37
+ console.error(err);
38
+ PORT.postMessage(null);
39
+ }
40
+ });
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ const node_worker_threads_1 = require("node:worker_threads");
3
+ const fs = require("node:fs");
4
+ const stream = require("node:stream");
5
+ const zlib = require("node:zlib");
6
+ const index_1 = require("@e-mc/compress");
7
+ const PORT = node_worker_threads_1.workerData[0];
8
+ node_worker_threads_1.parentPort.on('message', async (value) => {
9
+ try {
10
+ const { data, options, output } = value;
11
+ const chunks = [];
12
+ let transform = stream.Readable.from(index_1.asBuffer(data)).pipe(zlib.createGzip(options));
13
+ if (output) {
14
+ transform = transform.pipe(fs.createWriteStream(output));
15
+ }
16
+ else {
17
+ transform.on('data', chunk => {
18
+ chunks.push(chunk);
19
+ });
20
+ }
21
+ transform
22
+ .on('finish', () => {
23
+ if (chunks.length > 0) {
24
+ const result = Buffer.concat(chunks);
25
+ PORT.postMessage(result, [result.buffer]);
26
+ }
27
+ else {
28
+ PORT.postMessage(output || null);
29
+ }
30
+ })
31
+ .on('error', (err) => {
32
+ transform.destroy();
33
+ throw err;
34
+ });
35
+ }
36
+ catch (err) {
37
+ console.error(err);
38
+ PORT.postMessage(null);
39
+ }
40
+ });
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ const node_worker_threads_1 = require("node:worker_threads");
3
+ const wawoff2 = require("wawoff2");
4
+ const PORT = node_worker_threads_1.workerData[0];
5
+ node_worker_threads_1.parentPort.on('message', (value) => {
6
+ wawoff2.compress(value)
7
+ .then(data => {
8
+ PORT.postMessage(data);
9
+ })
10
+ .catch((err) => {
11
+ console.error(err);
12
+ PORT.postMessage(null);
13
+ });
14
+ });
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ const node_worker_threads_1 = require("node:worker_threads");
3
+ const wawoff2 = require("wawoff2");
4
+ const PORT = node_worker_threads_1.workerData[0];
5
+ node_worker_threads_1.parentPort.on('message', (value) => {
6
+ wawoff2.decompress(value)
7
+ .then(data => {
8
+ PORT.postMessage(data);
9
+ })
10
+ .catch((err) => {
11
+ console.error(err);
12
+ PORT.postMessage(null);
13
+ });
14
+ });
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ const node_worker_threads_1 = require("node:worker_threads");
3
+ const { toSfnt } = require('woff2sfnt-sfnt2woff');
4
+ const PORT = node_worker_threads_1.workerData[0];
5
+ node_worker_threads_1.parentPort.on('message', (value) => {
6
+ try {
7
+ const data = toSfnt(value);
8
+ PORT.postMessage(data, [data.buffer]);
9
+ }
10
+ catch (err) {
11
+ console.error(err);
12
+ PORT.postMessage(null);
13
+ }
14
+ });