molly-db 1.0.23 → 1.0.26
Sign up to get free protection for your applications and to get access to all the features.
- package/main.js +2 -2
- package/module/_init_.js +1 -3
- package/module/_worker_.js +9 -6
- package/package.json +2 -2
package/main.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
const worker = require('worker_threads');
|
2
2
|
const url = require('url');
|
3
3
|
const fs = require('fs');
|
4
|
+
const os = require('os');
|
4
5
|
|
5
6
|
/* --------------------------------------------------------------------------------------- */
|
6
7
|
|
@@ -15,13 +16,12 @@ function config( _config ) {
|
|
15
16
|
/* --------------------------------------------------------------------------------------- */
|
16
17
|
|
17
18
|
class molly_db{
|
18
|
-
|
19
19
|
constructor( opt ){ if( opt.pass )
|
20
20
|
this.pass = opt.pass; this.port = opt.port || 27017;
|
21
21
|
this.path = opt.path.replace( /^\./,process.cwd() );
|
22
|
+
this.threads = opt.threads || os.cpus().length;
|
22
23
|
return require(`${__dirname}/module/_worker_.js`)(this);
|
23
24
|
}
|
24
|
-
|
25
25
|
}
|
26
26
|
|
27
27
|
/* --------------------------------------------------------------------------------------- */
|
package/module/_init_.js
CHANGED
@@ -6,9 +6,7 @@ function fillDB( _db, _table, _path ){
|
|
6
6
|
|
7
7
|
if( (/^http/).test(_path) ){ try{
|
8
8
|
const stream = await fetch(_path,{responseType:'stream'});
|
9
|
-
_itr = readline.createInterface({
|
10
|
-
input: stream.data
|
11
|
-
})
|
9
|
+
_itr = readline.createInterface({ input: stream.data });
|
12
10
|
} catch(e) { console.log(`error reading ${_path}`); return response(); }}
|
13
11
|
|
14
12
|
else if( fs.existsSync(_path) )
|
package/module/_worker_.js
CHANGED
@@ -10,8 +10,8 @@ const fs = require('fs');
|
|
10
10
|
|
11
11
|
/* --------------------------------------------------------------------------------------- */
|
12
12
|
|
13
|
-
let query;
|
14
13
|
const db = new Object();
|
14
|
+
let query;
|
15
15
|
|
16
16
|
/* --------------------------------------------------------------------------------------- */
|
17
17
|
|
@@ -31,19 +31,22 @@ function app(req,res){
|
|
31
31
|
|
32
32
|
module.exports = (args)=>{ query = args;
|
33
33
|
return new Promise((response,reject)=>{
|
34
|
-
|
34
|
+
|
35
|
+
if ( cluster.isPrimary ) { for ( let i=query.threads; i--; ) {
|
36
|
+
const worker = cluster.fork();
|
37
|
+
worker.on('message', (msg)=>{ console.log(msg); response(); });
|
35
38
|
cluster.on('exit', (worker, code, signal) => { cluster.fork();
|
36
39
|
console.log(`worker ${worker.process.pid} died`);
|
37
|
-
});
|
38
|
-
|
39
|
-
} else {
|
40
|
+
}); worker.on('exit', (msg)=>{ reject(msg); });
|
41
|
+
}} else {
|
40
42
|
http.createServer( app ).listen( query.port,()=>{
|
41
43
|
_init_().then(()=>{ process.send({
|
42
44
|
workerID: process.pid, port: query.port,
|
43
45
|
protocol: 'HTTP', status: 'started',
|
44
46
|
})}).catch(e=>{ console.log(e); });
|
45
|
-
});
|
47
|
+
});
|
46
48
|
}
|
49
|
+
|
47
50
|
});
|
48
51
|
}
|
49
52
|
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"license": "MIT",
|
3
3
|
"main": "main.js",
|
4
|
-
"version": "1.0.
|
4
|
+
"version": "1.0.26",
|
5
5
|
"name": "molly-db",
|
6
6
|
"author": "bececrazy",
|
7
7
|
"scripts": {
|
@@ -11,7 +11,7 @@
|
|
11
11
|
"dependencies": {
|
12
12
|
"crypto-js": "^4.1.1",
|
13
13
|
"fs": "^0.0.1-security",
|
14
|
-
"molly-fetch": "^1.0.
|
14
|
+
"molly-fetch": "^1.0.16"
|
15
15
|
},
|
16
16
|
"description": "Molly-db is a free and open source library for nodejs that allow you create a lightweight encrypted database using Json files",
|
17
17
|
"keywords": [
|