"use strict"; module.exports = function attachWritableStreamHandlers({ stream, onClose, onError }) { function detachEventHandlers() { stream.removeListener("finish", onCloseWrapper); stream.removeListener("close", onCloseWrapper); stream.removeListener("error", onErrorWrapper); } function attachEventHandlers() { stream.on("finish", onCloseWrapper); stream.on("close", onCloseWrapper); stream.on("error", onErrorWrapper); } function onCloseWrapper() { onClose(); detachEventHandlers(); } function onErrorWrapper(error) { onError(error); detachEventHandlers(); } attachEventHandlers(); };