\href{https://npmjs.org/package/destroy}{\texttt{ }} \href{https://travis-ci.org/stream-utils/destroy}{\texttt{ }} \href{https://coveralls.io/r/stream-utils/destroy?branch=master}{\texttt{ }} !\mbox{[}License\mbox{]}\mbox{[}license-\/image\mbox{]} \href{https://npmjs.org/package/destroy}{\texttt{ }} \href{https://www.gittip.com/jonathanong/}{\texttt{ }}

Destroy a stream.

This module is meant to ensure a stream gets destroyed, handling different APIs and Node.\+js bugs.\hypertarget{md_sfcode_node_modules_destroy_README_autotoc_md8135}{}\doxysection{API}\label{md_sfcode_node_modules_destroy_README_autotoc_md8135}

\begin{DoxyCode}{0}
\DoxyCodeLine{var destroy = require('destroy') }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_destroy_README_autotoc_md8136}{}\doxysubsection{destroy(stream)}\label{md_sfcode_node_modules_destroy_README_autotoc_md8136}
Destroy the given stream. In most cases, this is identical to a simple {\ttfamily stream.\+destroy()} call. The rules are as follows for a given stream\+:


\begin{DoxyEnumerate}
\item If the {\ttfamily stream} is an instance of {\ttfamily Read\+Stream}, then call {\ttfamily stream.\+destroy()} and add a listener to the {\ttfamily open} event to call {\ttfamily stream.\+close()} if it is fired. This is for a Node.\+js bug that will leak a file descriptor if {\ttfamily .destroy()} is called before {\ttfamily open}.
\item If the {\ttfamily stream} is not an instance of {\ttfamily Stream}, then nothing happens.
\item If the {\ttfamily stream} has a {\ttfamily .destroy()} method, then call it.
\end{DoxyEnumerate}

The function returns the {\ttfamily stream} passed in as the argument.\hypertarget{md_sfcode_node_modules_destroy_README_autotoc_md8137}{}\doxysection{Example}\label{md_sfcode_node_modules_destroy_README_autotoc_md8137}

\begin{DoxyCode}{0}
\DoxyCodeLine{var destroy = require('destroy')}
\DoxyCodeLine{}
\DoxyCodeLine{var fs = require('fs')}
\DoxyCodeLine{var stream = fs.createReadStream('package.json')}
\DoxyCodeLine{}
\DoxyCodeLine{// ... and later}
\DoxyCodeLine{destroy(stream) }

\end{DoxyCode}
 