// Require our core node modules.
var stream = require( "stream" );
var util = require( "util" );


// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //


// Create an instance of our writable stream and try to write to it.
var myStream = new SomeStream();

// CAUTION: This will ERROR because at this point in time, we were able to call
// the constructor (SomeStream) due to function-hoisting; but, the .inherits() and
// .prototype lines of code have not had a chance to run. As such, SomeStream has not
// had a chance to actually inherit from stream.Writable at this point.
myStream.write( "Hello world!" );
myStream.write( "What it be like?!" );


// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //


// I am a sub-class of Writable stream.
function SomeStream() {

	// Call the super constructor.
	stream.Writable.call( this );

}

util.inherits( SomeStream, stream.Writable );


// When you write to this stream, all I do is turn around and log it to the console.
SomeStream.prototype._write = function( chunk, encoding, doneWriting ) {

	console.log( "Written to stream:", chunk.toString( "utf-8" ) );

	doneWriting();

};