Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = (socket, options) => {
options = options || {}
// Check if we are connected on a unix path
if (options.listeningAddr && options.listeningAddr.getPath()) {
options.remoteAddr = options.listeningAddr
}
if (options.remoteAddr && options.remoteAddr.getPath()) {
options.localAddr = options.remoteAddr
}
const { sink, source } = toIterable.duplex(socket)
const maConn = {
async sink (source) {
if (options.signal) {
source = abortable(source, options.signal)
}
try {
await sink((async function * () {
for await (const chunk of source) {
// Convert BufferList to Buffer
yield Buffer.isBuffer(chunk) ? chunk : chunk.slice()
}
})())
} catch (err) {
// If aborted we can safely ignore
if (err.type !== 'aborted') {