@e-mc/compress 0.14.2 → 0.14.3
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 +3 -3
- package/package.json +3 -3
- package/worker/plugin-image.js +0 -31
- package/worker/sfnt2woff.js +0 -24
- package/worker/system-brotli.js +0 -41
- package/worker/system-gzip.js +0 -41
- package/worker/system-zstd.js +0 -41
- package/worker/wawoff2-compress.js +0 -15
- package/worker/wawoff2-decompress.js +0 -15
- package/worker/woff2sfnt.js +0 -24
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.14.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.14.3/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IModule, ModuleConstructor } from "./index";
|
|
@@ -120,8 +120,8 @@ instance.tryImage("/tmp/image.png", "/path/output/compressed.png", options)
|
|
|
120
120
|
|
|
121
121
|
## References
|
|
122
122
|
|
|
123
|
-
- https://www.unpkg.com/@e-mc/types@0.14.
|
|
124
|
-
- https://www.unpkg.com/@e-mc/types@0.14.
|
|
123
|
+
- https://www.unpkg.com/@e-mc/types@0.14.3/lib/compress.d.ts
|
|
124
|
+
- https://www.unpkg.com/@e-mc/types@0.14.3/lib/settings.d.ts
|
|
125
125
|
|
|
126
126
|
* https://www.npmjs.com/package/@types/node
|
|
127
127
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/compress",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"description": "Compress constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"license": "BSD-3-Clause",
|
|
20
20
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@e-mc/core": "0.14.
|
|
23
|
-
"@e-mc/types": "0.14.
|
|
22
|
+
"@e-mc/core": "0.14.3",
|
|
23
|
+
"@e-mc/types": "0.14.3",
|
|
24
24
|
"wawoff2": "^2.0.1",
|
|
25
25
|
"woff2sfnt-sfnt2woff": "^1.0.0"
|
|
26
26
|
}
|
package/worker/plugin-image.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { parentPort, workerData } = require('node:worker_threads');
|
|
4
|
-
const { importESM } = require('@e-mc/types');
|
|
5
|
-
const Compress = require('@e-mc/compress');
|
|
6
|
-
const PORT = workerData[0];
|
|
7
|
-
parentPort.on('message', async (value) => {
|
|
8
|
-
try {
|
|
9
|
-
const { plugin, data, options, metadata } = value;
|
|
10
|
-
let transform;
|
|
11
|
-
try {
|
|
12
|
-
transform = await importESM(plugin, true);
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
transform = require(plugin);
|
|
16
|
-
}
|
|
17
|
-
void transform(options, metadata)(Compress.asBuffer(data))
|
|
18
|
-
.then(result => {
|
|
19
|
-
try {
|
|
20
|
-
PORT.postMessage(result, [result.buffer]);
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
PORT.postMessage(result);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
console.error(err);
|
|
29
|
-
PORT.postMessage(null);
|
|
30
|
-
}
|
|
31
|
-
});
|
package/worker/sfnt2woff.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { parentPort, workerData } = require('node:worker_threads');
|
|
4
|
-
const { toWoff } = require('woff2sfnt-sfnt2woff');
|
|
5
|
-
const PORT = workerData[0];
|
|
6
|
-
parentPort.on('message', (value) => {
|
|
7
|
-
let data = null;
|
|
8
|
-
try {
|
|
9
|
-
data = toWoff(value);
|
|
10
|
-
PORT.postMessage(data, [data.buffer]);
|
|
11
|
-
}
|
|
12
|
-
catch (err) {
|
|
13
|
-
if (data) {
|
|
14
|
-
try {
|
|
15
|
-
PORT.postMessage(data);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
console.error(err);
|
|
22
|
-
PORT.postMessage(null);
|
|
23
|
-
}
|
|
24
|
-
});
|
package/worker/system-brotli.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { parentPort, workerData } = require('node:worker_threads');
|
|
4
|
-
const fs = require('node:fs');
|
|
5
|
-
const stream = require('node:stream');
|
|
6
|
-
const zlib = require('node:zlib');
|
|
7
|
-
const Compress = require('@e-mc/compress');
|
|
8
|
-
const PORT = workerData[0];
|
|
9
|
-
parentPort.on('message', async (value) => {
|
|
10
|
-
try {
|
|
11
|
-
const { data, options, output } = value;
|
|
12
|
-
const chunks = [];
|
|
13
|
-
let transform = stream.Readable.from(Compress.asBuffer(data)).pipe(zlib.createBrotliCompress(options));
|
|
14
|
-
if (output) {
|
|
15
|
-
transform = transform.pipe(fs.createWriteStream(output));
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
transform.on('data', chunk => {
|
|
19
|
-
chunks.push(chunk);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
transform
|
|
23
|
-
.on('finish', () => {
|
|
24
|
-
if (chunks.length > 0) {
|
|
25
|
-
const result = Buffer.concat(chunks);
|
|
26
|
-
PORT.postMessage(result, [result.buffer]);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
PORT.postMessage(output || null);
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
.on('error', (err) => {
|
|
33
|
-
transform.destroy();
|
|
34
|
-
throw err;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
console.error(err);
|
|
39
|
-
PORT.postMessage(null);
|
|
40
|
-
}
|
|
41
|
-
});
|
package/worker/system-gzip.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { parentPort, workerData } = require('node:worker_threads');
|
|
4
|
-
const fs = require('node:fs');
|
|
5
|
-
const stream = require('node:stream');
|
|
6
|
-
const zlib = require('node:zlib');
|
|
7
|
-
const Compress = require('@e-mc/compress');
|
|
8
|
-
const PORT = workerData[0];
|
|
9
|
-
parentPort.on('message', async (value) => {
|
|
10
|
-
try {
|
|
11
|
-
const { data, options, output } = value;
|
|
12
|
-
const chunks = [];
|
|
13
|
-
let transform = stream.Readable.from(Compress.asBuffer(data)).pipe(zlib.createGzip(options));
|
|
14
|
-
if (output) {
|
|
15
|
-
transform = transform.pipe(fs.createWriteStream(output));
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
transform.on('data', chunk => {
|
|
19
|
-
chunks.push(chunk);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
transform
|
|
23
|
-
.on('finish', () => {
|
|
24
|
-
if (chunks.length > 0) {
|
|
25
|
-
const result = Buffer.concat(chunks);
|
|
26
|
-
PORT.postMessage(result, [result.buffer]);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
PORT.postMessage(output || null);
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
.on('error', (err) => {
|
|
33
|
-
transform.destroy();
|
|
34
|
-
throw err;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
console.error(err);
|
|
39
|
-
PORT.postMessage(null);
|
|
40
|
-
}
|
|
41
|
-
});
|
package/worker/system-zstd.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { parentPort, workerData } = require('node:worker_threads');
|
|
4
|
-
const fs = require('node:fs');
|
|
5
|
-
const stream = require('node:stream');
|
|
6
|
-
const zlib = require('node:zlib');
|
|
7
|
-
const Compress = require('@e-mc/compress');
|
|
8
|
-
const PORT = workerData[0];
|
|
9
|
-
parentPort.on('message', async (value) => {
|
|
10
|
-
try {
|
|
11
|
-
const { data, options, output } = value;
|
|
12
|
-
const chunks = [];
|
|
13
|
-
let transform = stream.Readable.from(Compress.asBuffer(data)).pipe(zlib.createZstdCompress(options));
|
|
14
|
-
if (output) {
|
|
15
|
-
transform = transform.pipe(fs.createWriteStream(output));
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
transform.on('data', chunk => {
|
|
19
|
-
chunks.push(chunk);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
transform
|
|
23
|
-
.on('finish', () => {
|
|
24
|
-
if (chunks.length > 0) {
|
|
25
|
-
const result = Buffer.concat(chunks);
|
|
26
|
-
PORT.postMessage(result, [result.buffer]);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
PORT.postMessage(output || null);
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
.on('error', (err) => {
|
|
33
|
-
transform.destroy();
|
|
34
|
-
throw err;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
console.error(err);
|
|
39
|
-
PORT.postMessage(null);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { parentPort, workerData } = require('node:worker_threads');
|
|
4
|
-
const { compress } = require('wawoff2');
|
|
5
|
-
const PORT = workerData[0];
|
|
6
|
-
parentPort.on('message', (value) => {
|
|
7
|
-
compress(value)
|
|
8
|
-
.then(data => {
|
|
9
|
-
PORT.postMessage(data);
|
|
10
|
-
})
|
|
11
|
-
.catch((err) => {
|
|
12
|
-
console.error(err);
|
|
13
|
-
PORT.postMessage(null);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { parentPort, workerData } = require('node:worker_threads');
|
|
4
|
-
const { decompress } = require('wawoff2');
|
|
5
|
-
const PORT = workerData[0];
|
|
6
|
-
parentPort.on('message', (value) => {
|
|
7
|
-
decompress(value)
|
|
8
|
-
.then(data => {
|
|
9
|
-
PORT.postMessage(data);
|
|
10
|
-
})
|
|
11
|
-
.catch((err) => {
|
|
12
|
-
console.error(err);
|
|
13
|
-
PORT.postMessage(null);
|
|
14
|
-
});
|
|
15
|
-
});
|
package/worker/woff2sfnt.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { parentPort, workerData } = require('node:worker_threads');
|
|
4
|
-
const { toSfnt } = require('woff2sfnt-sfnt2woff');
|
|
5
|
-
const PORT = workerData[0];
|
|
6
|
-
parentPort.on('message', (value) => {
|
|
7
|
-
let data = null;
|
|
8
|
-
try {
|
|
9
|
-
data = toSfnt(value);
|
|
10
|
-
PORT.postMessage(data, [data.buffer]);
|
|
11
|
-
}
|
|
12
|
-
catch (err) {
|
|
13
|
-
if (data) {
|
|
14
|
-
try {
|
|
15
|
-
PORT.postMessage(data);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
console.error(err);
|
|
22
|
-
PORT.postMessage(null);
|
|
23
|
-
}
|
|
24
|
-
});
|