ssh2-scp 2.0.3 → 2.0.5
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/dist/cjs/ssh-fs.cjs +26 -66
- package/dist/esm/ssh-fs.d.ts +2 -1
- package/dist/esm/ssh-fs.js +27 -67
- package/dist/esm/transfer.d.ts +0 -1
- package/package.json +4 -3
package/dist/cjs/ssh-fs.cjs
CHANGED
|
@@ -10,45 +10,7 @@ class SshFs {
|
|
|
10
10
|
this.session = session;
|
|
11
11
|
}
|
|
12
12
|
async detectChunkSize() {
|
|
13
|
-
|
|
14
|
-
return this._chunkSize;
|
|
15
|
-
}
|
|
16
|
-
const parseMemKb = (kb) => {
|
|
17
|
-
if (kb > 256 * 1024) {
|
|
18
|
-
return 4 * 1024;
|
|
19
|
-
} else if (kb > 128 * 1024) {
|
|
20
|
-
return 2 * 1024;
|
|
21
|
-
} else if (kb > 64 * 1024) {
|
|
22
|
-
return 1 * 1024;
|
|
23
|
-
}
|
|
24
|
-
return 512;
|
|
25
|
-
};
|
|
26
|
-
try {
|
|
27
|
-
const output = await this.runCmd("free -b");
|
|
28
|
-
const lines = output.trim().split("\n");
|
|
29
|
-
const memLine = lines.find((l) => l.startsWith("Mem:"));
|
|
30
|
-
if (memLine) {
|
|
31
|
-
const parts = memLine.trim().split(/\s+/);
|
|
32
|
-
const totalMemKb = parseInt(parts[1], 10);
|
|
33
|
-
this._chunkSize = parseMemKb(totalMemKb);
|
|
34
|
-
return this._chunkSize;
|
|
35
|
-
}
|
|
36
|
-
} catch (err) {
|
|
37
|
-
console.error("[ssh-fs] detectChunkSize: free -b failed", err);
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
const output = await this.runCmd("cat /proc/meminfo");
|
|
41
|
-
const memTotalLine = output.split("\n").find((l) => l.startsWith("MemTotal:"));
|
|
42
|
-
if (memTotalLine) {
|
|
43
|
-
const kb = parseInt(memTotalLine.split(":")[1].trim(), 10);
|
|
44
|
-
this._chunkSize = parseMemKb(kb);
|
|
45
|
-
return this._chunkSize;
|
|
46
|
-
}
|
|
47
|
-
} catch (err) {
|
|
48
|
-
console.error("[ssh-fs] detectChunkSize: /proc/meminfo failed", err);
|
|
49
|
-
}
|
|
50
|
-
this._chunkSize = 1 * 1024;
|
|
51
|
-
console.error("[ssh-fs] detectChunkSize: using default chunkSize");
|
|
13
|
+
this._chunkSize = 4 * 1024;
|
|
52
14
|
return this._chunkSize;
|
|
53
15
|
}
|
|
54
16
|
getExecOpts() {
|
|
@@ -58,30 +20,6 @@ class SshFs {
|
|
|
58
20
|
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
59
21
|
return months.indexOf(month);
|
|
60
22
|
}
|
|
61
|
-
parseMode(modeStr) {
|
|
62
|
-
const permMap = {
|
|
63
|
-
"---": 0,
|
|
64
|
-
"--x": 1,
|
|
65
|
-
"-w-": 2,
|
|
66
|
-
"-wx": 3,
|
|
67
|
-
"r--": 4,
|
|
68
|
-
"r-x": 5,
|
|
69
|
-
"rw-": 6,
|
|
70
|
-
"rwx": 7
|
|
71
|
-
};
|
|
72
|
-
const perms = modeStr.slice(1, 10);
|
|
73
|
-
const owner = permMap[perms.slice(0, 3)] || 0;
|
|
74
|
-
const group = permMap[perms.slice(3, 6)] || 0;
|
|
75
|
-
const other = permMap[perms.slice(6, 9)] || 0;
|
|
76
|
-
let fileType = 32768;
|
|
77
|
-
if (modeStr.startsWith("d")) fileType = 16384;
|
|
78
|
-
else if (modeStr.startsWith("l")) fileType = 40960;
|
|
79
|
-
else if (modeStr.startsWith("c")) fileType = 8192;
|
|
80
|
-
else if (modeStr.startsWith("b")) fileType = 24576;
|
|
81
|
-
else if (modeStr.startsWith("p")) fileType = 4096;
|
|
82
|
-
else if (modeStr.startsWith("s")) fileType = 49152;
|
|
83
|
-
return fileType | owner << 6 | group << 3 | other;
|
|
84
|
-
}
|
|
85
23
|
runCmd(cmd, timeout = 3e4) {
|
|
86
24
|
return new Promise((resolve, reject) => {
|
|
87
25
|
let timeoutId;
|
|
@@ -205,7 +143,7 @@ class SshFs {
|
|
|
205
143
|
const name = parts.slice(8).join(" ");
|
|
206
144
|
if (name === "." || name === "..") continue;
|
|
207
145
|
const type = parts[0].charAt(0);
|
|
208
|
-
const mode =
|
|
146
|
+
const mode = parseModeFromLongname(parts[0]);
|
|
209
147
|
const owner = parseInt(parts[2], 10);
|
|
210
148
|
const group = parseInt(parts[3], 10);
|
|
211
149
|
const size = parseInt(parts[4], 10);
|
|
@@ -269,7 +207,7 @@ class SshFs {
|
|
|
269
207
|
}
|
|
270
208
|
const size = parseInt(parts[4], 10);
|
|
271
209
|
const modeStr = parts[0];
|
|
272
|
-
const mode =
|
|
210
|
+
const mode = parseModeFromLongname(modeStr);
|
|
273
211
|
const uid = parseInt(parts[2], 10);
|
|
274
212
|
const gid = parseInt(parts[3], 10);
|
|
275
213
|
return {
|
|
@@ -318,7 +256,7 @@ class SshFs {
|
|
|
318
256
|
}
|
|
319
257
|
const size = parseInt(parts[4], 10);
|
|
320
258
|
const modeStr = parts[0];
|
|
321
|
-
const mode =
|
|
259
|
+
const mode = parseModeFromLongname(modeStr);
|
|
322
260
|
const uid = parseInt(parts[2], 10);
|
|
323
261
|
const gid = parseInt(parts[3], 10);
|
|
324
262
|
return {
|
|
@@ -405,5 +343,27 @@ class SshFs {
|
|
|
405
343
|
function createSshFs(session, options) {
|
|
406
344
|
return new SshFs(session, options);
|
|
407
345
|
}
|
|
346
|
+
function parseModeFromLongname(longname) {
|
|
347
|
+
if (!longname || longname.length < 10) return 0;
|
|
348
|
+
const typeMap = {
|
|
349
|
+
"-": 32768,
|
|
350
|
+
d: 16384,
|
|
351
|
+
l: 40960,
|
|
352
|
+
c: 8192,
|
|
353
|
+
b: 24576,
|
|
354
|
+
p: 4096,
|
|
355
|
+
s: 49152
|
|
356
|
+
};
|
|
357
|
+
const typeBits = typeMap[longname[0]] || 32768;
|
|
358
|
+
const permValues = [256, 128, 64, 32, 16, 8, 4, 2, 1];
|
|
359
|
+
let permBits = 0;
|
|
360
|
+
for (let i = 0; i < 9; i++) {
|
|
361
|
+
if (longname[i + 1] !== "-") {
|
|
362
|
+
permBits |= permValues[i];
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return typeBits | permBits;
|
|
366
|
+
}
|
|
408
367
|
exports.SshFs = SshFs;
|
|
409
368
|
exports.createSshFs = createSshFs;
|
|
369
|
+
exports.parseModeFromLongname = parseModeFromLongname;
|
package/dist/esm/ssh-fs.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export declare interface FileInfo {
|
|
|
18
18
|
group: number;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
export declare function parseModeFromLongname(longname: string): number;
|
|
22
|
+
|
|
21
23
|
export declare class SshFs {
|
|
22
24
|
private session;
|
|
23
25
|
private _chunkSize;
|
|
@@ -26,7 +28,6 @@ export declare class SshFs {
|
|
|
26
28
|
private detectChunkSize;
|
|
27
29
|
private getExecOpts;
|
|
28
30
|
private getMonthIndex;
|
|
29
|
-
private parseMode;
|
|
30
31
|
private runCmd;
|
|
31
32
|
private rmFolderCmd;
|
|
32
33
|
private rmCmd;
|
package/dist/esm/ssh-fs.js
CHANGED
|
@@ -8,45 +8,7 @@ class SshFs {
|
|
|
8
8
|
this.session = session;
|
|
9
9
|
}
|
|
10
10
|
async detectChunkSize() {
|
|
11
|
-
|
|
12
|
-
return this._chunkSize;
|
|
13
|
-
}
|
|
14
|
-
const parseMemKb = (kb) => {
|
|
15
|
-
if (kb > 256 * 1024) {
|
|
16
|
-
return 4 * 1024;
|
|
17
|
-
} else if (kb > 128 * 1024) {
|
|
18
|
-
return 2 * 1024;
|
|
19
|
-
} else if (kb > 64 * 1024) {
|
|
20
|
-
return 1 * 1024;
|
|
21
|
-
}
|
|
22
|
-
return 512;
|
|
23
|
-
};
|
|
24
|
-
try {
|
|
25
|
-
const output = await this.runCmd("free -b");
|
|
26
|
-
const lines = output.trim().split("\n");
|
|
27
|
-
const memLine = lines.find((l) => l.startsWith("Mem:"));
|
|
28
|
-
if (memLine) {
|
|
29
|
-
const parts = memLine.trim().split(/\s+/);
|
|
30
|
-
const totalMemKb = parseInt(parts[1], 10);
|
|
31
|
-
this._chunkSize = parseMemKb(totalMemKb);
|
|
32
|
-
return this._chunkSize;
|
|
33
|
-
}
|
|
34
|
-
} catch (err) {
|
|
35
|
-
console.error("[ssh-fs] detectChunkSize: free -b failed", err);
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
const output = await this.runCmd("cat /proc/meminfo");
|
|
39
|
-
const memTotalLine = output.split("\n").find((l) => l.startsWith("MemTotal:"));
|
|
40
|
-
if (memTotalLine) {
|
|
41
|
-
const kb = parseInt(memTotalLine.split(":")[1].trim(), 10);
|
|
42
|
-
this._chunkSize = parseMemKb(kb);
|
|
43
|
-
return this._chunkSize;
|
|
44
|
-
}
|
|
45
|
-
} catch (err) {
|
|
46
|
-
console.error("[ssh-fs] detectChunkSize: /proc/meminfo failed", err);
|
|
47
|
-
}
|
|
48
|
-
this._chunkSize = 1 * 1024;
|
|
49
|
-
console.error("[ssh-fs] detectChunkSize: using default chunkSize");
|
|
11
|
+
this._chunkSize = 4 * 1024;
|
|
50
12
|
return this._chunkSize;
|
|
51
13
|
}
|
|
52
14
|
getExecOpts() {
|
|
@@ -56,30 +18,6 @@ class SshFs {
|
|
|
56
18
|
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
57
19
|
return months.indexOf(month);
|
|
58
20
|
}
|
|
59
|
-
parseMode(modeStr) {
|
|
60
|
-
const permMap = {
|
|
61
|
-
"---": 0,
|
|
62
|
-
"--x": 1,
|
|
63
|
-
"-w-": 2,
|
|
64
|
-
"-wx": 3,
|
|
65
|
-
"r--": 4,
|
|
66
|
-
"r-x": 5,
|
|
67
|
-
"rw-": 6,
|
|
68
|
-
"rwx": 7
|
|
69
|
-
};
|
|
70
|
-
const perms = modeStr.slice(1, 10);
|
|
71
|
-
const owner = permMap[perms.slice(0, 3)] || 0;
|
|
72
|
-
const group = permMap[perms.slice(3, 6)] || 0;
|
|
73
|
-
const other = permMap[perms.slice(6, 9)] || 0;
|
|
74
|
-
let fileType = 32768;
|
|
75
|
-
if (modeStr.startsWith("d")) fileType = 16384;
|
|
76
|
-
else if (modeStr.startsWith("l")) fileType = 40960;
|
|
77
|
-
else if (modeStr.startsWith("c")) fileType = 8192;
|
|
78
|
-
else if (modeStr.startsWith("b")) fileType = 24576;
|
|
79
|
-
else if (modeStr.startsWith("p")) fileType = 4096;
|
|
80
|
-
else if (modeStr.startsWith("s")) fileType = 49152;
|
|
81
|
-
return fileType | owner << 6 | group << 3 | other;
|
|
82
|
-
}
|
|
83
21
|
runCmd(cmd, timeout = 3e4) {
|
|
84
22
|
return new Promise((resolve, reject) => {
|
|
85
23
|
let timeoutId;
|
|
@@ -203,7 +141,7 @@ class SshFs {
|
|
|
203
141
|
const name = parts.slice(8).join(" ");
|
|
204
142
|
if (name === "." || name === "..") continue;
|
|
205
143
|
const type = parts[0].charAt(0);
|
|
206
|
-
const mode =
|
|
144
|
+
const mode = parseModeFromLongname(parts[0]);
|
|
207
145
|
const owner = parseInt(parts[2], 10);
|
|
208
146
|
const group = parseInt(parts[3], 10);
|
|
209
147
|
const size = parseInt(parts[4], 10);
|
|
@@ -267,7 +205,7 @@ class SshFs {
|
|
|
267
205
|
}
|
|
268
206
|
const size = parseInt(parts[4], 10);
|
|
269
207
|
const modeStr = parts[0];
|
|
270
|
-
const mode =
|
|
208
|
+
const mode = parseModeFromLongname(modeStr);
|
|
271
209
|
const uid = parseInt(parts[2], 10);
|
|
272
210
|
const gid = parseInt(parts[3], 10);
|
|
273
211
|
return {
|
|
@@ -316,7 +254,7 @@ class SshFs {
|
|
|
316
254
|
}
|
|
317
255
|
const size = parseInt(parts[4], 10);
|
|
318
256
|
const modeStr = parts[0];
|
|
319
|
-
const mode =
|
|
257
|
+
const mode = parseModeFromLongname(modeStr);
|
|
320
258
|
const uid = parseInt(parts[2], 10);
|
|
321
259
|
const gid = parseInt(parts[3], 10);
|
|
322
260
|
return {
|
|
@@ -403,7 +341,29 @@ class SshFs {
|
|
|
403
341
|
function createSshFs(session, options) {
|
|
404
342
|
return new SshFs(session, options);
|
|
405
343
|
}
|
|
344
|
+
function parseModeFromLongname(longname) {
|
|
345
|
+
if (!longname || longname.length < 10) return 0;
|
|
346
|
+
const typeMap = {
|
|
347
|
+
"-": 32768,
|
|
348
|
+
d: 16384,
|
|
349
|
+
l: 40960,
|
|
350
|
+
c: 8192,
|
|
351
|
+
b: 24576,
|
|
352
|
+
p: 4096,
|
|
353
|
+
s: 49152
|
|
354
|
+
};
|
|
355
|
+
const typeBits = typeMap[longname[0]] || 32768;
|
|
356
|
+
const permValues = [256, 128, 64, 32, 16, 8, 4, 2, 1];
|
|
357
|
+
let permBits = 0;
|
|
358
|
+
for (let i = 0; i < 9; i++) {
|
|
359
|
+
if (longname[i + 1] !== "-") {
|
|
360
|
+
permBits |= permValues[i];
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return typeBits | permBits;
|
|
364
|
+
}
|
|
406
365
|
export {
|
|
407
366
|
SshFs,
|
|
408
|
-
createSshFs
|
|
367
|
+
createSshFs,
|
|
368
|
+
parseModeFromLongname
|
|
409
369
|
};
|
package/dist/esm/transfer.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssh2-scp",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "Remote file system operations over SSH2 session without SFTP",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "npm run build:esm && npm run build:cjs",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"build:cjs": "vite build --config build/vite.config.cjs.ts --outDir dist/cjs",
|
|
9
9
|
"test": "node test/ssh2-fs.test.mjs && node test/transfer.test.mjs",
|
|
10
10
|
"lint": "echo \"Lint not configured\" && exit 0",
|
|
11
|
-
"typecheck": "tsc --noEmit"
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"bench": "node benchmark/benchmark.js"
|
|
12
13
|
},
|
|
13
14
|
"homepage": "https://github.com/electerm/ssh2-scp#readme",
|
|
14
15
|
"bugs": {
|
|
@@ -56,4 +57,4 @@
|
|
|
56
57
|
"engines": {
|
|
57
58
|
"node": ">=22.0.0"
|
|
58
59
|
}
|
|
59
|
-
}
|
|
60
|
+
}
|