GPL license, tested in IE11, FF and Chrome

master
Qvazar 2015-09-14 14:27:55 +02:00
rodzic 9247ffca22
commit 4877c7ca2c
5 zmienionych plików z 33 dodań i 28 usunięć

22
LICENSE
Wyświetl plik

@ -1,22 +0,0 @@
The MIT License (MIT)
Copyright (c) 2015 Sebastian Jørgensen
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.

Wyświetl plik

@ -1,10 +1,19 @@
# js-untar
Library for extracting tar files in the browser.
## Browser feature requirements
* [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer).
* [Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API).
* [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and the [Blob() constructor](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob).
As of September 2015 this includes Chrome>=20, Firefox>=13, IE>=10, Opera>=12.10 and Safari>=8.
[Web Worker transfarable objects](https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage) are used when available, increasing speed greatly. This is supported in Chrome>=21, Firefox>=18, Opera>=15 and Safari.
## Documentation
Load the module with RequireJS or similar. Module is a function that returns a modified Promise with a progress callback.
Load the module with RequireJS or similar. The module is a function that returns a modified Promise with a progress callback.
This callback is executed every time a file is extracted.
The standard Promise.then method is also called when extraction is done, with all extracted files as argument.
The standard Promise.then method is also called when extraction is done, with all extracted files as argument.
The extraction is done in a [Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) to allow the main UI thread to continue.
### Example:
@ -12,6 +21,7 @@ The standard Promise.then method is also called when extraction is done, with al
// Load the source ArrayBuffer from a XMLHttpRequest or any other way.
var sourceBuffer = ...;
// Listening to progress events
untar(sourceBuffer)
.progress(function(extractedFile) {
...
@ -19,10 +29,22 @@ The standard Promise.then method is also called when extraction is done, with al
.then(function(extractedFiles) {
...
});
untar(sourceBuffer).then(
function(extractedFiles) { // onSuccess
...
},
function(err) { // onError
...
},
function(extractedFile) { // onProgress
...
}
);
});
### File object
The returned file object has the following properties. Most of these are explained in the [Tar wikipedia entry](https://en.wikipedia.org/wiki/Tar_(computing)#File_format).
The returned file object(s) has the following properties. Most of these are explained in the [Tar wikipedia entry](https://en.wikipedia.org/wiki/Tar_(computing)#File_format).
* name = The full filename (including path and ustar filename prefix).
* mode

Wyświetl plik

@ -15,6 +15,7 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
files: [
'https://www.promisejs.org/polyfills/promise-6.1.0.js',
{pattern: 'build/**/**/*.js', included: false},
{pattern: 'spec/**/*.*', included: false},
'test-main.js'
@ -57,7 +58,7 @@ module.exports = function(config) {
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
browsers: ['Chrome', 'Firefox', 'IE'],
browserNoActivityTimeout: 60000,

Wyświetl plik

@ -39,6 +39,8 @@
"jasmine-core": "^2.3.4",
"karma": "^0.13.9",
"karma-chrome-launcher": "^0.2.0",
"karma-firefox-launcher": "^0.1.6",
"karma-ie-launcher": "^0.2.0",
"karma-jasmine": "^0.3.6",
"karma-phantomjs-launcher": "^0.2.1",
"karma-requirejs": "^0.2.2",

Wyświetl plik

@ -37,13 +37,15 @@ function ProgressivePromise(fn) {
return promise;
};
var origThen = promise.then;
promise.then = function(onSuccess, onFail, onProgress) {
Promise.prototype.then.call(promise, onSuccess, onFail);
origThen.call(promise, onSuccess, onFail);
if (onProgress !== undefined) {
promise.progress(onProgress);
}
return promise;
};