function write( src, dest, db, clbk ) {
	var total;
	var files;
	var dpath;
	var fpath;
	var fopts;
	var file;
	var i;

	files = objectKeys( db );
	total = files.length;
	fopts = {
		'encoding': 'utf8'
	};
	i = -1;

	return next();

	/**
	* Writes the next file.
	*
	* @private
	*/
	function next() {
		i += 1;

		file = files[ i ];
		dpath = path.dirname( file.substring( src.length+1 ) ); // +1 to account for path separator
		dpath = path.join( dest, dpath );

		debug( 'Creating output directory: %s', dpath );
		mkdirp( dpath, onDir );
	}

	/**
	* Callback invoked upon creating an output directory.
	*
	* @private
	* @param {Error} [error] - error object
	* @returns {void}
	*/
	function onDir( error ) {
		if ( error ) {
			debug( 'Encountered an error when creating output directory. File: %s (%d of %d). Directory: %s. Error: %s', file, i+1, total, dpath, error.message );
			return clbk( error );
		}
		debug( 'Successfully created output directory.' );

		fpath = path.join( dpath, BASENAME );
		debug( 'Writing file %d of %d: %s', i+1, total, fpath );

		writeFile( fpath, db[ file ], fopts, onWrite );
	}

	/**
	* Callback invoked after writing a file.
	*
	* @private
	* @param {Error} [error] - error object
	* @returns {void}
	*/
	function onWrite( error ) {
		if ( error ) {
			debug( 'Encountered an error when writing file contents. File: %s (%d of %d). Destination: %s. Error: %s', file, i+1, total, fpath, error.message );
			return clbk( error );
		}
		debug( 'Successfully wrote file.' );
		done();
	}

	/**
	* Callback invoked upon writing file contents.
	*
	* @private
	* @returns {void}
	*/
	function done() {
		var j = i + 1;
		if ( j < total ) {
			debug( 'Wrote %d of %d files.', j, total );
			return next();
		}
		debug( 'Successfully wrote all file contents.' );
		return clbk();
	}
}
Writes a database to a file tree.

@private
@param {string} src - source directory
@param {string} dest - output directory
@param {Object} db - database
@param {Callback} clbk - callback to invoke upon completion
@returns {void}