(data, encoding, cb)
| 192 | } |
| 193 | _read(n) {} |
| 194 | _write(data, encoding, cb) { |
| 195 | if (this.buffer === null) { |
| 196 | this.buffer = data; |
| 197 | } else { |
| 198 | const newBuffer = Buffer.allocUnsafe(this.buffer.length + data.length); |
| 199 | this.buffer.copy(newBuffer, 0); |
| 200 | data.copy(newBuffer, this.buffer.length); |
| 201 | this.buffer = newBuffer; |
| 202 | } |
| 203 | // Wait for at least all length bytes |
| 204 | if (this.buffer.length < 4) |
| 205 | return cb(); |
| 206 | |
| 207 | const len = readUInt32BE(this.buffer, 0); |
| 208 | // Make sure we have a full message before querying pageant |
| 209 | if ((this.buffer.length - 4) < len) |
| 210 | return cb(); |
| 211 | |
| 212 | data = this.buffer.slice(0, 4 + len); |
| 213 | if (this.buffer.length > (4 + len)) |
| 214 | return cb(new Error('Unexpected multiple agent requests')); |
| 215 | this.buffer = null; |
| 216 | |
| 217 | let error; |
| 218 | const proc = this.proc = spawn(EXEPATH, [ data.length ]); |
| 219 | proc.stdout.on('data', (data) => { |
| 220 | this.push(data); |
| 221 | }); |
| 222 | proc.on('error', (err) => { |
| 223 | error = err; |
| 224 | cb(error); |
| 225 | }); |
| 226 | proc.on('close', (code) => { |
| 227 | this.proc = undefined; |
| 228 | if (!error) { |
| 229 | if (error = ERROR[code]) |
| 230 | return cb(error); |
| 231 | cb(); |
| 232 | } |
| 233 | }); |
| 234 | proc.stdin.end(data); |
| 235 | } |
| 236 | _final(cb) { |
| 237 | destroy(this); |
| 238 | cb(); |
nothing calls this directly
no test coverage detected