Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic auth and update uglify #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/jszip-utils-ie.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/*

JSZipUtils - A collection of cross-browser utilities to go along with JSZip.
<http://stuk.github.io/jszip-utils>
Expand Down
6 changes: 4 additions & 2 deletions dist/jszip-utils-ie.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions dist/jszip-utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/*

JSZipUtils - A collection of cross-browser utilities to go along with JSZip.
<http://stuk.github.io/jszip-utils>
Expand Down Expand Up @@ -34,7 +34,7 @@ function createActiveXHR() {
}

// Create the request object
var createXHR = window.ActiveXObject ?
var createXHR = (typeof window !== "undefined" && window.ActiveXObject) ?
/* Microsoft failed to properly
* implement the XMLHttpRequest in IE7 (can't request local files),
* so we use the ActiveXObject when it is available
Expand All @@ -49,7 +49,7 @@ var createXHR = window.ActiveXObject ?



JSZipUtils.getBinaryContent = function(path, callback) {
JSZipUtils.getBinaryContent = function(path, callback, auth) {
/*
* Here is the tricky part : getting the data.
* In firefox/chrome/opera/... setting the mimeType to 'text/plain; charset=x-user-defined'
Expand All @@ -70,6 +70,10 @@ JSZipUtils.getBinaryContent = function(path, callback) {

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good PR.
I'm wondering if it's also possible to include here:

xhr.withCredentials = true;

This for most of the cases will do the job.

Cheers

xhr.open('GET', path, true);

if (auth) {
xhr.setRequestHeader("Authorization", "Basic " + auth);
}

// recent browsers
if ("responseType" in xhr) {
xhr.responseType = "arraybuffer";
Expand Down
45 changes: 43 additions & 2 deletions dist/jszip-utils.min.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/*

JSZipUtils - A collection of cross-browser utilities to go along with JSZip.
<http://stuk.github.io/jszip-utils>
Expand All @@ -7,4 +7,45 @@ JSZipUtils - A collection of cross-browser utilities to go along with JSZip.
Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip-utils/master/LICENSE.markdown.

*/
!function(a){"object"==typeof exports?module.exports=a():"function"==typeof define&&define.amd?define(a):"undefined"!=typeof window?window.JSZipUtils=a():"undefined"!=typeof global?global.JSZipUtils=a():"undefined"!=typeof self&&(self.JSZipUtils=a())}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){"use strict";function c(){try{return new window.XMLHttpRequest}catch(a){}}function d(){try{return new window.ActiveXObject("Microsoft.XMLHTTP")}catch(a){}}var e={};e._getBinaryFromXHR=function(a){return a.response||a.responseText};var f=window.ActiveXObject?function(){return c()||d()}:c;e.getBinaryContent=function(a,b){try{var c=f();c.open("GET",a,!0),"responseType"in c&&(c.responseType="arraybuffer"),c.overrideMimeType&&c.overrideMimeType("text/plain; charset=x-user-defined"),c.onreadystatechange=function(){var d,f;if(4===c.readyState)if(200===c.status||0===c.status){d=null,f=null;try{d=e._getBinaryFromXHR(c)}catch(g){f=new Error(g)}b(f,d)}else b(new Error("Ajax error for "+a+" : "+this.status+" "+this.statusText),null)},c.send()}catch(d){b(new Error(d),null)}},b.exports=e},{}]},{},[1])(1)});
!function(a){"object"==typeof exports?module.exports=a():"function"==typeof define&&define.amd?define(a):"undefined"!=typeof window?window.JSZipUtils=a():"undefined"!=typeof global?global.JSZipUtils=a():"undefined"!=typeof self&&(self.JSZipUtils=a())}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){"use strict";
// taken from jQuery
function d(){try{return new window.XMLHttpRequest}catch(a){}}function e(){try{return new window.ActiveXObject("Microsoft.XMLHTTP")}catch(a){}}var f={};
// just use the responseText with xhr1, response with xhr2.
// The transformation doesn't throw away high-order byte (with responseText)
// because JSZip handles that case. If not used with JSZip, you may need to
// do it, see https://developer.mozilla.org/En/Using_XMLHttpRequest#Handling_binary_data
f._getBinaryFromXHR=function(a){
// for xhr.responseText, the 0xFF mask is applied by JSZip
return a.response||a.responseText};
// Create the request object
var g="undefined"!=typeof window&&window.ActiveXObject?/* Microsoft failed to properly
* implement the XMLHttpRequest in IE7 (can't request local files),
* so we use the ActiveXObject when it is available
* Additionally XMLHttpRequest can be disabled in IE7/IE8 so
* we need a fallback.
*/
function(){return d()||e()}:
// For all other browsers, use the standard XMLHttpRequest object
d;f.getBinaryContent=function(a,b,c){/*
* Here is the tricky part : getting the data.
* In firefox/chrome/opera/... setting the mimeType to 'text/plain; charset=x-user-defined'
* is enough, the result is in the standard xhr.responseText.
* cf https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Receiving_binary_data_in_older_browsers
* In IE <= 9, we must use (the IE only) attribute responseBody
* (for binary data, its content is different from responseText).
* In IE 10, the 'charset=x-user-defined' trick doesn't work, only the
* responseType will work :
* http://msdn.microsoft.com/en-us/library/ie/hh673569%28v=vs.85%29.aspx#Binary_Object_upload_and_download
*
* I'd like to use jQuery to avoid this XHR madness, but it doesn't support
* the responseType attribute : http://bugs.jquery.com/ticket/11461
*/
try{var d=g();d.open("GET",a,!0),c&&d.setRequestHeader("Authorization","Basic "+c),
// recent browsers
"responseType"in d&&(d.responseType="arraybuffer"),
// older browser
d.overrideMimeType&&d.overrideMimeType("text/plain; charset=x-user-defined"),d.onreadystatechange=function(c){var e,g;
// use `xhr` and not `this`... thanks IE
if(4===d.readyState)if(200===d.status||0===d.status){e=null,g=null;try{e=f._getBinaryFromXHR(d)}catch(h){g=new Error(h)}b(g,e)}else b(new Error("Ajax error for "+a+" : "+this.status+" "+this.statusText),null)},d.send()}catch(e){b(new Error(e),null)}},
// export
b.exports=f},{}]},{},[1])(1)});
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var createXHR = (typeof window !== "undefined" && window.ActiveXObject) ?



JSZipUtils.getBinaryContent = function(path, callback) {
JSZipUtils.getBinaryContent = function(path, callback, auth) {
/*
* Here is the tricky part : getting the data.
* In firefox/chrome/opera/... setting the mimeType to 'text/plain; charset=x-user-defined'
Expand All @@ -60,6 +60,10 @@ JSZipUtils.getBinaryContent = function(path, callback) {

xhr.open('GET', path, true);

if (auth) {
xhr.setRequestHeader("Authorization", "Basic " + auth);
}

// recent browsers
if ("responseType" in xhr) {
xhr.responseType = "arraybuffer";
Expand Down
2 changes: 1 addition & 1 deletion lib/license_header.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/*

JSZipUtils - A collection of cross-browser utilities to go along with JSZip.
<http://stuk.github.io/jszip-utils>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"browserify": "~2.35.0",
"grunt-browserify": "~1.3.0",
"grunt-contrib-jshint": "~0.6.4",
"grunt-contrib-uglify": "~0.2.4"
"grunt-contrib-uglify": "~1.0.2"
},
"dependencies":{
},
"license": "MIT or GPLv3"
"license": "(MIT OR GPL-3.0)"
}