/* 
 * catberry-dust
 *
 * Copyright (c) 2014 Denis Rechkunov and project contributors.
 *
 * catberry-dust's license follows:
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge, 
 * publish, distribute, sublicense, and/or sell copies of the Software, 
 * and to permit persons to whom the Software is furnished to do so, 
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 * 
 * This license applies to all parts of catberry-dust that are not externally
 * maintained libraries.
 */

'use strict';

module.exports = Stub;

var Chunk = require('./Chunk');

function Stub(dust, callback) {
	this.head = new Chunk(this, null, null, dust);
	this.dust = dust;
	this.out = '';
	this.callback = callback;
}

/**
 * Flushes all data from chunks to consumer.
 */
Stub.prototype.flush = function () {
	while (this.head) {
		if (this.head.error) {
			throw this.head.error;
		}

		this.out += this.head.data.join('');
		this.head = this.head.next;
	}
	this.callback(null, this.out);
};

@@ -1698,16 +1698,61 @@
 r;%0A%09%09%7D%0A%0A
+%09%09if (!this.head.flushable) %7B%0A%09%09%09return;%0A%09%09%7D%0A
 %09%09this.o

Fix bug with Stub.