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