tinytar-node10
Version:
Pure javascript implementation of POSIX TAR file format.
2 lines • 8.45 kB
JavaScript
!function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.tinyTar=e():r.tinyTar=e()}(this,function(){return function(r){function e(n){if(t[n])return t[n].exports;var i=t[n]={exports:{},id:n,loaded:!1};return r[n].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var t={};return e.m=r,e.c=t,e.p="",e(0)}([function(r,e,t){"use strict";var n=t(1),i=t(2),o=t(3),u=t(5);n.extend(r.exports,o,u,i)},function(r,e){"use strict";function t(r){return r===T}function n(r){return"string"==typeof r||"[object String]"==Object.prototype.toString.call(r)}function i(r){return"[object Date]"==Object.prototype.toString.call(r)}function o(r){return null!==r&&"object"==typeof r}function u(r){return"function"==typeof r}function c(r){return"number"==typeof r&&r>-1&&r%1==0&&r<=x}function a(r){return"[object Array]"==Object.prototype.toString.call(r)}function f(r){return o(r)&&!u(r)&&c(r.length)}function s(r){return"[object ArrayBuffer]"==Object.prototype.toString.call(r)}function p(r,e){return Array.prototype.map.call(r,e)}function l(r,e){var t=T;return u(e)&&Array.prototype.every.call(r,function(r,n,i){var o=e(r,n,i);return o&&(t=r),!o}),t}function d(r){return Object.assign.apply(null,arguments)}function h(r){var e,t,i;if(n(r)){for(t=r.length,i=new Uint8Array(t),e=0;e<t;e++)i[e]=255&r.charCodeAt(e);return i}return s(r)?new Uint8Array(r):o(r)&&s(r.buffer)?new Uint8Array(r.buffer):f(r)?new Uint8Array(r):o(r)&&u(r.toString)?h(r.toString()):new Uint8Array}var x=9007199254740991,T=function(r){return r}();r.exports.MAX_SAFE_INTEGER=x,r.exports.isUndefined=t,r.exports.isString=n,r.exports.isObject=o,r.exports.isDateTime=i,r.exports.isFunction=u,r.exports.isArray=a,r.exports.isArrayLike=f,r.exports.isArrayBuffer=s,r.exports.map=p,r.exports.find=l,r.exports.extend=d,r.exports.toUint8Array=h},function(r,e){"use strict";var t="\0";r.exports={NULL_CHAR:t,TMAGIC:"ustar"+t+"00",OLDGNU_MAGIC:"ustar "+t,REGTYPE:0,LNKTYPE:1,SYMTYPE:2,CHRTYPE:3,BLKTYPE:4,DIRTYPE:5,FIFOTYPE:6,CONTTYPE:7,TSUID:parseInt("4000",8),TSGID:parseInt("2000",8),TSVTX:parseInt("1000",8),TUREAD:parseInt("0400",8),TUWRITE:parseInt("0200",8),TUEXEC:parseInt("0100",8),TGREAD:parseInt("0040",8),TGWRITE:parseInt("0020",8),TGEXEC:parseInt("0010",8),TOREAD:parseInt("0004",8),TOWRITE:parseInt("0002",8),TOEXEC:parseInt("0001",8),TPERMALL:parseInt("0777",8),TPERMMASK:parseInt("0777",8)}},function(r,e,t){"use strict";function n(r){return p.recordSize}function i(r){return Math.ceil(r.data.length/p.recordSize)*p.recordSize}function o(r){var e=0;return r.forEach(function(r){e+=n(r)+i(r)}),e+=2*p.recordSize,new Uint8Array(e)}function u(r,e,t){t=parseInt(t)||0;var i=t;p.posixHeader.forEach(function(t){for(var n=t[3](e,t),o=n.length,u=0;u<o;u+=1)r[i+u]=255&n.charCodeAt(u);i+=t[1]});var o=s.find(p.posixHeader,function(r){return"checksum"==r[0]});if(o){var u=p.calculateChecksum(r,t,!0),c=p.formatTarNumber(u,o[1]-2)+f.NULL_CHAR+" ";i=t+o[2];for(var a=0;a<c.length;a+=1)r[i]=255&c.charCodeAt(a),i++}return t+n(e)}function c(r,e,t){return t=parseInt(t,10)||0,r.set(e.data,t),t+i(e)}function a(r){r=s.map(r,function(r){return s.extend({},r,{data:s.toUint8Array(r.data)})});var e=o(r),t=0;return r.forEach(function(r){t=u(e,r,t),t=c(e,r,t)}),e}var f=t(2),s=t(1),p=t(4);r.exports.tar=a},function(r,e,t){"use strict";function n(r){if(8==r.length){var e=r.split("");if(e[5]==l.NULL_CHAR)return" "!=e[6]&&e[6]!=l.NULL_CHAR||(e[6]="0")," "!=e[7]&&e[7]!=l.NULL_CHAR||(e[7]="0"),e=e.join(""),e==l.TMAGIC?e:r;if(e[7]==l.NULL_CHAR)return e[5]==l.NULL_CHAR&&(e[5]=" "),e[6]==l.NULL_CHAR&&(e[6]=" "),e==l.OLDGNU_MAGIC?e:r}return r}function i(r,e){return e-=1,p.isUndefined(r)&&(r=""),r=(""+r).substr(0,e),r+l.NULL_CHAR}function o(r,e,t){for(t=parseInt(t)||0,e-=1,r=(parseInt(r)||t).toString(8).substr(-e,e);r.length<e;)r="0"+r;return r+l.NULL_CHAR}function u(r,e){if(p.isDateTime(r))r=Math.floor(1*r/1e3);else if(r=parseInt(r,10),isFinite(r)){if(r<=0)return""}else r=Math.floor(1*new Date/1e3);return o(r,e,0)}function c(r,e){var t=String.fromCharCode.apply(null,r);if(e)return t;var n=t.indexOf(l.NULL_CHAR);return n>=0?t.substr(0,n):t}function a(r){var e=String.fromCharCode.apply(null,r);return parseInt(e.replace(/^0+$/g,""),8)||0}function f(r){return 0==r.length||0==r[0]?null:new Date(1e3*a(r))}function s(r,e,t){var n=parseInt(e,10)||0,i=Math.min(n+A,r.length),o=0,u=0,c=0;t&&m.every(function(r){return"checksum"!=r[0]||(u=n+r[2],c=u+r[1],!1)});for(var a=" ".charCodeAt(0),f=n;f<i;f++){var s=f>=u&&f<c?a:r[f];o=(o+s)%262144}return o}var p=t(1),l=t(2),d=512,h=l.TPERMALL,x=0,T=0,m=[["name",100,0,function(r,e){return i(r[e[0]],e[1])},function(r,e,t){return c(r.slice(e,e+t[1]))}],["mode",8,100,function(r,e){var t=r[e[0]]||h;return t&=l.TPERMMASK,o(t,e[1],h)},function(r,e,t){var n=a(r.slice(e,e+t[1]));return n&=l.TPERMMASK}],["uid",8,108,function(r,e){return o(r[e[0]],e[1],x)},function(r,e,t){return a(r.slice(e,e+t[1]))}],["gid",8,116,function(r,e){return o(r[e[0]],e[1],T)},function(r,e,t){return a(r.slice(e,e+t[1]))}],["size",12,124,function(r,e){return o(r.data.length,e[1])},function(r,e,t){return a(r.slice(e,e+t[1]))}],["modifyTime",12,136,function(r,e){return u(r[e[0]],e[1])},function(r,e,t){return f(r.slice(e,e+t[1]))}],["checksum",8,148,function(r,e){return" "},function(r,e,t){return a(r.slice(e,e+t[1]))}],["type",1,156,function(r,e){return""+(parseInt(r[e[0]],10)||0)%8},function(r,e,t){return(parseInt(String.fromCharCode(r[e]),10)||0)%8}],["linkName",100,157,function(r,e){return""},function(r,e,t){return c(r.slice(e,e+t[1]))}],["ustar",8,257,function(r,e){return l.TMAGIC},function(r,e,t){return n(c(r.slice(e,e+t[1]),!0))},function(r,e){return r[e[0]]==l.TMAGIC||r[e[0]]==l.OLDGNU_MAGIC}],["owner",32,265,function(r,e){return i(r[e[0]],e[1])},function(r,e,t){return c(r.slice(e,e+t[1]))}],["group",32,297,function(r,e){return i(r[e[0]],e[1])},function(r,e,t){return c(r.slice(e,e+t[1]))}],["majorNumber",8,329,function(r,e){return""},function(r,e,t){return a(r.slice(e,e+t[1]))}],["minorNumber",8,337,function(r,e){return""},function(r,e,t){return a(r.slice(e,e+t[1]))}],["prefix",131,345,function(r,e){return i(r[e[0]],e[1])},function(r,e,t){return c(r.slice(e,e+t[1]))}],["accessTime",12,476,function(r,e){return u(r[e[0]],e[1])},function(r,e,t){return f(r.slice(e,e+t[1]))}],["createTime",12,488,function(r,e){return u(r[e[0]],e[1])},function(r,e,t){return f(r.slice(e,e+t[1]))}]],A=function(r){var e=r[r.length-1];return e[2]+e[1]}(m);r.exports.recordSize=d,r.exports.defaultFileMode=h,r.exports.defaultUid=x,r.exports.defaultGid=T,r.exports.posixHeader=m,r.exports.effectiveHeaderSize=A,r.exports.calculateChecksum=s,r.exports.formatTarString=i,r.exports.formatTarNumber=o,r.exports.formatTarDateTime=u,r.exports.parseTarString=c,r.exports.parseTarNumber=a,r.exports.parseTarDateTime=f},function(r,e,t){"use strict";function n(r){return l.recordSize}function i(r){return Math.ceil(r/l.recordSize)*l.recordSize}function o(r,e){for(var t=e,n=Math.min(r.length,e+2*l.recordSize),i=t;i<n;i++)if(0!=r[i])return!1;return!0}function u(r,e,t){if(r.length-e<l.recordSize){if(t.checkFileSize)throw new Error(x.unexpectedEndOfFile);return null}e=parseInt(e)||0;var n={},i=e;if(l.posixHeader.forEach(function(e){n[e[0]]=e[4](r,i,e),i+=e[1]}),0!=n.type&&(n.size=0),t.checkHeader&&l.posixHeader.forEach(function(r){if(p.isFunction(r[5])&&!r[5](n,r)){var t=new Error(x.fileCorrupted);throw t.data={offset:e+r[2],field:r[0]},t}}),t.checkChecksum){var o=l.calculateChecksum(r,e,!0);if(o!=n.checksum){var u=new Error(x.checksumCheckFailed);throw u.data={offset:e,header:n,checksum:o},u}}return n}function c(r,e,t,n){return n.extractData?t.size<=0?new Uint8Array:r.slice(e,e+t.size):null}function a(r,e){var t={};return l.posixHeader.forEach(function(e){var n=e[0];h[n]||(t[n]=r[n])}),t.isOldGNUFormat=r.ustar==s.OLDGNU_MAGIC,e&&(t.data=e),t}function f(r,e){e=p.extend({},d,e);for(var t=[],f=0,s=r.length;s-f>=l.recordSize;){r=p.toUint8Array(r);var h=u(r,f,e);if(!h)break;f+=n(h);var x=c(r,f,h,e);if(t.push(a(h,x)),f+=i(h.size),o(r,f))break}return t}var s=t(2),p=t(1),l=t(4),d={extractData:!0,checkHeader:!0,checkChecksum:!0,checkFileSize:!0},h={size:!0,checksum:!0,ustar:!0},x={unexpectedEndOfFile:"Unexpected end of file.",fileCorrupted:"File is corrupted.",checksumCheckFailed:"Checksum check failed."};r.exports.untar=f}])});
//# sourceMappingURL=tinytar.min.js.map