var fs = require('fs');
var path = require('path');
var sizeOf = require('image-size');
var mustache = require('mustache');
var through = require('through');
var gutil = require('gulp-util');
var mime = require('mime');
var SVGO = require('svgo');
var svgo = new SVGO();

module.exports = function(opts) {
	var tpl = fs.readFileSync(opts.styleTemplate).toString();
	var buffer = [];
	var svgs = [];

	var bufferContents = function(file) {
		var type = mime.lookup(file.path);
		var dim = sizeOf(file.path);

		if(type !== 'image/svg+xml') {
			// console.log(imgData, dim);
			dim.data = [
				'url(data:',
				mime.lookup(dim.type),
				';base64,',
				file.contents.toString('base64'),
				')'
			].join('');
			dim.name = path.basename(file.path, '.' + dim.type);
			buffer.push(dim);
		} else if(type === 'image/svg+xml') {
			svgo.optimize(file.contents.toString(), function(res) {
				dim = {
					width: dim.width,
					height: dim.height,
					data: [
						'url(data:image/svg+xml;charset=utf8,',
						encodeURIComponent(res.data),
						')'
					].join(''),
					format: 'svg',
					name: path.basename(file.path, '.svg')
				};
				buffer.push(dim);
			});
		}
	};

	var endStream = function() {
		this.emit('data', new gutil.File({
			  contents: new Buffer(mustache.render(tpl, {
				  items: buffer
			  }), 'utf8'),
			  path: opts.styleName
		  }));
		this.emit('end');
	};

	return new through(bufferContents, endStream);
};

@@ -265,16 +265,176 @@
 VGO();%0A%0A
+function strictEncodeURIComponent(str) %7B%0A%09return encodeURIComponent(str).replace(/%5B!'()*%5D/g, function(c) %7B%0A%09%09return '%25' + c.charCodeAt(0).toString(16);%0A%09%7D);%0A%7D%0A%0A
 module.e
@@ -1165,17 +1165,23 @@
 ,%0A%09%09%09%09%09%09
-e
+strictE
 ncodeURI

Support RFC 3986 strict