058d1ee52f19317bd3148c216e31ea9fbb007323
[osm/NG-UI.git] / src / assets / js / tar.js
1 /*
2 Copyright 2020 TATA ELXSI
3
4 Licensed under the Apache License, Version 2.0 (the 'License');
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
17 */
18 var Tar =
19 /******/ (function(modules) { // webpackBootstrap
20 /******/ // The module cache
21 /******/ var installedModules = {};
22 /******/
23 /******/ // The require function
24 /******/ function __webpack_require__(moduleId) {
25 /******/
26 /******/ // Check if module is in cache
27 /******/ if(installedModules[moduleId]) {
28 /******/ return installedModules[moduleId].exports;
29 /******/ }
30 /******/ // Create a new module (and put it into the cache)
31 /******/ var module = installedModules[moduleId] = {
32 /******/ i: moduleId,
33 /******/ l: false,
34 /******/ exports: {}
35 /******/ };
36 /******/
37 /******/ // Execute the module function
38 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
39 /******/
40 /******/ // Flag the module as loaded
41 /******/ module.l = true;
42 /******/
43 /******/ // Return the exports of the module
44 /******/ return module.exports;
45 /******/ }
46 /******/
47 /******/
48 /******/ // expose the modules object (__webpack_modules__)
49 /******/ __webpack_require__.m = modules;
50 /******/
51 /******/ // expose the module cache
52 /******/ __webpack_require__.c = installedModules;
53 /******/
54 /******/ // identity function for calling harmony imports with the correct context
55 /******/ __webpack_require__.i = function(value) { return value; };
56 /******/
57 /******/ // define getter function for harmony exports
58 /******/ __webpack_require__.d = function(exports, name, getter) {
59 /******/ if(!__webpack_require__.o(exports, name)) {
60 /******/ Object.defineProperty(exports, name, {
61 /******/ configurable: false,
62 /******/ enumerable: true,
63 /******/ get: getter
64 /******/ });
65 /******/ }
66 /******/ };
67 /******/
68 /******/ // getDefaultExport function for compatibility with non-harmony modules
69 /******/ __webpack_require__.n = function(module) {
70 /******/ var getter = module && module.__esModule ?
71 /******/ function getDefault() { return module['default']; } :
72 /******/ function getModuleExports() { return module; };
73 /******/ __webpack_require__.d(getter, 'a', getter);
74 /******/ return getter;
75 /******/ };
76 /******/
77 /******/ // Object.prototype.hasOwnProperty.call
78 /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
79 /******/
80 /******/ // __webpack_public_path__
81 /******/ __webpack_require__.p = "";
82 /******/
83 /******/ // Load entry module and return exports
84 /******/ return __webpack_require__(__webpack_require__.s = 2);
85 /******/ })
86 /************************************************************************/
87 /******/ ([
88 /* 0 */
89 /***/ (function(module, exports) {
90
91 /*
92 * tar-js
93 * MIT (c) 2011 T. Jameson Little
94 */
95
96 (function () {
97 "use strict";
98
99 var lookup = [
100 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
101 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
102 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
103 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
104 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
105 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
106 'w', 'x', 'y', 'z', '0', '1', '2', '3',
107 '4', '5', '6', '7', '8', '9', '+', '/'
108 ];
109 function clean(length) {
110 var i, buffer = new Uint8Array(length);
111 for (i = 0; i < length; i += 1) {
112 buffer[i] = 0;
113 }
114 return buffer;
115 }
116
117 function extend(orig, length, addLength, multipleOf) {
118 var newSize = length + addLength,
119 buffer = clean((parseInt(newSize / multipleOf) + 1) * multipleOf);
120
121 buffer.set(orig);
122
123 return buffer;
124 }
125
126 function pad(num, bytes, base) {
127 num = num.toString(base || 8);
128 return "000000000000".substr(num.length + 12 - bytes) + num;
129 }
130
131 function stringToUint8 (input, out, offset) {
132 var i, length;
133
134 out = out || clean(input.length);
135
136 offset = offset || 0;
137 for (i = 0, length = input.length; i < length; i += 1) {
138 out[offset] = input.charCodeAt(i);
139 offset += 1;
140 }
141
142 return out;
143 }
144
145 function uint8ToBase64(uint8) {
146 var i,
147 extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
148 output = "",
149 temp, length;
150
151 function tripletToBase64 (num) {
152 return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
153 };
154
155 // go through the array every three bytes, we'll deal with trailing stuff later
156 for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
157 temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
158 output += tripletToBase64(temp);
159 }
160
161 // this prevents an ERR_INVALID_URL in Chrome (Firefox okay)
162 switch (output.length % 4) {
163 case 1:
164 output += '=';
165 break;
166 case 2:
167 output += '==';
168 break;
169 default:
170 break;
171 }
172
173 return output;
174 }
175
176 module.exports.clean = clean;
177 module.exports.pad = pad;
178 module.exports.extend = extend;
179 module.exports.stringToUint8 = stringToUint8;
180 module.exports.uint8ToBase64 = uint8ToBase64;
181 }());
182
183
184 /***/ }),
185 /* 1 */
186 /***/ (function(module, exports, __webpack_require__) {
187
188 /*
189 * tar-js
190 * MIT (c) 2011 T. Jameson Little
191 */
192
193 (function () {
194 "use strict";
195
196 /*
197 struct posix_header { // byte offset
198 char name[100]; // 0
199 char mode[8]; // 100
200 char uid[8]; // 108
201 char gid[8]; // 116
202 char size[12]; // 124
203 char mtime[12]; // 136
204 char chksum[8]; // 148
205 char typeflag; // 156
206 char linkname[100]; // 157
207 char magic[6]; // 257
208 char version[2]; // 263
209 char uname[32]; // 265
210 char gname[32]; // 297
211 char devmajor[8]; // 329
212 char devminor[8]; // 337
213 char prefix[155]; // 345
214 // 500
215 };
216 */
217
218 var utils = __webpack_require__(0),
219 headerFormat;
220
221 headerFormat = [
222 {
223 'field': 'fileName',
224 'length': 100
225 },
226 {
227 'field': 'fileMode',
228 'length': 8
229 },
230 {
231 'field': 'uid',
232 'length': 8
233 },
234 {
235 'field': 'gid',
236 'length': 8
237 },
238 {
239 'field': 'fileSize',
240 'length': 12
241 },
242 {
243 'field': 'mtime',
244 'length': 12
245 },
246 {
247 'field': 'checksum',
248 'length': 8
249 },
250 {
251 'field': 'type',
252 'length': 1
253 },
254 {
255 'field': 'linkName',
256 'length': 100
257 },
258 {
259 'field': 'ustar',
260 'length': 8
261 },
262 {
263 'field': 'owner',
264 'length': 32
265 },
266 {
267 'field': 'group',
268 'length': 32
269 },
270 {
271 'field': 'majorNumber',
272 'length': 8
273 },
274 {
275 'field': 'minorNumber',
276 'length': 8
277 },
278 {
279 'field': 'filenamePrefix',
280 'length': 155
281 },
282 {
283 'field': 'padding',
284 'length': 12
285 }
286 ];
287
288 function formatHeader(data, cb) {
289 var buffer = utils.clean(512),
290 offset = 0;
291
292 headerFormat.forEach(function (value) {
293 var str = data[value.field] || "",
294 i, length;
295
296 for (i = 0, length = str.length; i < length; i += 1) {
297 buffer[offset] = str.charCodeAt(i);
298 offset += 1;
299 }
300
301 offset += value.length - i; // space it out with nulls
302 });
303
304 if (typeof cb === 'function') {
305 return cb(buffer, offset);
306 }
307 return buffer;
308 }
309
310 module.exports.structure = headerFormat;
311 module.exports.format = formatHeader;
312 }());
313
314
315 /***/ }),
316 /* 2 */
317 /***/ (function(module, exports, __webpack_require__) {
318
319 /*
320 * tar-js
321 * MIT (c) 2011 T. Jameson Little
322 */
323
324 (function () {
325 "use strict";
326
327 var header = __webpack_require__(1),
328 utils = __webpack_require__(0),
329 recordSize = 512,
330 blockSize;
331
332 function Tar(recordsPerBlock) {
333 this.written = 0;
334 blockSize = (recordsPerBlock || 20) * recordSize;
335 this.out = utils.clean(blockSize);
336 }
337
338 Tar.prototype.append = function (filepath, input, opts, callback) {
339 var data,
340 checksum,
341 mode,
342 mtime,
343 uid,
344 gid,
345 headerArr;
346
347 if (typeof input === 'string') {
348 input = utils.stringToUint8(input);
349 } else if (input.constructor !== Uint8Array.prototype.constructor) {
350 throw 'Invalid input type. You gave me: ' + input.constructor.toString().match(/function\s*([$A-Za-z_][0-9A-Za-z_]*)\s*\(/)[1];
351 }
352
353 if (typeof opts === 'function') {
354 callback = opts;
355 opts = {};
356 }
357
358 opts = opts || {};
359
360 mode = opts.mode || parseInt('777', 8) & 0xfff;
361 mtime = opts.mtime || Math.floor(+new Date() / 1000);
362 uid = opts.uid || 0;
363 gid = opts.gid || 0;
364
365 data = {
366 fileName: filepath,
367 fileMode: utils.pad(mode, 7),
368 uid: utils.pad(uid, 7),
369 gid: utils.pad(gid, 7),
370 fileSize: utils.pad(input.length, 11),
371 mtime: utils.pad(mtime, 11),
372 checksum: ' ',
373 type: opts.type || '0',
374 ustar: 'ustar ',
375 owner: opts.owner || '',
376 group: opts.group || ''
377 };
378
379 // calculate the checksum
380 checksum = 0;
381 Object.keys(data).forEach(function (key) {
382 var i, value = data[key], length;
383
384 for (i = 0, length = value.length; i < length; i += 1) {
385 checksum += value.charCodeAt(i);
386 }
387 });
388
389 data.checksum = utils.pad(checksum, 6) + "\u0000 ";
390
391 headerArr = header.format(data);
392
393 var i, offset, length;
394
395 this.out.set(headerArr, this.written);
396
397 this.written += headerArr.length;
398
399 // If there is not enough space in this.out, we need to expand it to
400 // fit the new input.
401 if (this.written + input.length > this.out.length) {
402 this.out = utils.extend(this.out, this.written, input.length, blockSize);
403 }
404
405 this.out.set(input, this.written);
406
407 // to the nearest multiple of recordSize
408 this.written += input.length + (recordSize - (input.length % recordSize || recordSize));
409
410 // make sure there's at least 2 empty records worth of extra space
411 if (this.out.length - this.written < recordSize * 2) {
412 this.out = utils.extend(this.out, this.written, recordSize * 2, blockSize);
413 }
414
415 if (typeof callback === 'function') {
416 callback(this.out);
417 }
418
419 return this.out;
420 };
421
422 Tar.prototype.clear = function () {
423 this.written = 0;
424 this.out = utils.clean(blockSize);
425 };
426
427 module.exports = Tar;
428 }());
429
430
431 /***/ })
432 /******/ ]);