@e-mc/compress 0.8.27 → 0.8.28
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 +4 -4
- package/index.js +16 -4
- package/package.json +3 -3
- package/worker/plugin-image.js +0 -34
- package/worker/sfnt2woff.js +0 -23
- package/worker/system-brotli.js +0 -40
- package/worker/system-gzip.js +0 -40
- package/worker/wawoff2-compress.js +0 -14
- package/worker/wawoff2-decompress.js +0 -14
- package/worker/woff2sfnt.js +0 -23
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.28/lib/index.d.ts
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { CompressLevel } from "./squared";
|
|
@@ -51,9 +51,9 @@ interface CompressConstructor extends ModuleConstructor {
|
|
|
51
51
|
|
|
52
52
|
## References
|
|
53
53
|
|
|
54
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
55
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
56
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
54
|
+
- https://www.unpkg.com/@e-mc/types@0.8.28/lib/squared.d.ts
|
|
55
|
+
- https://www.unpkg.com/@e-mc/types@0.8.28/lib/compress.d.ts
|
|
56
|
+
- https://www.unpkg.com/@e-mc/types@0.8.28/lib/settings.d.ts
|
|
57
57
|
|
|
58
58
|
## LICENSE
|
|
59
59
|
|
package/index.js
CHANGED
|
@@ -181,15 +181,21 @@ class Compress extends module_1.default {
|
|
|
181
181
|
return this.getReadable(file).pipe(zlib.createGzip(gzip));
|
|
182
182
|
}
|
|
183
183
|
createBrotliCompress(file, options) {
|
|
184
|
-
var _a;
|
|
184
|
+
var _a, _b;
|
|
185
|
+
var _c;
|
|
185
186
|
let level, chunkSize, mimeType;
|
|
186
187
|
if (options) {
|
|
187
188
|
({ level, chunkSize, mimeType } = options);
|
|
188
189
|
}
|
|
189
|
-
|
|
190
|
-
let brotli = this.module.brotli;
|
|
190
|
+
let brotli = this.module.brotli, params = {};
|
|
191
191
|
if ((0, types_1.isPlainObject)(brotli)) {
|
|
192
|
-
|
|
192
|
+
if ((0, types_1.isPlainObject)(brotli.params)) {
|
|
193
|
+
brotli = (0, types_1.cloneObject)(brotli, true);
|
|
194
|
+
params = brotli.params;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
brotli = { ...brotli, params };
|
|
198
|
+
}
|
|
193
199
|
}
|
|
194
200
|
else {
|
|
195
201
|
brotli = { params };
|
|
@@ -202,6 +208,12 @@ class Compress extends module_1.default {
|
|
|
202
208
|
else {
|
|
203
209
|
(_a = brotli.chunkSize) !== null && _a !== void 0 ? _a : (brotli.chunkSize = this.chunkSize);
|
|
204
210
|
}
|
|
211
|
+
if (typeof level === 'number') {
|
|
212
|
+
params[zlib.constants.BROTLI_PARAM_QUALITY] = level;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
(_b = params[_c = zlib.constants.BROTLI_PARAM_QUALITY]) !== null && _b !== void 0 ? _b : (params[_c] = this.level.br);
|
|
216
|
+
}
|
|
205
217
|
return this.getReadable(file).pipe(zlib.createBrotliCompress(brotli));
|
|
206
218
|
}
|
|
207
219
|
createWriteStreamAsGzip(file, output, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/compress",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.28",
|
|
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": "MIT",
|
|
24
24
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@e-mc/module": "0.8.
|
|
27
|
-
"@e-mc/types": "0.8.
|
|
26
|
+
"@e-mc/module": "0.8.28",
|
|
27
|
+
"@e-mc/types": "0.8.28",
|
|
28
28
|
"tinify": "^1.8.0",
|
|
29
29
|
"wawoff2": "^2.0.1",
|
|
30
30
|
"woff2sfnt-sfnt2woff": "^1.0.0"
|
package/worker/plugin-image.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
});
|
package/worker/sfnt2woff.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
let data = null;
|
|
7
|
-
try {
|
|
8
|
-
data = toWoff(value);
|
|
9
|
-
PORT.postMessage(data, [data.buffer]);
|
|
10
|
-
}
|
|
11
|
-
catch (err) {
|
|
12
|
-
if (data) {
|
|
13
|
-
try {
|
|
14
|
-
PORT.postMessage(data);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
console.error(err);
|
|
21
|
-
PORT.postMessage(null);
|
|
22
|
-
}
|
|
23
|
-
});
|
package/worker/system-brotli.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
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
|
-
});
|
package/worker/system-gzip.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
});
|
package/worker/woff2sfnt.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
let data = null;
|
|
7
|
-
try {
|
|
8
|
-
data = toSfnt(value);
|
|
9
|
-
PORT.postMessage(data, [data.buffer]);
|
|
10
|
-
}
|
|
11
|
-
catch (err) {
|
|
12
|
-
if (data) {
|
|
13
|
-
try {
|
|
14
|
-
PORT.postMessage(data);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
console.error(err);
|
|
21
|
-
PORT.postMessage(null);
|
|
22
|
-
}
|
|
23
|
-
});
|