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

Method name

lib/protocol/SFTP.js:1940–2056  ·  view source on GitHub ↗
(reqid, names)

Source from the content-addressed store, hash-verified

1938 );
1939 }
1940 name(reqid, names) {
1941 if (!this.server)
1942 throw new Error('Server-only method called in client mode');
1943
1944 if (!Array.isArray(names)) {
1945 if (typeof names !== 'object' || names === null)
1946 throw new Error('names is not an object or array');
1947 names = [ names ];
1948 }
1949
1950 const count = names.length;
1951 let namesLen = 0;
1952 let nameAttrs;
1953 const attrs = [];
1954
1955 for (let i = 0; i < count; ++i) {
1956 const name = names[i];
1957 const filename = (
1958 !name || !name.filename || typeof name.filename !== 'string'
1959 ? ''
1960 : name.filename
1961 );
1962 namesLen += 4 + Buffer.byteLength(filename);
1963 const longname = (
1964 !name || !name.longname || typeof name.longname !== 'string'
1965 ? ''
1966 : name.longname
1967 );
1968 namesLen += 4 + Buffer.byteLength(longname);
1969
1970 if (typeof name.attrs === 'object' && name.attrs !== null) {
1971 nameAttrs = attrsToBytes(name.attrs);
1972 namesLen += 4 + nameAttrs.nb;
1973
1974 if (nameAttrs.nb) {
1975 let bytes;
1976
1977 if (nameAttrs.nb === ATTRS_BUF.length) {
1978 bytes = new Uint8Array(ATTRS_BUF);
1979 } else {
1980 bytes = new Uint8Array(nameAttrs.nb);
1981 bufferCopy(ATTRS_BUF, bytes, 0, nameAttrs.nb, 0);
1982 }
1983
1984 nameAttrs.bytes = bytes;
1985 }
1986
1987 attrs.push(nameAttrs);
1988 } else {
1989 namesLen += 4;
1990 attrs.push(null);
1991 }
1992 }
1993
1994 let p = 9;
1995 const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + namesLen);
1996
1997 writeUInt32BE(buf, buf.length - 4, 0);

Callers 2

test-sftp.jsFile · 0.80

Calls 5

attrsToBytesFunction · 0.85
bufferCopyFunction · 0.85
writeUInt32BEFunction · 0.85
sendOrBufferFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected