lib/conversion.js
function convertToZStream(stream, options) {
	if(stream._isZStream) return stream;

	if(isRequestStream(stream)) {
		// Request Stream
		return new RequestStream(stream, options);
	}

	if(isClassicStream(stream)) {
		if(stream.readable && stream.writable) {
			// Duplex
			return new ClassicDuplex(stream, options);
		} else if(stream.readable) {
			// Readable
			return new ClassicReadable(stream, options);
		} else {
			// Writable
			return new ClassicWritable(stream, options);
		}
	}

	var origFuncs = {};
	for(var key in stream) {
		origFuncs[key] = stream[key];
	}
	// Use duck typing in case of multiple stream implementations
	extend(stream, streamMixins.prototype);
	streamMixins.call(stream, origFuncs);
	if(stream.read) {
		extend(stream, readableMixins.prototype);
		readableMixins.call(stream);
	}
	if(stream.write) {
		extend(stream, writableMixins.prototype);
		writableMixins.call(stream);
	}
	if(typeof process === 'object' && (stream === process.stdout || stream === process.stderr)) {
		// Don't abort stdio streams on error
		stream._zNoAbort = true;
	}
	return stream;
}
function convertToZStream(stream, options) {
	if(stream._isZStream) return stream;

	if(isRequestStream(stream)) {
		// Request Stream
		return new RequestStream(stream, options);
	}

	if(isClassicStream(stream)) {
		if(stream.readable && stream.writable) {
			// Duplex
			return new ClassicDuplex(stream, options);
		} else if(stream.readable) {
			// Readable
			return new ClassicReadable(stream, options);
		} else {
			// Writable
			return new ClassicWritable(stream, options);
		}
	}

	var origFuncs = {};
	for(var key in stream) {
		origFuncs[key] = stream[key];
	}
	// Use duck typing in case of multiple stream implementations
	extend(stream, streamMixins.prototype);
	streamMixins.call(stream, origFuncs);
	if(stream.read) {
		extend(stream, readableMixins.prototype);
		readableMixins.call(stream);
	}
	if(stream.write) {
		extend(stream, writableMixins.prototype);
		writableMixins.call(stream);
	}
	if(typeof process === 'object' && (stream === process.stdout || stream === process.stderr)) {
		// Don't abort stdio streams on error
		stream._zNoAbort = true;
	}
	return stream;
}
function convertToZStream ( stream , options ) { if ( stream . _isZStream ) return stream ; if ( isRequestStream ( stream ) ) { // Request Stream return new RequestStream ( stream , options ) ; } if ( isClassicStream ( stream ) ) { if ( stream . readable && stream . writable ) { // Duplex return new ClassicDuplex ( stream , options ) ; } else if ( stream . readable ) { // Readable return new ClassicReadable ( stream , options ) ; } else { // Writable return new ClassicWritable ( stream , options ) ; } } var origFuncs = { } ; for ( var key in stream ) { origFuncs [ key ] = stream [ key ] ; } // Use duck typing in case of multiple stream implementations extend ( stream , streamMixins . prototype ) ; streamMixins . call ( stream , origFuncs ) ; if ( stream . read ) { extend ( stream , readableMixins . prototype ) ; readableMixins . call ( stream ) ; } if ( stream . write ) { extend ( stream , writableMixins . prototype ) ; writableMixins . call ( stream ) ; } if ( typeof process === 'object' && ( stream === process . stdout || stream === process . stderr ) ) { // Don't abort stdio streams on error stream . _zNoAbort = true ; } return stream ; }
Convert a Stream into a ZStream. Either by wrapping it, or adding ZStream mixins

@class zstreams
@static
@method convertToZStream
@param {Stream} stream - The stream to try converting into a ZStream
@param {Object} [options] - If expecting to convert, this will be passed as options into the stream being instanciated.
Convert a Stream into a ZStream . Either by wrapping it or adding ZStream mixins