(reqid, data, encoding)
| 1896 | ); |
| 1897 | } |
| 1898 | data(reqid, data, encoding) { |
| 1899 | if (!this.server) |
| 1900 | throw new Error('Server-only method called in client mode'); |
| 1901 | |
| 1902 | const isBuffer = Buffer.isBuffer(data); |
| 1903 | |
| 1904 | if (!isBuffer && typeof data !== 'string') |
| 1905 | throw new Error('data is not a Buffer or string'); |
| 1906 | |
| 1907 | let isUTF8; |
| 1908 | if (!isBuffer && !encoding) { |
| 1909 | encoding = undefined; |
| 1910 | isUTF8 = true; |
| 1911 | } |
| 1912 | |
| 1913 | const dataLen = ( |
| 1914 | isBuffer |
| 1915 | ? data.length |
| 1916 | : Buffer.byteLength(data, encoding) |
| 1917 | ); |
| 1918 | let p = 9; |
| 1919 | const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + dataLen); |
| 1920 | |
| 1921 | writeUInt32BE(buf, buf.length - 4, 0); |
| 1922 | buf[4] = RESPONSE.DATA; |
| 1923 | writeUInt32BE(buf, reqid, 5); |
| 1924 | |
| 1925 | writeUInt32BE(buf, dataLen, p); |
| 1926 | if (dataLen) { |
| 1927 | if (isBuffer) |
| 1928 | buf.set(data, p += 4); |
| 1929 | else if (isUTF8) |
| 1930 | buf.utf8Write(data, p += 4, dataLen); |
| 1931 | else |
| 1932 | buf.write(data, p += 4, dataLen, encoding); |
| 1933 | } |
| 1934 | |
| 1935 | const isBuffered = sendOrBuffer(this, buf); |
| 1936 | this._debug && this._debug( |
| 1937 | `SFTP: Outbound: ${isBuffered ? 'Buffered' : 'Sending'} DATA` |
| 1938 | ); |
| 1939 | } |
| 1940 | name(reqid, names) { |
| 1941 | if (!this.server) |
| 1942 | throw new Error('Server-only method called in client mode'); |
no test coverage detected