<commit_before>
/* Make a zip file, uses (if available) builtin browser blob
	functionality to get around URL size limit on base64 encoded zip
*/
function buildZip(name, data) {
	var zip = new JSZip();
	folder = zip.folder("instagram-" + name);
	for (item in data) {
		folder.file("image" + data[item]["id"] + ".png", data[item]["data"], {base64: true});
	}

	if (window.Blob) {

		content = zip.generate({base64: false});

		// Builds a byte array from our zip data
		// Ref: http://stackoverflow.com/questions/13790949/downloading-generated-binary-content-contains-utf-8-encoded-chars-in-disk-file
		len = content.length;
		bytes = new Uint8Array(len);
		for( var i = 0; i < len; ++i ) {
			bytes[i] = content.charCodeAt(i);
		}

		var blob = new Blob([bytes], { type : 'application/zip' });
		var oURL = (window.URL || window.webkitURL);

		oURL = oURL.createObjectURL(blob);
		location.href = oURL;

	} else {
		content = zip.generate();
		location.href="data:application/zip;base64,"+ content;
	}

	// Fire an event to let everyone know we're done
	$.event.trigger({
		type: "built",
		message: "Zip complete!",
		time: new Date()
	});
}

/* Wraps the metadata fetching and image conversion
*/
function zipImages(user, items) {

	$.event.trigger({
		type: "building",
		message: "Building zip!",
		time: new Date()
	});
	var instagrams = new Array();
	var response = false;


	$.event.trigger({
		type: "imgload",
		message: "Loading images...",
		time: new Date()
	});

	$.each(items, function(index, metagram){
		var img = metagram.images.standard_resolution

		// Tried using YQL for this, but there's a 25KB limit on base64 image results :(
		$.getJSON("https://base64convert.orchestra.io/?url=" + img.url + "&callback=?", function(converted){
			instagrams.push({"data": converted.data,
			"id": metagram.id})
			if (instagrams.length == items.length) {
				buildZip(user, instagrams);
			}
		})
	});
	return response;
}

function getMeta(user, max_id){
	/*
		Use YQL as a JSONP proxy
	*/

	var url;
	if (max_id == null) {
		url = [ "https://query.yahooapis.com/v1/public/yql?q=",
		"select%20*%20from%20json%20where%20url%3D%22http%3A%2F%2Finstagram.com%2F",
		user, "%2Fmedia%22&format=json&callback=?"].join("");
	} else {
		url = [ "https://query.yahooapis.com/v1/public/yql?q=",
		"select%20*%20from%20json%20where%20url%3D%22http%3A%2F%2Finstagram.com%2F",
		user, "%2Fmedia%3Fmax_id%3D", max_id, "D%22&format=json&callback=?"].join("");<commit_msg>comment the base64 converter URL (make a bit more obvious)<commit_after>
/* Make a zip file, uses (if available) builtin browser blob
	functionality to get around URL size limit on base64 encoded zip
*/
function buildZip(name, data) {
	var zip = new JSZip();
	folder = zip.folder("instagram-" + name);
	for (item in data) {
		folder.file("image" + data[item]["id"] + ".png", data[item]["data"], {base64: true});
	}

	if (window.Blob) {

		content = zip.generate({base64: false});

		// Builds a byte array from our zip data
		// Ref: http://stackoverflow.com/questions/13790949/downloading-generated-binary-content-contains-utf-8-encoded-chars-in-disk-file
		len = content.length;
		bytes = new Uint8Array(len);
		for( var i = 0; i < len; ++i ) {
			bytes[i] = content.charCodeAt(i);
		}

		var blob = new Blob([bytes], { type : 'application/zip' });
		var oURL = (window.URL || window.webkitURL);

		oURL = oURL.createObjectURL(blob);
		location.href = oURL;

	} else {
		content = zip.generate();
		location.href="data:application/zip;base64,"+ content;
	}

	// Fire an event to let everyone know we're done
	$.event.trigger({
		type: "built",
		message: "Zip complete!",
		time: new Date()
	});
}

/* Wraps the metadata fetching and image conversion
*/
function zipImages(user, items) {

	/* The location of the base64 converter.
	 * @param url		(required)	Image URL
	 * @param callback	(required)  JS callback
	 */
	var base64_converter = "https://base64convert.orchestra.io/";

	$.event.trigger({
		type: "building",
		message: "Building zip!",
		time: new Date()
	});
	var instagrams = new Array();
	var response = false;


	$.event.trigger({
		type: "imgload",
		message: "Loading images...",
		time: new Date()
	});

	$.each(items, function(index, metagram){
		var img = metagram.images.standard_resolution

		// Tried using YQL for this, but there's a 25KB limit on base64 image results :(
		$.getJSON(base64_converter + "?url=" + img.url + "&callback=?", function(converted){
			instagrams.push({"data": converted.data,
			"id": metagram.id})
			if (instagrams.length == items.length) {
				buildZip(user, instagrams);
			}
		})
	});
	return response;
}

function getMeta(user, max_id){
	/*
		Use YQL as a JSONP proxy
	*/

	var url;
	if (max_id == null) {
		url = [ "https://query.yahooapis.com/v1/public/yql?q=",
		"select%20*%20from%20json%20where%20url%3D%22http%3A%2F%2Finstagram.com%2F",
		user, "%2Fmedia%22&format=json&callback=?"].join("");
	} else {
		url = [ "https://query.yahooapis.com/v1/public/yql?q=",
		"select%20*%20from%20json%20where%20url%3D%22http%3A%2F%2Finstagram.com%2F",
		user, "%2Fmedia%3Fmax_id%3D", max_id, "D%22&format=json&callback=?"].join("");
{'fraction_non_alphanumeric': 0.1739468064453504, 'fraction_numerical': 0.0283440108716754, 'mean_word_length': 4.050980392156863, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2703844', 'n_tokens_mistral': 2079, 'n_tokens_neox': 1864, 'n_words': 438}