MCPcopy Create free account
hub / github.com/mscdex/ssh2 / attrsToBytes

Function attrsToBytes

lib/protocol/SFTP.js:2451–2512  ·  view source on GitHub ↗
(attrs)

Source from the content-addressed store, hash-verified

2449}
2450
2451function attrsToBytes(attrs) {
2452 let flags = 0;
2453 let nb = 0;
2454
2455 if (typeof attrs === 'object' && attrs !== null) {
2456 if (typeof attrs.size === 'number') {
2457 flags |= ATTR.SIZE;
2458 const val = attrs.size;
2459 // Big Endian
2460 ATTRS_BUF[nb++] = val / 72057594037927940; // 2**56
2461 ATTRS_BUF[nb++] = val / 281474976710656; // 2**48
2462 ATTRS_BUF[nb++] = val / 1099511627776; // 2**40
2463 ATTRS_BUF[nb++] = val / 4294967296; // 2**32
2464 ATTRS_BUF[nb++] = val / 16777216; // 2**24
2465 ATTRS_BUF[nb++] = val / 65536; // 2**16
2466 ATTRS_BUF[nb++] = val / 256; // 2**8
2467 ATTRS_BUF[nb++] = val;
2468 }
2469 if (typeof attrs.uid === 'number' && typeof attrs.gid === 'number') {
2470 flags |= ATTR.UIDGID;
2471 const uid = attrs.uid;
2472 const gid = attrs.gid;
2473 // Big Endian
2474 ATTRS_BUF[nb++] = uid >>> 24;
2475 ATTRS_BUF[nb++] = uid >>> 16;
2476 ATTRS_BUF[nb++] = uid >>> 8;
2477 ATTRS_BUF[nb++] = uid;
2478 ATTRS_BUF[nb++] = gid >>> 24;
2479 ATTRS_BUF[nb++] = gid >>> 16;
2480 ATTRS_BUF[nb++] = gid >>> 8;
2481 ATTRS_BUF[nb++] = gid;
2482 }
2483 if (typeof attrs.mode === 'number' || typeof attrs.mode === 'string') {
2484 const mode = modeNum(attrs.mode);
2485 flags |= ATTR.PERMISSIONS;
2486 // Big Endian
2487 ATTRS_BUF[nb++] = mode >>> 24;
2488 ATTRS_BUF[nb++] = mode >>> 16;
2489 ATTRS_BUF[nb++] = mode >>> 8;
2490 ATTRS_BUF[nb++] = mode;
2491 }
2492 if ((typeof attrs.atime === 'number' || isDate(attrs.atime))
2493 && (typeof attrs.mtime === 'number' || isDate(attrs.mtime))) {
2494 const atime = toUnixTimestamp(attrs.atime);
2495 const mtime = toUnixTimestamp(attrs.mtime);
2496
2497 flags |= ATTR.ACMODTIME;
2498 // Big Endian
2499 ATTRS_BUF[nb++] = atime >>> 24;
2500 ATTRS_BUF[nb++] = atime >>> 16;
2501 ATTRS_BUF[nb++] = atime >>> 8;
2502 ATTRS_BUF[nb++] = atime;
2503 ATTRS_BUF[nb++] = mtime >>> 24;
2504 ATTRS_BUF[nb++] = mtime >>> 16;
2505 ATTRS_BUF[nb++] = mtime >>> 8;
2506 ATTRS_BUF[nb++] = mtime;
2507 }
2508 // TODO: extended attributes

Callers 7

openMethod · 0.85
mkdirMethod · 0.85
setstatMethod · 0.85
fsetstatMethod · 0.85
ext_openssh_lsetstatMethod · 0.85
nameMethod · 0.85
attrsMethod · 0.85

Calls 2

modeNumFunction · 0.85
toUnixTimestampFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…