@eluvio/elv-client-js 3.1.96 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/ElvClient-min.js +11 -15
  2. package/dist/ElvClient-node-min.js +13 -17
  3. package/dist/ElvFrameClient-min.js +9 -13
  4. package/dist/ElvPermissionsClient-min.js +9 -13
  5. package/dist/src/AuthorizationClient.js +1980 -2238
  6. package/dist/src/ContentObjectVerification.js +173 -164
  7. package/dist/src/Crypto.js +324 -376
  8. package/dist/src/ElvClient.js +1022 -1182
  9. package/dist/src/ElvWallet.js +95 -119
  10. package/dist/src/EthClient.js +896 -1040
  11. package/dist/src/FrameClient.js +300 -331
  12. package/dist/src/HttpClient.js +147 -153
  13. package/dist/src/Id.js +3 -1
  14. package/dist/src/PermissionsClient.js +1168 -1294
  15. package/dist/src/RemoteSigner.js +211 -263
  16. package/dist/src/UserProfileClient.js +1023 -1164
  17. package/dist/src/Utils.js +217 -212
  18. package/dist/src/client/ABRPublishing.js +858 -895
  19. package/dist/src/client/AccessGroups.js +959 -1102
  20. package/dist/src/client/ContentAccess.js +3434 -3727
  21. package/dist/src/client/ContentManagement.js +2068 -2252
  22. package/dist/src/client/Contracts.js +563 -647
  23. package/dist/src/client/Files.js +1757 -1886
  24. package/dist/src/client/NFT.js +112 -126
  25. package/dist/src/client/NTP.js +422 -478
  26. package/dist/src/index.js +11 -0
  27. package/dist/src/marketplaceClient/ClientMethods.js +1918 -0
  28. package/dist/src/marketplaceClient/Configuration.js +29 -0
  29. package/dist/src/marketplaceClient/Utils.js +304 -0
  30. package/dist/src/marketplaceClient/index.js +1553 -0
  31. package/dist/src/walletClient/ClientMethods.js +1828 -0
  32. package/dist/src/walletClient/Configuration.js +29 -0
  33. package/dist/src/walletClient/Utils.js +290 -0
  34. package/dist/src/walletClient/index.js +1459 -0
  35. package/package.json +5 -3
  36. package/src/ElvClient.js +4 -1
  37. package/src/Utils.js +44 -3
  38. package/src/index.js +7 -0
  39. package/src/walletClient/ClientMethods.js +1016 -0
  40. package/src/walletClient/Configuration.js +40 -0
  41. package/src/walletClient/README.md +185 -0
  42. package/src/walletClient/Utils.js +234 -0
  43. package/src/walletClient/index.js +884 -0
  44. package/testScripts/TestMarketplaceClient.js +25 -0
@@ -2,11 +2,9 @@ var _defineProperty = require("@babel/runtime/helpers/defineProperty");
2
2
 
3
3
  var _regeneratorRuntime = require("@babel/runtime/regenerator");
4
4
 
5
- var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
5
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
6
6
 
7
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
-
9
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
10
8
 
11
9
  /**
12
10
  * Methods for accessing and managing access groups
@@ -45,57 +43,51 @@ var _require = require("../Validation"),
45
43
  */
46
44
 
47
45
 
48
- exports.ListFiles = /*#__PURE__*/function () {
49
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
50
- var libraryId, objectId, versionHash, path;
51
- return _regeneratorRuntime.wrap(function _callee$(_context) {
52
- while (1) {
53
- switch (_context.prev = _context.next) {
54
- case 0:
55
- libraryId = _ref.libraryId, objectId = _ref.objectId, versionHash = _ref.versionHash;
56
- ValidateParameters({
57
- libraryId: libraryId,
58
- objectId: objectId,
59
- versionHash: versionHash
60
- });
61
-
62
- if (versionHash) {
63
- objectId = this.utils.DecodeVersionHash(versionHash).objectId;
64
- }
65
-
66
- path = UrlJoin("q", versionHash || objectId, "meta", "files");
67
- _context.t0 = this.utils;
68
- _context.t1 = this.HttpClient;
69
- _context.next = 8;
70
- return this.authClient.AuthorizationHeader({
71
- libraryId: libraryId,
72
- objectId: objectId,
73
- versionHash: versionHash
74
- });
75
-
76
- case 8:
77
- _context.t2 = _context.sent;
78
- _context.t3 = path;
79
- _context.t4 = {
80
- headers: _context.t2,
81
- method: "GET",
82
- path: _context.t3
83
- };
84
- _context.t5 = _context.t1.Request.call(_context.t1, _context.t4);
85
- return _context.abrupt("return", _context.t0.ResponseToJson.call(_context.t0, _context.t5));
46
+ exports.ListFiles = function _callee(_ref) {
47
+ var libraryId, objectId, versionHash, path;
48
+ return _regeneratorRuntime.async(function _callee$(_context) {
49
+ while (1) {
50
+ switch (_context.prev = _context.next) {
51
+ case 0:
52
+ libraryId = _ref.libraryId, objectId = _ref.objectId, versionHash = _ref.versionHash;
53
+ ValidateParameters({
54
+ libraryId: libraryId,
55
+ objectId: objectId,
56
+ versionHash: versionHash
57
+ });
58
+
59
+ if (versionHash) {
60
+ objectId = this.utils.DecodeVersionHash(versionHash).objectId;
61
+ }
86
62
 
87
- case 13:
88
- case "end":
89
- return _context.stop();
90
- }
63
+ path = UrlJoin("q", versionHash || objectId, "meta", "files");
64
+ _context.t0 = this.utils;
65
+ _context.t1 = this.HttpClient;
66
+ _context.next = 8;
67
+ return _regeneratorRuntime.awrap(this.authClient.AuthorizationHeader({
68
+ libraryId: libraryId,
69
+ objectId: objectId,
70
+ versionHash: versionHash
71
+ }));
72
+
73
+ case 8:
74
+ _context.t2 = _context.sent;
75
+ _context.t3 = path;
76
+ _context.t4 = {
77
+ headers: _context.t2,
78
+ method: "GET",
79
+ path: _context.t3
80
+ };
81
+ _context.t5 = _context.t1.Request.call(_context.t1, _context.t4);
82
+ return _context.abrupt("return", _context.t0.ResponseToJson.call(_context.t0, _context.t5));
83
+
84
+ case 13:
85
+ case "end":
86
+ return _context.stop();
91
87
  }
92
- }, _callee, this);
93
- }));
94
-
95
- return function (_x) {
96
- return _ref2.apply(this, arguments);
97
- };
98
- }();
88
+ }
89
+ }, null, this);
90
+ };
99
91
  /**
100
92
  * Copy/reference files from S3 to a content object.
101
93
  *
@@ -132,241 +124,235 @@ exports.ListFiles = /*#__PURE__*/function () {
132
124
  */
133
125
 
134
126
 
135
- exports.UploadFilesFromS3 = /*#__PURE__*/function () {
136
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
137
- var libraryId, objectId, writeToken, region, bucket, fileInfo, accessKey, secret, signedUrl, _ref3$encryption, encryption, _ref3$copy, copy, callback, s3prefixRegex, i, fileSourcePath, s3prefixMatch, bucketName, encryption_key, conk, cloudCredentials, defaults, ops, _yield$this$CreateFil, id, status, done, progress, _progress;
138
-
139
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
140
- while (1) {
141
- switch (_context2.prev = _context2.next) {
142
- case 0:
143
- libraryId = _ref3.libraryId, objectId = _ref3.objectId, writeToken = _ref3.writeToken, region = _ref3.region, bucket = _ref3.bucket, fileInfo = _ref3.fileInfo, accessKey = _ref3.accessKey, secret = _ref3.secret, signedUrl = _ref3.signedUrl, _ref3$encryption = _ref3.encryption, encryption = _ref3$encryption === void 0 ? "none" : _ref3$encryption, _ref3$copy = _ref3.copy, copy = _ref3$copy === void 0 ? false : _ref3$copy, callback = _ref3.callback;
144
- ValidateParameters({
145
- libraryId: libraryId,
146
- objectId: objectId
147
- });
148
- ValidateWriteToken(writeToken);
149
- s3prefixRegex = /^s3:\/\/([^/]+)\//i; // for matching and extracting bucket name when full s3:// path is specified
150
- // if fileInfo source paths start with s3://bucketName/, check against bucket arg passed in, and strip
151
-
152
- i = 0;
153
-
154
- case 5:
155
- if (!(i < fileInfo.length)) {
156
- _context2.next = 18;
157
- break;
158
- }
127
+ exports.UploadFilesFromS3 = function _callee2(_ref2) {
128
+ var libraryId, objectId, writeToken, region, bucket, fileInfo, accessKey, secret, signedUrl, _ref2$encryption, encryption, _ref2$copy, copy, callback, s3prefixRegex, i, fileSourcePath, s3prefixMatch, bucketName, encryption_key, conk, cloudCredentials, defaults, ops, _ref3, id, status, done, progress, _progress;
159
129
 
160
- fileSourcePath = fileInfo[i].source;
161
- s3prefixMatch = s3prefixRegex.exec(fileSourcePath);
130
+ return _regeneratorRuntime.async(function _callee2$(_context2) {
131
+ while (1) {
132
+ switch (_context2.prev = _context2.next) {
133
+ case 0:
134
+ libraryId = _ref2.libraryId, objectId = _ref2.objectId, writeToken = _ref2.writeToken, region = _ref2.region, bucket = _ref2.bucket, fileInfo = _ref2.fileInfo, accessKey = _ref2.accessKey, secret = _ref2.secret, signedUrl = _ref2.signedUrl, _ref2$encryption = _ref2.encryption, encryption = _ref2$encryption === void 0 ? "none" : _ref2$encryption, _ref2$copy = _ref2.copy, copy = _ref2$copy === void 0 ? false : _ref2$copy, callback = _ref2.callback;
135
+ ValidateParameters({
136
+ libraryId: libraryId,
137
+ objectId: objectId
138
+ });
139
+ ValidateWriteToken(writeToken);
140
+ s3prefixRegex = /^s3:\/\/([^/]+)\//i; // for matching and extracting bucket name when full s3:// path is specified
141
+ // if fileInfo source paths start with s3://bucketName/, check against bucket arg passed in, and strip
162
142
 
163
- if (!s3prefixMatch) {
164
- _context2.next = 15;
165
- break;
166
- }
143
+ i = 0;
167
144
 
168
- bucketName = s3prefixMatch[1];
145
+ case 5:
146
+ if (!(i < fileInfo.length)) {
147
+ _context2.next = 18;
148
+ break;
149
+ }
169
150
 
170
- if (!(bucketName !== bucket)) {
171
- _context2.next = 14;
172
- break;
173
- }
151
+ fileSourcePath = fileInfo[i].source;
152
+ s3prefixMatch = s3prefixRegex.exec(fileSourcePath);
174
153
 
175
- throw Error("Full S3 file path \"" + fileSourcePath + "\" specified, but does not match provided bucket name '" + bucket + "'");
154
+ if (!s3prefixMatch) {
155
+ _context2.next = 15;
156
+ break;
157
+ }
176
158
 
177
- case 14:
178
- // strip prefix
179
- fileInfo[i].source = fileSourcePath.replace(s3prefixRegex, "");
159
+ bucketName = s3prefixMatch[1];
180
160
 
181
- case 15:
182
- i++;
183
- _context2.next = 5;
161
+ if (!(bucketName !== bucket)) {
162
+ _context2.next = 14;
184
163
  break;
164
+ }
185
165
 
186
- case 18:
187
- this.Log("Uploading files from S3: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
166
+ throw Error("Full S3 file path \"" + fileSourcePath + "\" specified, but does not match provided bucket name '" + bucket + "'");
188
167
 
189
- if (!(encryption === "cgck")) {
190
- _context2.next = 25;
191
- break;
192
- }
168
+ case 14:
169
+ // strip prefix
170
+ fileInfo[i].source = fileSourcePath.replace(s3prefixRegex, "");
193
171
 
194
- _context2.next = 22;
195
- return this.EncryptionConk({
196
- libraryId: libraryId,
197
- objectId: objectId,
198
- writeToken: writeToken
199
- });
172
+ case 15:
173
+ i++;
174
+ _context2.next = 5;
175
+ break;
200
176
 
201
- case 22:
202
- conk = _context2.sent;
203
- conk = _objectSpread(_objectSpread({}, conk), {}, {
204
- secret_key: ""
205
- });
206
- encryption_key = "kp__".concat(this.utils.B58(Buffer.from(JSON.stringify(conk))));
177
+ case 18:
178
+ this.Log("Uploading files from S3: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
179
+
180
+ if (!(encryption === "cgck")) {
181
+ _context2.next = 25;
182
+ break;
183
+ }
207
184
 
208
- case 25:
185
+ _context2.next = 22;
186
+ return _regeneratorRuntime.awrap(this.EncryptionConk({
187
+ libraryId: libraryId,
188
+ objectId: objectId,
189
+ writeToken: writeToken
190
+ }));
191
+
192
+ case 22:
193
+ conk = _context2.sent;
194
+ conk = _objectSpread({}, conk, {
195
+ secret_key: ""
196
+ });
197
+ encryption_key = "kp__".concat(this.utils.B58(Buffer.from(JSON.stringify(conk))));
198
+
199
+ case 25:
200
+ cloudCredentials = {
201
+ access_key_id: accessKey,
202
+ secret_access_key: secret
203
+ };
204
+
205
+ if (signedUrl) {
209
206
  cloudCredentials = {
210
- access_key_id: accessKey,
211
- secret_access_key: secret
207
+ signed_url: signedUrl
212
208
  };
209
+ }
213
210
 
214
- if (signedUrl) {
215
- cloudCredentials = {
216
- signed_url: signedUrl
217
- };
211
+ defaults = {
212
+ encryption_key: encryption_key,
213
+ access: {
214
+ protocol: "s3",
215
+ platform: "aws",
216
+ path: bucket,
217
+ storage_endpoint: {
218
+ region: region
219
+ },
220
+ cloud_credentials: cloudCredentials
218
221
  }
219
-
220
- defaults = {
221
- encryption_key: encryption_key,
222
- access: {
223
- protocol: "s3",
224
- platform: "aws",
225
- path: bucket,
226
- storage_endpoint: {
227
- region: region
222
+ };
223
+ ops = fileInfo.map(function (info) {
224
+ if (copy) {
225
+ return {
226
+ op: "ingest-copy",
227
+ path: info.path,
228
+ encryption: {
229
+ scheme: encryption === "cgck" ? "cgck" : "none"
228
230
  },
229
- cloud_credentials: cloudCredentials
230
- }
231
- };
232
- ops = fileInfo.map(function (info) {
233
- if (copy) {
234
- return {
235
- op: "ingest-copy",
236
- path: info.path,
237
- encryption: {
238
- scheme: encryption === "cgck" ? "cgck" : "none"
239
- },
240
- ingest: {
241
- type: "key",
242
- path: info.source
243
- }
244
- };
245
- } else {
246
- return {
247
- op: "add-reference",
248
- path: info.path,
249
- reference: {
250
- type: "key",
251
- path: info.source
252
- }
253
- };
254
- }
255
- }); // eslint-disable-next-line no-unused-vars
256
-
257
- _context2.next = 31;
258
- return this.CreateFileUploadJob({
259
- libraryId: libraryId,
260
- objectId: objectId,
261
- writeToken: writeToken,
262
- ops: ops,
263
- defaults: defaults
264
- });
265
-
266
- case 31:
267
- _yield$this$CreateFil = _context2.sent;
268
- id = _yield$this$CreateFil.id;
269
-
270
- case 33:
271
- if (!true) {
272
- _context2.next = 56;
273
- break;
231
+ ingest: {
232
+ type: "key",
233
+ path: info.source
234
+ }
235
+ };
236
+ } else {
237
+ return {
238
+ op: "add-reference",
239
+ path: info.path,
240
+ reference: {
241
+ type: "key",
242
+ path: info.source
243
+ }
244
+ };
274
245
  }
246
+ }); // eslint-disable-next-line no-unused-vars
247
+
248
+ _context2.next = 31;
249
+ return _regeneratorRuntime.awrap(this.CreateFileUploadJob({
250
+ libraryId: libraryId,
251
+ objectId: objectId,
252
+ writeToken: writeToken,
253
+ ops: ops,
254
+ defaults: defaults
255
+ }));
256
+
257
+ case 31:
258
+ _ref3 = _context2.sent;
259
+ id = _ref3.id;
260
+
261
+ case 33:
262
+ if (!true) {
263
+ _context2.next = 56;
264
+ break;
265
+ }
275
266
 
276
- _context2.next = 36;
277
- return new Promise(function (resolve) {
278
- return setTimeout(resolve, 1000);
279
- });
280
-
281
- case 36:
282
- _context2.next = 38;
283
- return this.UploadStatus({
284
- libraryId: libraryId,
285
- objectId: objectId,
286
- writeToken: writeToken,
287
- uploadId: id
288
- });
267
+ _context2.next = 36;
268
+ return _regeneratorRuntime.awrap(new Promise(function (resolve) {
269
+ return setTimeout(resolve, 1000);
270
+ }));
271
+
272
+ case 36:
273
+ _context2.next = 38;
274
+ return _regeneratorRuntime.awrap(this.UploadStatus({
275
+ libraryId: libraryId,
276
+ objectId: objectId,
277
+ writeToken: writeToken,
278
+ uploadId: id
279
+ }));
280
+
281
+ case 38:
282
+ status = _context2.sent;
283
+
284
+ if (!(status.errors && status.errors.length > 1)) {
285
+ _context2.next = 43;
286
+ break;
287
+ }
289
288
 
290
- case 38:
291
- status = _context2.sent;
289
+ throw status.errors.join("\n");
292
290
 
293
- if (!(status.errors && status.errors.length > 1)) {
294
- _context2.next = 43;
295
- break;
296
- }
291
+ case 43:
292
+ if (!status.error) {
293
+ _context2.next = 48;
294
+ break;
295
+ }
297
296
 
298
- throw status.errors.join("\n");
297
+ this.Log("S3 file upload failed:\n".concat(JSON.stringify(status, null, 2)));
298
+ throw status.error;
299
299
 
300
- case 43:
301
- if (!status.error) {
302
- _context2.next = 48;
303
- break;
304
- }
300
+ case 48:
301
+ if (!(status.status.toLowerCase() === "failed")) {
302
+ _context2.next = 50;
303
+ break;
304
+ }
305
305
 
306
- this.Log("S3 file upload failed:\n".concat(JSON.stringify(status, null, 2)));
307
- throw status.error;
306
+ throw "File upload failed";
308
307
 
309
- case 48:
310
- if (!(status.status.toLowerCase() === "failed")) {
311
- _context2.next = 50;
312
- break;
313
- }
308
+ case 50:
309
+ done = false;
314
310
 
315
- throw "File upload failed";
311
+ if (copy) {
312
+ done = status.ingest_copy.done;
316
313
 
317
- case 50:
318
- done = false;
319
-
320
- if (copy) {
321
- done = status.ingest_copy.done;
322
-
323
- if (callback) {
324
- progress = status.ingest_copy.progress;
325
- callback({
326
- done: done,
327
- uploaded: progress.bytes.completed,
328
- total: progress.bytes.total,
329
- uploadedFiles: progress.files.completed,
330
- totalFiles: progress.files.total,
331
- fileStatus: progress.files.details
332
- });
333
- }
334
- } else {
335
- done = status.add_reference.done;
336
-
337
- if (callback) {
338
- _progress = status.add_reference.progress;
339
- callback({
340
- done: done,
341
- uploadedFiles: _progress.completed,
342
- totalFiles: _progress.total
343
- });
344
- }
314
+ if (callback) {
315
+ progress = status.ingest_copy.progress;
316
+ callback({
317
+ done: done,
318
+ uploaded: progress.bytes.completed,
319
+ total: progress.bytes.total,
320
+ uploadedFiles: progress.files.completed,
321
+ totalFiles: progress.files.total,
322
+ fileStatus: progress.files.details
323
+ });
345
324
  }
325
+ } else {
326
+ done = status.add_reference.done;
346
327
 
347
- if (!done) {
348
- _context2.next = 54;
349
- break;
328
+ if (callback) {
329
+ _progress = status.add_reference.progress;
330
+ callback({
331
+ done: done,
332
+ uploadedFiles: _progress.completed,
333
+ totalFiles: _progress.total
334
+ });
350
335
  }
336
+ }
351
337
 
352
- return _context2.abrupt("break", 56);
353
-
354
- case 54:
355
- _context2.next = 33;
338
+ if (!done) {
339
+ _context2.next = 54;
356
340
  break;
341
+ }
357
342
 
358
- case 56:
359
- case "end":
360
- return _context2.stop();
361
- }
362
- }
363
- }, _callee2, this);
364
- }));
343
+ return _context2.abrupt("break", 56);
344
+
345
+ case 54:
346
+ _context2.next = 33;
347
+ break;
365
348
 
366
- return function (_x2) {
367
- return _ref4.apply(this, arguments);
368
- };
369
- }();
349
+ case 56:
350
+ case "end":
351
+ return _context2.stop();
352
+ }
353
+ }
354
+ }, null, this);
355
+ };
370
356
  /**
371
357
  * Upload files to a content object.
372
358
  *
@@ -395,627 +381,577 @@ exports.UploadFilesFromS3 = /*#__PURE__*/function () {
395
381
  */
396
382
 
397
383
 
398
- exports.UploadFiles = /*#__PURE__*/function () {
399
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref5) {
400
- var _this = this;
384
+ exports.UploadFiles = function _callee4(_ref4) {
385
+ var _this = this;
401
386
 
402
- var libraryId, objectId, writeToken, fileInfo, _ref5$encryption, encryption, callback, conk, progress, fileDataMap, i, entry, _yield$this$CreateFil2, id, jobs, bufferSize, jobSpecs, prepared, uploaded, PrepareJobs, UploadJob, rateTestJobs, rates, j, start, elapsed, size, averageRate, concurrentUploads;
387
+ var libraryId, objectId, writeToken, fileInfo, _ref4$encryption, encryption, callback, conk, progress, fileDataMap, i, entry, _ref5, id, jobs, bufferSize, jobSpecs, prepared, uploaded, PrepareJobs, UploadJob, rateTestJobs, rates, j, start, elapsed, size, averageRate, concurrentUploads;
403
388
 
404
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
405
- while (1) {
406
- switch (_context6.prev = _context6.next) {
407
- case 0:
408
- libraryId = _ref5.libraryId, objectId = _ref5.objectId, writeToken = _ref5.writeToken, fileInfo = _ref5.fileInfo, _ref5$encryption = _ref5.encryption, encryption = _ref5$encryption === void 0 ? "none" : _ref5$encryption, callback = _ref5.callback;
409
- ValidateParameters({
410
- libraryId: libraryId,
411
- objectId: objectId
412
- });
413
- ValidateWriteToken(writeToken);
414
- this.Log("Uploading files: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
389
+ return _regeneratorRuntime.async(function _callee4$(_context6) {
390
+ while (1) {
391
+ switch (_context6.prev = _context6.next) {
392
+ case 0:
393
+ libraryId = _ref4.libraryId, objectId = _ref4.objectId, writeToken = _ref4.writeToken, fileInfo = _ref4.fileInfo, _ref4$encryption = _ref4.encryption, encryption = _ref4$encryption === void 0 ? "none" : _ref4$encryption, callback = _ref4.callback;
394
+ ValidateParameters({
395
+ libraryId: libraryId,
396
+ objectId: objectId
397
+ });
398
+ ValidateWriteToken(writeToken);
399
+ this.Log("Uploading files: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
415
400
 
416
- if (!(encryption === "cgck")) {
417
- _context6.next = 8;
418
- break;
419
- }
420
-
421
- _context6.next = 7;
422
- return this.EncryptionConk({
423
- libraryId: libraryId,
424
- objectId: objectId,
425
- writeToken: writeToken
426
- });
401
+ if (!(encryption === "cgck")) {
402
+ _context6.next = 8;
403
+ break;
404
+ }
427
405
 
428
- case 7:
429
- conk = _context6.sent;
406
+ _context6.next = 7;
407
+ return _regeneratorRuntime.awrap(this.EncryptionConk({
408
+ libraryId: libraryId,
409
+ objectId: objectId,
410
+ writeToken: writeToken
411
+ }));
430
412
 
431
- case 8:
432
- // Extract file data into easily accessible hash while removing the data from the fileinfo for upload job creation
433
- progress = {};
434
- fileDataMap = {};
413
+ case 7:
414
+ conk = _context6.sent;
435
415
 
436
- for (i = 0; i < fileInfo.length; i++) {
437
- entry = _objectSpread(_objectSpread({}, fileInfo[i]), {}, {
438
- data: undefined
439
- });
440
- entry.path = entry.path.replace(/^\/+/, "");
416
+ case 8:
417
+ // Extract file data into easily accessible hash while removing the data from the fileinfo for upload job creation
418
+ progress = {};
419
+ fileDataMap = {};
441
420
 
442
- if (encryption === "cgck") {
443
- entry.encryption = {
444
- scheme: "cgck"
445
- };
446
- }
421
+ for (i = 0; i < fileInfo.length; i++) {
422
+ entry = _objectSpread({}, fileInfo[i], {
423
+ data: undefined
424
+ });
425
+ entry.path = entry.path.replace(/^\/+/, "");
447
426
 
448
- fileDataMap[entry.path] = fileInfo[i].data;
449
- delete entry.data;
450
- entry.type = "file";
451
- progress[entry.path] = {
452
- uploaded: 0,
453
- total: entry.size
427
+ if (encryption === "cgck") {
428
+ entry.encryption = {
429
+ scheme: "cgck"
454
430
  };
455
- fileInfo[i] = entry;
456
431
  }
457
432
 
458
- this.Log(fileInfo);
433
+ fileDataMap[entry.path] = fileInfo[i].data;
434
+ delete entry.data;
435
+ entry.type = "file";
436
+ progress[entry.path] = {
437
+ uploaded: 0,
438
+ total: entry.size
439
+ };
440
+ fileInfo[i] = entry;
441
+ }
459
442
 
460
- if (callback) {
461
- callback(progress);
462
- }
443
+ this.Log(fileInfo);
463
444
 
464
- _context6.next = 15;
465
- return this.CreateFileUploadJob({
466
- libraryId: libraryId,
467
- objectId: objectId,
468
- writeToken: writeToken,
469
- ops: fileInfo,
470
- encryption: encryption
471
- });
445
+ if (callback) {
446
+ callback(progress);
447
+ }
472
448
 
473
- case 15:
474
- _yield$this$CreateFil2 = _context6.sent;
475
- id = _yield$this$CreateFil2.id;
476
- jobs = _yield$this$CreateFil2.jobs;
477
- this.Log("Upload ID: ".concat(id));
478
- this.Log(jobs); // How far encryption can get ahead of upload
479
-
480
- bufferSize = 100 * 1024 * 1024;
481
- jobSpecs = [];
482
- prepared = 0;
483
- uploaded = 0; // Insert the data to upload into the job spec, encrypting if necessary
484
-
485
- PrepareJobs = /*#__PURE__*/function () {
486
- var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
487
- var j, jobId, job, f, _fileInfo, data;
488
-
489
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
490
- while (1) {
491
- switch (_context3.prev = _context3.next) {
492
- case 0:
493
- j = 0;
494
-
495
- case 1:
496
- if (!(j < jobs.length)) {
497
- _context3.next = 31;
498
- break;
499
- }
500
-
501
- case 2:
502
- if (!(prepared - uploaded > bufferSize)) {
503
- _context3.next = 7;
504
- break;
505
- }
506
-
507
- _context3.next = 5;
508
- return new Promise(function (resolve) {
509
- return setTimeout(resolve, 500);
510
- });
511
-
512
- case 5:
513
- _context3.next = 2;
514
- break;
515
-
516
- case 7:
517
- // Retrieve job info
518
- jobId = jobs[j];
519
- _context3.next = 10;
520
- return _this.UploadJobStatus({
521
- libraryId: libraryId,
522
- objectId: objectId,
523
- writeToken: writeToken,
524
- uploadId: id,
525
- jobId: jobId
526
- });
527
-
528
- case 10:
529
- job = _context3.sent;
530
- f = 0;
531
-
532
- case 12:
533
- if (!(f < job.files.length)) {
534
- _context3.next = 25;
535
- break;
536
- }
537
-
538
- _fileInfo = job.files[f];
539
- data = void 0;
540
-
541
- if (typeof fileDataMap[_fileInfo.path] === "number") {
542
- // File descriptor - Read data from file
543
- data = Buffer.alloc(_fileInfo.len);
544
- fs.readSync(fileDataMap[_fileInfo.path], data, 0, _fileInfo.len, _fileInfo.off);
545
- } else {
546
- // Full data - Slice requested chunk
547
- data = fileDataMap[_fileInfo.path].slice(_fileInfo.off, _fileInfo.off + _fileInfo.len);
548
- }
549
-
550
- if (!(encryption === "cgck")) {
551
- _context3.next = 20;
552
- break;
553
- }
554
-
555
- _context3.next = 19;
556
- return _this.Crypto.Encrypt(conk, data);
557
-
558
- case 19:
559
- data = _context3.sent;
560
-
561
- case 20:
562
- job.files[f].data = data;
563
- prepared += _fileInfo.len;
564
-
565
- case 22:
566
- f++;
567
- _context3.next = 12;
568
- break;
569
-
570
- case 25:
571
- jobSpecs[j] = job; // Wait for a bit to let upload start
572
-
573
- _context3.next = 28;
574
- return new Promise(function (resolve) {
575
- return setTimeout(resolve, 50);
576
- });
577
-
578
- case 28:
579
- j++;
580
- _context3.next = 1;
581
- break;
582
-
583
- case 31:
584
- case "end":
585
- return _context3.stop();
449
+ _context6.next = 15;
450
+ return _regeneratorRuntime.awrap(this.CreateFileUploadJob({
451
+ libraryId: libraryId,
452
+ objectId: objectId,
453
+ writeToken: writeToken,
454
+ ops: fileInfo,
455
+ encryption: encryption
456
+ }));
457
+
458
+ case 15:
459
+ _ref5 = _context6.sent;
460
+ id = _ref5.id;
461
+ jobs = _ref5.jobs;
462
+ this.Log("Upload ID: ".concat(id));
463
+ this.Log(jobs); // How far encryption can get ahead of upload
464
+
465
+ bufferSize = 100 * 1024 * 1024;
466
+ jobSpecs = [];
467
+ prepared = 0;
468
+ uploaded = 0; // Insert the data to upload into the job spec, encrypting if necessary
469
+
470
+ PrepareJobs = function PrepareJobs() {
471
+ var j, jobId, job, f, _fileInfo, data;
472
+
473
+ return _regeneratorRuntime.async(function PrepareJobs$(_context3) {
474
+ while (1) {
475
+ switch (_context3.prev = _context3.next) {
476
+ case 0:
477
+ j = 0;
478
+
479
+ case 1:
480
+ if (!(j < jobs.length)) {
481
+ _context3.next = 31;
482
+ break;
586
483
  }
587
- }
588
- }, _callee3);
589
- }));
590
484
 
591
- return function PrepareJobs() {
592
- return _ref7.apply(this, arguments);
593
- };
594
- }();
595
-
596
- UploadJob = /*#__PURE__*/function () {
597
- var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(jobId, j) {
598
- var jobSpec, files, f, _fileInfo2;
599
-
600
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
601
- while (1) {
602
- switch (_context4.prev = _context4.next) {
603
- case 0:
604
- if (jobSpecs[j]) {
605
- _context4.next = 5;
606
- break;
607
- }
608
-
609
- _context4.next = 3;
610
- return new Promise(function (resolve) {
611
- return setTimeout(resolve, 500);
612
- });
613
-
614
- case 3:
615
- _context4.next = 0;
616
- break;
617
-
618
- case 5:
619
- jobSpec = jobSpecs[j];
620
- files = jobSpec.files; // Upload each item
621
-
622
- f = 0;
623
-
624
- case 8:
625
- if (!(f < files.length)) {
626
- _context4.next = 18;
627
- break;
628
- }
629
-
630
- _fileInfo2 = files[f];
631
- _context4.next = 12;
632
- return _this.UploadFileData({
633
- libraryId: libraryId,
634
- objectId: objectId,
635
- writeToken: writeToken,
636
- uploadId: id,
637
- jobId: jobId,
638
- fileData: _fileInfo2.data
639
- });
640
-
641
- case 12:
642
- delete jobSpecs[j].files[f].data;
643
- uploaded += _fileInfo2.len;
644
-
645
- if (callback) {
646
- progress[_fileInfo2.path] = _objectSpread(_objectSpread({}, progress[_fileInfo2.path]), {}, {
647
- uploaded: progress[_fileInfo2.path].uploaded + _fileInfo2.len
648
- });
649
- callback(progress);
650
- }
651
-
652
- case 15:
653
- f++;
654
- _context4.next = 8;
655
- break;
656
-
657
- case 18:
658
- case "end":
659
- return _context4.stop();
485
+ case 2:
486
+ if (!(prepared - uploaded > bufferSize)) {
487
+ _context3.next = 7;
488
+ break;
660
489
  }
661
- }
662
- }, _callee4);
663
- }));
664
490
 
665
- return function UploadJob(_x4, _x5) {
666
- return _ref8.apply(this, arguments);
667
- };
668
- }(); // Preparing jobs is done asyncronously
491
+ _context3.next = 5;
492
+ return _regeneratorRuntime.awrap(new Promise(function (resolve) {
493
+ return setTimeout(resolve, 500);
494
+ }));
495
+
496
+ case 5:
497
+ _context3.next = 2;
498
+ break;
499
+
500
+ case 7:
501
+ // Retrieve job info
502
+ jobId = jobs[j];
503
+ _context3.next = 10;
504
+ return _regeneratorRuntime.awrap(_this.UploadJobStatus({
505
+ libraryId: libraryId,
506
+ objectId: objectId,
507
+ writeToken: writeToken,
508
+ uploadId: id,
509
+ jobId: jobId
510
+ }));
511
+
512
+ case 10:
513
+ job = _context3.sent;
514
+ f = 0;
515
+
516
+ case 12:
517
+ if (!(f < job.files.length)) {
518
+ _context3.next = 25;
519
+ break;
520
+ }
669
521
 
522
+ _fileInfo = job.files[f];
523
+ data = void 0;
670
524
 
671
- PrepareJobs(); // Upload the first several chunks in sequence, to determine average upload rate
525
+ if (typeof fileDataMap[_fileInfo.path] === "number") {
526
+ // File descriptor - Read data from file
527
+ data = Buffer.alloc(_fileInfo.len);
528
+ fs.readSync(fileDataMap[_fileInfo.path], data, 0, _fileInfo.len, _fileInfo.off);
529
+ } else {
530
+ // Full data - Slice requested chunk
531
+ data = fileDataMap[_fileInfo.path].slice(_fileInfo.off, _fileInfo.off + _fileInfo.len);
532
+ }
672
533
 
673
- rateTestJobs = Math.min(3, jobs.length);
674
- rates = [];
675
- j = 0;
534
+ if (!(encryption === "cgck")) {
535
+ _context3.next = 20;
536
+ break;
537
+ }
676
538
 
677
- case 30:
678
- if (!(j < rateTestJobs)) {
679
- _context6.next = 40;
680
- break;
681
- }
539
+ _context3.next = 19;
540
+ return _regeneratorRuntime.awrap(_this.Crypto.Encrypt(conk, data));
682
541
 
683
- start = new Date().getTime();
684
- _context6.next = 34;
685
- return UploadJob(jobs[j], j);
686
-
687
- case 34:
688
- elapsed = (new Date().getTime() - start) / 1000;
689
- size = jobSpecs[j].files.map(function (file) {
690
- return file.len;
691
- }).reduce(function (length, total) {
692
- return length + total;
693
- }, 0);
694
- rates.push(size / elapsed / (1024 * 1024));
695
-
696
- case 37:
697
- j++;
698
- _context6.next = 30;
699
- break;
542
+ case 19:
543
+ data = _context3.sent;
700
544
 
701
- case 40:
702
- averageRate = rates.reduce(function (mbps, total) {
703
- return mbps + total;
704
- }, 0) / rateTestJobs; // Upload remaining jobs in parallel
705
-
706
- concurrentUploads = Math.min(5, Math.ceil(averageRate / 2));
707
- _context6.next = 44;
708
- return this.utils.LimitedMap(concurrentUploads, jobs, /*#__PURE__*/function () {
709
- var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(jobId, j) {
710
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
711
- while (1) {
712
- switch (_context5.prev = _context5.next) {
713
- case 0:
714
- if (!(j < rateTestJobs)) {
715
- _context5.next = 2;
716
- break;
717
- }
718
-
719
- return _context5.abrupt("return");
720
-
721
- case 2:
722
- _context5.next = 4;
723
- return UploadJob(jobId, j);
724
-
725
- case 4:
726
- case "end":
727
- return _context5.stop();
728
- }
729
- }
730
- }, _callee5);
731
- }));
545
+ case 20:
546
+ job.files[f].data = data;
547
+ prepared += _fileInfo.len;
732
548
 
733
- return function (_x6, _x7) {
734
- return _ref9.apply(this, arguments);
735
- };
736
- }());
549
+ case 22:
550
+ f++;
551
+ _context3.next = 12;
552
+ break;
737
553
 
738
- case 44:
739
- case "end":
740
- return _context6.stop();
741
- }
742
- }
743
- }, _callee6, this);
744
- }));
745
-
746
- return function (_x3) {
747
- return _ref6.apply(this, arguments);
748
- };
749
- }();
750
-
751
- exports.CreateFileUploadJob = /*#__PURE__*/function () {
752
- var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref10) {
753
- var libraryId, objectId, writeToken, ops, _ref10$defaults, defaults, _ref10$encryption, encryption, body, path;
754
-
755
- return _regeneratorRuntime.wrap(function _callee7$(_context7) {
756
- while (1) {
757
- switch (_context7.prev = _context7.next) {
758
- case 0:
759
- libraryId = _ref10.libraryId, objectId = _ref10.objectId, writeToken = _ref10.writeToken, ops = _ref10.ops, _ref10$defaults = _ref10.defaults, defaults = _ref10$defaults === void 0 ? {} : _ref10$defaults, _ref10$encryption = _ref10.encryption, encryption = _ref10$encryption === void 0 ? "none" : _ref10$encryption;
760
- ValidateParameters({
761
- libraryId: libraryId,
762
- objectId: objectId
763
- });
764
- ValidateWriteToken(writeToken);
765
- this.Log("Creating file upload job: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
766
- this.Log(ops);
554
+ case 25:
555
+ jobSpecs[j] = job; // Wait for a bit to let upload start
767
556
 
768
- if (encryption === "cgck") {
769
- defaults.encryption = {
770
- scheme: "cgck"
771
- };
772
- }
557
+ _context3.next = 28;
558
+ return _regeneratorRuntime.awrap(new Promise(function (resolve) {
559
+ return setTimeout(resolve, 50);
560
+ }));
773
561
 
774
- body = {
775
- seq: 0,
776
- seq_complete: true,
777
- defaults: defaults,
778
- ops: ops
779
- };
780
- path = UrlJoin("q", writeToken, "file_jobs");
781
- _context7.t0 = this.utils;
782
- _context7.t1 = this.HttpClient;
783
- _context7.next = 12;
784
- return this.authClient.AuthorizationHeader({
785
- libraryId: libraryId,
786
- objectId: objectId,
787
- update: true,
788
- encryption: encryption
562
+ case 28:
563
+ j++;
564
+ _context3.next = 1;
565
+ break;
566
+
567
+ case 31:
568
+ case "end":
569
+ return _context3.stop();
570
+ }
571
+ }
789
572
  });
573
+ };
574
+
575
+ UploadJob = function UploadJob(jobId, j) {
576
+ var jobSpec, files, f, _fileInfo2;
577
+
578
+ return _regeneratorRuntime.async(function UploadJob$(_context4) {
579
+ while (1) {
580
+ switch (_context4.prev = _context4.next) {
581
+ case 0:
582
+ if (jobSpecs[j]) {
583
+ _context4.next = 5;
584
+ break;
585
+ }
790
586
 
791
- case 12:
792
- _context7.t2 = _context7.sent;
793
- _context7.t3 = path;
794
- _context7.t4 = body;
795
- _context7.t5 = {
796
- headers: _context7.t2,
797
- method: "POST",
798
- path: _context7.t3,
799
- body: _context7.t4,
800
- failover: false
801
- };
802
- _context7.t6 = _context7.t1.Request.call(_context7.t1, _context7.t5);
803
- return _context7.abrupt("return", _context7.t0.ResponseToJson.call(_context7.t0, _context7.t6));
587
+ _context4.next = 3;
588
+ return _regeneratorRuntime.awrap(new Promise(function (resolve) {
589
+ return setTimeout(resolve, 500);
590
+ }));
804
591
 
805
- case 18:
806
- case "end":
807
- return _context7.stop();
808
- }
809
- }
810
- }, _callee7, this);
811
- }));
812
-
813
- return function (_x8) {
814
- return _ref11.apply(this, arguments);
815
- };
816
- }();
817
-
818
- exports.UploadStatus = /*#__PURE__*/function () {
819
- var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref12) {
820
- var libraryId, objectId, writeToken, uploadId, path;
821
- return _regeneratorRuntime.wrap(function _callee8$(_context8) {
822
- while (1) {
823
- switch (_context8.prev = _context8.next) {
824
- case 0:
825
- libraryId = _ref12.libraryId, objectId = _ref12.objectId, writeToken = _ref12.writeToken, uploadId = _ref12.uploadId;
826
- ValidateParameters({
827
- libraryId: libraryId,
828
- objectId: objectId
829
- });
830
- ValidateWriteToken(writeToken);
831
- path = UrlJoin("q", writeToken, "file_jobs", uploadId);
832
- _context8.t0 = this.utils;
833
- _context8.t1 = this.HttpClient;
834
- _context8.next = 8;
835
- return this.authClient.AuthorizationHeader({
836
- libraryId: libraryId,
837
- objectId: objectId,
838
- update: true
839
- });
592
+ case 3:
593
+ _context4.next = 0;
594
+ break;
840
595
 
841
- case 8:
842
- _context8.t2 = _context8.sent;
843
- _context8.t3 = path;
844
- _context8.t4 = {
845
- headers: _context8.t2,
846
- method: "GET",
847
- path: _context8.t3,
848
- failover: false
849
- };
850
- _context8.t5 = _context8.t1.Request.call(_context8.t1, _context8.t4);
851
- return _context8.abrupt("return", _context8.t0.ResponseToJson.call(_context8.t0, _context8.t5));
596
+ case 5:
597
+ jobSpec = jobSpecs[j];
598
+ files = jobSpec.files; // Upload each item
852
599
 
853
- case 13:
854
- case "end":
855
- return _context8.stop();
856
- }
857
- }
858
- }, _callee8, this);
859
- }));
860
-
861
- return function (_x9) {
862
- return _ref13.apply(this, arguments);
863
- };
864
- }();
865
-
866
- exports.UploadJobStatus = /*#__PURE__*/function () {
867
- var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref14) {
868
- var libraryId, objectId, writeToken, uploadId, jobId, path;
869
- return _regeneratorRuntime.wrap(function _callee9$(_context9) {
870
- while (1) {
871
- switch (_context9.prev = _context9.next) {
872
- case 0:
873
- libraryId = _ref14.libraryId, objectId = _ref14.objectId, writeToken = _ref14.writeToken, uploadId = _ref14.uploadId, jobId = _ref14.jobId;
874
- ValidateParameters({
875
- libraryId: libraryId,
876
- objectId: objectId
877
- });
878
- ValidateWriteToken(writeToken);
879
- path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId);
880
- _context9.t0 = this.utils;
881
- _context9.t1 = this.HttpClient;
882
- _context9.next = 8;
883
- return this.authClient.AuthorizationHeader({
884
- libraryId: libraryId,
885
- objectId: objectId,
886
- update: true
887
- });
600
+ f = 0;
888
601
 
889
- case 8:
890
- _context9.t2 = _context9.sent;
891
- _context9.t3 = path;
892
- _context9.t4 = {
893
- headers: _context9.t2,
894
- method: "GET",
895
- path: _context9.t3,
896
- failover: false
897
- };
898
- _context9.t5 = _context9.t1.Request.call(_context9.t1, _context9.t4);
899
- return _context9.abrupt("return", _context9.t0.ResponseToJson.call(_context9.t0, _context9.t5));
602
+ case 8:
603
+ if (!(f < files.length)) {
604
+ _context4.next = 18;
605
+ break;
606
+ }
900
607
 
901
- case 13:
902
- case "end":
903
- return _context9.stop();
904
- }
905
- }
906
- }, _callee9, this);
907
- }));
908
-
909
- return function (_x10) {
910
- return _ref15.apply(this, arguments);
911
- };
912
- }();
913
-
914
- exports.UploadFileData = /*#__PURE__*/function () {
915
- var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref16) {
916
- var libraryId, objectId, writeToken, uploadId, jobId, fileData, path;
917
- return _regeneratorRuntime.wrap(function _callee10$(_context10) {
918
- while (1) {
919
- switch (_context10.prev = _context10.next) {
920
- case 0:
921
- libraryId = _ref16.libraryId, objectId = _ref16.objectId, writeToken = _ref16.writeToken, uploadId = _ref16.uploadId, jobId = _ref16.jobId, fileData = _ref16.fileData;
922
- ValidateParameters({
923
- libraryId: libraryId,
924
- objectId: objectId
925
- });
926
- ValidateWriteToken(writeToken);
927
- path = UrlJoin("q", writeToken, "file_jobs", uploadId, jobId);
928
- _context10.t0 = this.utils;
929
- _context10.t1 = this.HttpClient;
930
- _context10.t2 = path;
931
- _context10.t3 = fileData;
932
- _context10.t4 = _objectSpread;
933
- _context10.t5 = {
934
- "Content-type": "application/octet-stream"
935
- };
936
- _context10.next = 12;
937
- return this.authClient.AuthorizationHeader({
938
- libraryId: libraryId,
939
- objectId: objectId,
940
- update: true
941
- });
608
+ _fileInfo2 = files[f];
609
+ _context4.next = 12;
610
+ return _regeneratorRuntime.awrap(_this.UploadFileData({
611
+ libraryId: libraryId,
612
+ objectId: objectId,
613
+ writeToken: writeToken,
614
+ uploadId: id,
615
+ jobId: jobId,
616
+ fileData: _fileInfo2.data
617
+ }));
618
+
619
+ case 12:
620
+ delete jobSpecs[j].files[f].data;
621
+ uploaded += _fileInfo2.len;
622
+
623
+ if (callback) {
624
+ progress[_fileInfo2.path] = _objectSpread({}, progress[_fileInfo2.path], {
625
+ uploaded: progress[_fileInfo2.path].uploaded + _fileInfo2.len
626
+ });
627
+ callback(progress);
628
+ }
942
629
 
943
- case 12:
944
- _context10.t6 = _context10.sent;
945
- _context10.t7 = (0, _context10.t4)(_context10.t5, _context10.t6);
946
- _context10.t8 = {
947
- method: "POST",
948
- path: _context10.t2,
949
- body: _context10.t3,
950
- bodyType: "BINARY",
951
- headers: _context10.t7,
952
- failover: false
953
- };
954
- _context10.t9 = _context10.t1.Request.call(_context10.t1, _context10.t8);
955
- _context10.next = 18;
956
- return _context10.t0.ResponseToJson.call(_context10.t0, _context10.t9);
957
-
958
- case 18:
959
- case "end":
960
- return _context10.stop();
961
- }
962
- }
963
- }, _callee10, this);
964
- }));
965
-
966
- return function (_x11) {
967
- return _ref17.apply(this, arguments);
968
- };
969
- }();
970
-
971
- exports.FinalizeUploadJob = /*#__PURE__*/function () {
972
- var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(_ref18) {
973
- var libraryId, objectId, writeToken, path;
974
- return _regeneratorRuntime.wrap(function _callee11$(_context11) {
975
- while (1) {
976
- switch (_context11.prev = _context11.next) {
977
- case 0:
978
- libraryId = _ref18.libraryId, objectId = _ref18.objectId, writeToken = _ref18.writeToken;
979
- ValidateParameters({
980
- libraryId: libraryId,
981
- objectId: objectId
630
+ case 15:
631
+ f++;
632
+ _context4.next = 8;
633
+ break;
634
+
635
+ case 18:
636
+ case "end":
637
+ return _context4.stop();
638
+ }
639
+ }
982
640
  });
983
- ValidateWriteToken(writeToken);
984
- this.Log("Finalizing upload job: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
985
- path = UrlJoin("q", writeToken, "files");
986
- _context11.t0 = this.HttpClient;
987
- _context11.t1 = path;
988
- _context11.next = 9;
989
- return this.authClient.AuthorizationHeader({
990
- libraryId: libraryId,
991
- objectId: objectId,
992
- update: true
641
+ }; // Preparing jobs is done asyncronously
642
+
643
+
644
+ PrepareJobs(); // Upload the first several chunks in sequence, to determine average upload rate
645
+
646
+ rateTestJobs = Math.min(3, jobs.length);
647
+ rates = [];
648
+ j = 0;
649
+
650
+ case 30:
651
+ if (!(j < rateTestJobs)) {
652
+ _context6.next = 40;
653
+ break;
654
+ }
655
+
656
+ start = new Date().getTime();
657
+ _context6.next = 34;
658
+ return _regeneratorRuntime.awrap(UploadJob(jobs[j], j));
659
+
660
+ case 34:
661
+ elapsed = (new Date().getTime() - start) / 1000;
662
+ size = jobSpecs[j].files.map(function (file) {
663
+ return file.len;
664
+ }).reduce(function (length, total) {
665
+ return length + total;
666
+ }, 0);
667
+ rates.push(size / elapsed / (1024 * 1024));
668
+
669
+ case 37:
670
+ j++;
671
+ _context6.next = 30;
672
+ break;
673
+
674
+ case 40:
675
+ averageRate = rates.reduce(function (mbps, total) {
676
+ return mbps + total;
677
+ }, 0) / rateTestJobs; // Upload remaining jobs in parallel
678
+
679
+ concurrentUploads = Math.min(5, Math.ceil(averageRate / 2));
680
+ _context6.next = 44;
681
+ return _regeneratorRuntime.awrap(this.utils.LimitedMap(concurrentUploads, jobs, function _callee3(jobId, j) {
682
+ return _regeneratorRuntime.async(function _callee3$(_context5) {
683
+ while (1) {
684
+ switch (_context5.prev = _context5.next) {
685
+ case 0:
686
+ if (!(j < rateTestJobs)) {
687
+ _context5.next = 2;
688
+ break;
689
+ }
690
+
691
+ return _context5.abrupt("return");
692
+
693
+ case 2:
694
+ _context5.next = 4;
695
+ return _regeneratorRuntime.awrap(UploadJob(jobId, j));
696
+
697
+ case 4:
698
+ case "end":
699
+ return _context5.stop();
700
+ }
701
+ }
993
702
  });
703
+ }));
994
704
 
995
- case 9:
996
- _context11.t2 = _context11.sent;
997
- _context11.t3 = {
998
- method: "POST",
999
- path: _context11.t1,
1000
- bodyType: "BINARY",
1001
- headers: _context11.t2,
1002
- failover: false
705
+ case 44:
706
+ case "end":
707
+ return _context6.stop();
708
+ }
709
+ }
710
+ }, null, this);
711
+ };
712
+
713
+ exports.CreateFileUploadJob = function _callee5(_ref6) {
714
+ var libraryId, objectId, writeToken, ops, _ref6$defaults, defaults, _ref6$encryption, encryption, body, path;
715
+
716
+ return _regeneratorRuntime.async(function _callee5$(_context7) {
717
+ while (1) {
718
+ switch (_context7.prev = _context7.next) {
719
+ case 0:
720
+ libraryId = _ref6.libraryId, objectId = _ref6.objectId, writeToken = _ref6.writeToken, ops = _ref6.ops, _ref6$defaults = _ref6.defaults, defaults = _ref6$defaults === void 0 ? {} : _ref6$defaults, _ref6$encryption = _ref6.encryption, encryption = _ref6$encryption === void 0 ? "none" : _ref6$encryption;
721
+ ValidateParameters({
722
+ libraryId: libraryId,
723
+ objectId: objectId
724
+ });
725
+ ValidateWriteToken(writeToken);
726
+ this.Log("Creating file upload job: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
727
+ this.Log(ops);
728
+
729
+ if (encryption === "cgck") {
730
+ defaults.encryption = {
731
+ scheme: "cgck"
1003
732
  };
1004
- _context11.next = 13;
1005
- return _context11.t0.Request.call(_context11.t0, _context11.t3);
733
+ }
1006
734
 
1007
- case 13:
1008
- case "end":
1009
- return _context11.stop();
1010
- }
735
+ body = {
736
+ seq: 0,
737
+ seq_complete: true,
738
+ defaults: defaults,
739
+ ops: ops
740
+ };
741
+ path = UrlJoin("q", writeToken, "file_jobs");
742
+ _context7.t0 = this.utils;
743
+ _context7.t1 = this.HttpClient;
744
+ _context7.next = 12;
745
+ return _regeneratorRuntime.awrap(this.authClient.AuthorizationHeader({
746
+ libraryId: libraryId,
747
+ objectId: objectId,
748
+ update: true,
749
+ encryption: encryption
750
+ }));
751
+
752
+ case 12:
753
+ _context7.t2 = _context7.sent;
754
+ _context7.t3 = path;
755
+ _context7.t4 = body;
756
+ _context7.t5 = {
757
+ headers: _context7.t2,
758
+ method: "POST",
759
+ path: _context7.t3,
760
+ body: _context7.t4,
761
+ failover: false
762
+ };
763
+ _context7.t6 = _context7.t1.Request.call(_context7.t1, _context7.t5);
764
+ return _context7.abrupt("return", _context7.t0.ResponseToJson.call(_context7.t0, _context7.t6));
765
+
766
+ case 18:
767
+ case "end":
768
+ return _context7.stop();
1011
769
  }
1012
- }, _callee11, this);
1013
- }));
1014
-
1015
- return function (_x12) {
1016
- return _ref19.apply(this, arguments);
1017
- };
1018
- }();
770
+ }
771
+ }, null, this);
772
+ };
773
+
774
+ exports.UploadStatus = function _callee6(_ref7) {
775
+ var libraryId, objectId, writeToken, uploadId, path;
776
+ return _regeneratorRuntime.async(function _callee6$(_context8) {
777
+ while (1) {
778
+ switch (_context8.prev = _context8.next) {
779
+ case 0:
780
+ libraryId = _ref7.libraryId, objectId = _ref7.objectId, writeToken = _ref7.writeToken, uploadId = _ref7.uploadId;
781
+ ValidateParameters({
782
+ libraryId: libraryId,
783
+ objectId: objectId
784
+ });
785
+ ValidateWriteToken(writeToken);
786
+ path = UrlJoin("q", writeToken, "file_jobs", uploadId);
787
+ _context8.t0 = this.utils;
788
+ _context8.t1 = this.HttpClient;
789
+ _context8.next = 8;
790
+ return _regeneratorRuntime.awrap(this.authClient.AuthorizationHeader({
791
+ libraryId: libraryId,
792
+ objectId: objectId,
793
+ update: true
794
+ }));
795
+
796
+ case 8:
797
+ _context8.t2 = _context8.sent;
798
+ _context8.t3 = path;
799
+ _context8.t4 = {
800
+ headers: _context8.t2,
801
+ method: "GET",
802
+ path: _context8.t3,
803
+ failover: false
804
+ };
805
+ _context8.t5 = _context8.t1.Request.call(_context8.t1, _context8.t4);
806
+ return _context8.abrupt("return", _context8.t0.ResponseToJson.call(_context8.t0, _context8.t5));
807
+
808
+ case 13:
809
+ case "end":
810
+ return _context8.stop();
811
+ }
812
+ }
813
+ }, null, this);
814
+ };
815
+
816
+ exports.UploadJobStatus = function _callee7(_ref8) {
817
+ var libraryId, objectId, writeToken, uploadId, jobId, path;
818
+ return _regeneratorRuntime.async(function _callee7$(_context9) {
819
+ while (1) {
820
+ switch (_context9.prev = _context9.next) {
821
+ case 0:
822
+ libraryId = _ref8.libraryId, objectId = _ref8.objectId, writeToken = _ref8.writeToken, uploadId = _ref8.uploadId, jobId = _ref8.jobId;
823
+ ValidateParameters({
824
+ libraryId: libraryId,
825
+ objectId: objectId
826
+ });
827
+ ValidateWriteToken(writeToken);
828
+ path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId);
829
+ _context9.t0 = this.utils;
830
+ _context9.t1 = this.HttpClient;
831
+ _context9.next = 8;
832
+ return _regeneratorRuntime.awrap(this.authClient.AuthorizationHeader({
833
+ libraryId: libraryId,
834
+ objectId: objectId,
835
+ update: true
836
+ }));
837
+
838
+ case 8:
839
+ _context9.t2 = _context9.sent;
840
+ _context9.t3 = path;
841
+ _context9.t4 = {
842
+ headers: _context9.t2,
843
+ method: "GET",
844
+ path: _context9.t3,
845
+ failover: false
846
+ };
847
+ _context9.t5 = _context9.t1.Request.call(_context9.t1, _context9.t4);
848
+ return _context9.abrupt("return", _context9.t0.ResponseToJson.call(_context9.t0, _context9.t5));
849
+
850
+ case 13:
851
+ case "end":
852
+ return _context9.stop();
853
+ }
854
+ }
855
+ }, null, this);
856
+ };
857
+
858
+ exports.UploadFileData = function _callee8(_ref9) {
859
+ var libraryId, objectId, writeToken, uploadId, jobId, fileData, path;
860
+ return _regeneratorRuntime.async(function _callee8$(_context10) {
861
+ while (1) {
862
+ switch (_context10.prev = _context10.next) {
863
+ case 0:
864
+ libraryId = _ref9.libraryId, objectId = _ref9.objectId, writeToken = _ref9.writeToken, uploadId = _ref9.uploadId, jobId = _ref9.jobId, fileData = _ref9.fileData;
865
+ ValidateParameters({
866
+ libraryId: libraryId,
867
+ objectId: objectId
868
+ });
869
+ ValidateWriteToken(writeToken);
870
+ path = UrlJoin("q", writeToken, "file_jobs", uploadId, jobId);
871
+ _context10.t0 = _regeneratorRuntime;
872
+ _context10.t1 = this.utils;
873
+ _context10.t2 = this.HttpClient;
874
+ _context10.t3 = path;
875
+ _context10.t4 = fileData;
876
+ _context10.t5 = _objectSpread;
877
+ _context10.t6 = {
878
+ "Content-type": "application/octet-stream"
879
+ };
880
+ _context10.next = 13;
881
+ return _regeneratorRuntime.awrap(this.authClient.AuthorizationHeader({
882
+ libraryId: libraryId,
883
+ objectId: objectId,
884
+ update: true
885
+ }));
886
+
887
+ case 13:
888
+ _context10.t7 = _context10.sent;
889
+ _context10.t8 = (0, _context10.t5)(_context10.t6, _context10.t7);
890
+ _context10.t9 = {
891
+ method: "POST",
892
+ path: _context10.t3,
893
+ body: _context10.t4,
894
+ bodyType: "BINARY",
895
+ headers: _context10.t8,
896
+ failover: false
897
+ };
898
+ _context10.t10 = _context10.t2.Request.call(_context10.t2, _context10.t9);
899
+ _context10.t11 = _context10.t1.ResponseToJson.call(_context10.t1, _context10.t10);
900
+ _context10.next = 20;
901
+ return _context10.t0.awrap.call(_context10.t0, _context10.t11);
902
+
903
+ case 20:
904
+ case "end":
905
+ return _context10.stop();
906
+ }
907
+ }
908
+ }, null, this);
909
+ };
910
+
911
+ exports.FinalizeUploadJob = function _callee9(_ref10) {
912
+ var libraryId, objectId, writeToken, path;
913
+ return _regeneratorRuntime.async(function _callee9$(_context11) {
914
+ while (1) {
915
+ switch (_context11.prev = _context11.next) {
916
+ case 0:
917
+ libraryId = _ref10.libraryId, objectId = _ref10.objectId, writeToken = _ref10.writeToken;
918
+ ValidateParameters({
919
+ libraryId: libraryId,
920
+ objectId: objectId
921
+ });
922
+ ValidateWriteToken(writeToken);
923
+ this.Log("Finalizing upload job: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
924
+ path = UrlJoin("q", writeToken, "files");
925
+ _context11.t0 = _regeneratorRuntime;
926
+ _context11.t1 = this.HttpClient;
927
+ _context11.t2 = path;
928
+ _context11.next = 10;
929
+ return _regeneratorRuntime.awrap(this.authClient.AuthorizationHeader({
930
+ libraryId: libraryId,
931
+ objectId: objectId,
932
+ update: true
933
+ }));
934
+
935
+ case 10:
936
+ _context11.t3 = _context11.sent;
937
+ _context11.t4 = {
938
+ method: "POST",
939
+ path: _context11.t2,
940
+ bodyType: "BINARY",
941
+ headers: _context11.t3,
942
+ failover: false
943
+ };
944
+ _context11.t5 = _context11.t1.Request.call(_context11.t1, _context11.t4);
945
+ _context11.next = 15;
946
+ return _context11.t0.awrap.call(_context11.t0, _context11.t5);
947
+
948
+ case 15:
949
+ case "end":
950
+ return _context11.stop();
951
+ }
952
+ }
953
+ }, null, this);
954
+ };
1019
955
  /**
1020
956
  * Create the specified directories on the specified object
1021
957
  *
@@ -1029,48 +965,42 @@ exports.FinalizeUploadJob = /*#__PURE__*/function () {
1029
965
  */
1030
966
 
1031
967
 
1032
- exports.CreateFileDirectories = /*#__PURE__*/function () {
1033
- var _ref21 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(_ref20) {
1034
- var libraryId, objectId, writeToken, filePaths, ops;
1035
- return _regeneratorRuntime.wrap(function _callee12$(_context12) {
1036
- while (1) {
1037
- switch (_context12.prev = _context12.next) {
1038
- case 0:
1039
- libraryId = _ref20.libraryId, objectId = _ref20.objectId, writeToken = _ref20.writeToken, filePaths = _ref20.filePaths;
1040
- ValidateParameters({
1041
- libraryId: libraryId,
1042
- objectId: objectId
1043
- });
1044
- ValidateWriteToken(writeToken);
1045
- this.Log("Creating Directories: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
1046
- this.Log(filePaths);
1047
- ops = filePaths.map(function (path) {
1048
- return {
1049
- op: "add",
1050
- type: "directory",
1051
- path: path
1052
- };
1053
- });
1054
- _context12.next = 8;
1055
- return this.CreateFileUploadJob({
1056
- libraryId: libraryId,
1057
- objectId: objectId,
1058
- writeToken: writeToken,
1059
- ops: ops
1060
- });
1061
-
1062
- case 8:
1063
- case "end":
1064
- return _context12.stop();
1065
- }
968
+ exports.CreateFileDirectories = function _callee10(_ref11) {
969
+ var libraryId, objectId, writeToken, filePaths, ops;
970
+ return _regeneratorRuntime.async(function _callee10$(_context12) {
971
+ while (1) {
972
+ switch (_context12.prev = _context12.next) {
973
+ case 0:
974
+ libraryId = _ref11.libraryId, objectId = _ref11.objectId, writeToken = _ref11.writeToken, filePaths = _ref11.filePaths;
975
+ ValidateParameters({
976
+ libraryId: libraryId,
977
+ objectId: objectId
978
+ });
979
+ ValidateWriteToken(writeToken);
980
+ this.Log("Creating Directories: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
981
+ this.Log(filePaths);
982
+ ops = filePaths.map(function (path) {
983
+ return {
984
+ op: "add",
985
+ type: "directory",
986
+ path: path
987
+ };
988
+ });
989
+ _context12.next = 8;
990
+ return _regeneratorRuntime.awrap(this.CreateFileUploadJob({
991
+ libraryId: libraryId,
992
+ objectId: objectId,
993
+ writeToken: writeToken,
994
+ ops: ops
995
+ }));
996
+
997
+ case 8:
998
+ case "end":
999
+ return _context12.stop();
1066
1000
  }
1067
- }, _callee12, this);
1068
- }));
1069
-
1070
- return function (_x13) {
1071
- return _ref21.apply(this, arguments);
1072
- };
1073
- }();
1001
+ }
1002
+ }, null, this);
1003
+ };
1074
1004
  /**
1075
1005
  * Delete the specified list of files/directories
1076
1006
  *
@@ -1084,47 +1014,41 @@ exports.CreateFileDirectories = /*#__PURE__*/function () {
1084
1014
  */
1085
1015
 
1086
1016
 
1087
- exports.DeleteFiles = /*#__PURE__*/function () {
1088
- var _ref23 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(_ref22) {
1089
- var libraryId, objectId, writeToken, filePaths, ops;
1090
- return _regeneratorRuntime.wrap(function _callee13$(_context13) {
1091
- while (1) {
1092
- switch (_context13.prev = _context13.next) {
1093
- case 0:
1094
- libraryId = _ref22.libraryId, objectId = _ref22.objectId, writeToken = _ref22.writeToken, filePaths = _ref22.filePaths;
1095
- ValidateParameters({
1096
- libraryId: libraryId,
1097
- objectId: objectId
1098
- });
1099
- ValidateWriteToken(writeToken);
1100
- this.Log("Deleting Files: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
1101
- this.Log(filePaths);
1102
- ops = filePaths.map(function (path) {
1103
- return {
1104
- op: "del",
1105
- path: path
1106
- };
1107
- });
1108
- _context13.next = 8;
1109
- return this.CreateFileUploadJob({
1110
- libraryId: libraryId,
1111
- objectId: objectId,
1112
- writeToken: writeToken,
1113
- ops: ops
1114
- });
1115
-
1116
- case 8:
1117
- case "end":
1118
- return _context13.stop();
1119
- }
1017
+ exports.DeleteFiles = function _callee11(_ref12) {
1018
+ var libraryId, objectId, writeToken, filePaths, ops;
1019
+ return _regeneratorRuntime.async(function _callee11$(_context13) {
1020
+ while (1) {
1021
+ switch (_context13.prev = _context13.next) {
1022
+ case 0:
1023
+ libraryId = _ref12.libraryId, objectId = _ref12.objectId, writeToken = _ref12.writeToken, filePaths = _ref12.filePaths;
1024
+ ValidateParameters({
1025
+ libraryId: libraryId,
1026
+ objectId: objectId
1027
+ });
1028
+ ValidateWriteToken(writeToken);
1029
+ this.Log("Deleting Files: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
1030
+ this.Log(filePaths);
1031
+ ops = filePaths.map(function (path) {
1032
+ return {
1033
+ op: "del",
1034
+ path: path
1035
+ };
1036
+ });
1037
+ _context13.next = 8;
1038
+ return _regeneratorRuntime.awrap(this.CreateFileUploadJob({
1039
+ libraryId: libraryId,
1040
+ objectId: objectId,
1041
+ writeToken: writeToken,
1042
+ ops: ops
1043
+ }));
1044
+
1045
+ case 8:
1046
+ case "end":
1047
+ return _context13.stop();
1120
1048
  }
1121
- }, _callee13, this);
1122
- }));
1123
-
1124
- return function (_x14) {
1125
- return _ref23.apply(this, arguments);
1126
- };
1127
- }();
1049
+ }
1050
+ }, null, this);
1051
+ };
1128
1052
  /**
1129
1053
  * Download a file from a content object
1130
1054
  *
@@ -1151,216 +1075,212 @@ exports.DeleteFiles = /*#__PURE__*/function () {
1151
1075
  */
1152
1076
 
1153
1077
 
1154
- exports.DownloadFile = /*#__PURE__*/function () {
1155
- var _ref25 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(_ref24) {
1156
- var libraryId,
1157
- objectId,
1158
- versionHash,
1159
- writeToken,
1160
- filePath,
1161
- _ref24$format,
1162
- format,
1163
- _ref24$chunked,
1164
- chunked,
1165
- chunkSize,
1166
- _ref24$clientSideDecr,
1167
- clientSideDecryption,
1168
- callback,
1169
- fileInfo,
1170
- encrypted,
1171
- encryption,
1172
- path,
1173
- headers,
1174
- ownerCapKey,
1175
- ownerCap,
1176
- bytesTotal,
1177
- _args14 = arguments;
1178
-
1179
- return _regeneratorRuntime.wrap(function _callee14$(_context14) {
1180
- while (1) {
1181
- switch (_context14.prev = _context14.next) {
1182
- case 0:
1183
- libraryId = _ref24.libraryId, objectId = _ref24.objectId, versionHash = _ref24.versionHash, writeToken = _ref24.writeToken, filePath = _ref24.filePath, _ref24$format = _ref24.format, format = _ref24$format === void 0 ? "arrayBuffer" : _ref24$format, _ref24$chunked = _ref24.chunked, chunked = _ref24$chunked === void 0 ? false : _ref24$chunked, chunkSize = _ref24.chunkSize, _ref24$clientSideDecr = _ref24.clientSideDecryption, clientSideDecryption = _ref24$clientSideDecr === void 0 ? false : _ref24$clientSideDecr, callback = _ref24.callback;
1184
- ValidateParameters({
1185
- libraryId: libraryId,
1186
- objectId: objectId,
1187
- versionHash: versionHash
1188
- });
1189
- ValidatePresence("filePath", filePath);
1190
-
1191
- if (versionHash) {
1192
- objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1193
- }
1194
-
1195
- _context14.next = 6;
1196
- return this.ContentObjectMetadata({
1197
- libraryId: libraryId,
1198
- objectId: objectId,
1199
- versionHash: versionHash,
1200
- writeToken: writeToken,
1201
- metadataSubtree: UrlJoin("files", filePath)
1202
- });
1203
-
1204
- case 6:
1205
- fileInfo = _context14.sent;
1206
- encrypted = fileInfo && fileInfo["."].encryption && fileInfo["."].encryption.scheme === "cgck";
1207
- encryption = encrypted ? "cgck" : undefined;
1208
- path = encrypted && !clientSideDecryption ? UrlJoin("q", writeToken || versionHash || objectId, "rep", "files_download", filePath) : UrlJoin("q", writeToken || versionHash || objectId, "files", filePath);
1209
- _context14.next = 12;
1210
- return this.authClient.AuthorizationHeader({
1211
- libraryId: libraryId,
1212
- objectId: objectId,
1213
- versionHash: versionHash,
1214
- encryption: encryption
1215
- });
1216
-
1217
- case 12:
1218
- headers = _context14.sent;
1219
- headers.Accept = "*/*"; // If not owner, indicate re-encryption
1220
-
1221
- ownerCapKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(this.signer.address));
1222
- _context14.next = 17;
1223
- return this.ContentObjectMetadata({
1224
- libraryId: libraryId,
1225
- objectId: objectId,
1226
- metadataSubtree: ownerCapKey
1227
- });
1228
-
1229
- case 17:
1230
- ownerCap = _context14.sent;
1231
- _context14.t1 = encrypted;
1232
-
1233
- if (!_context14.t1) {
1234
- _context14.next = 26;
1235
- break;
1236
- }
1237
-
1238
- _context14.t2 = this.utils;
1239
- _context14.t3 = this.signer.address;
1240
- _context14.next = 24;
1241
- return this.ContentObjectOwner({
1242
- objectId: objectId
1243
- });
1244
-
1245
- case 24:
1246
- _context14.t4 = _context14.sent;
1247
- _context14.t1 = !_context14.t2.EqualAddress.call(_context14.t2, _context14.t3, _context14.t4);
1248
-
1249
- case 26:
1250
- _context14.t0 = _context14.t1;
1078
+ exports.DownloadFile = function _callee12(_ref13) {
1079
+ var libraryId,
1080
+ objectId,
1081
+ versionHash,
1082
+ writeToken,
1083
+ filePath,
1084
+ _ref13$format,
1085
+ format,
1086
+ _ref13$chunked,
1087
+ chunked,
1088
+ chunkSize,
1089
+ _ref13$clientSideDecr,
1090
+ clientSideDecryption,
1091
+ callback,
1092
+ fileInfo,
1093
+ encrypted,
1094
+ encryption,
1095
+ path,
1096
+ headers,
1097
+ ownerCapKey,
1098
+ ownerCap,
1099
+ bytesTotal,
1100
+ _args14 = arguments;
1101
+
1102
+ return _regeneratorRuntime.async(function _callee12$(_context14) {
1103
+ while (1) {
1104
+ switch (_context14.prev = _context14.next) {
1105
+ case 0:
1106
+ libraryId = _ref13.libraryId, objectId = _ref13.objectId, versionHash = _ref13.versionHash, writeToken = _ref13.writeToken, filePath = _ref13.filePath, _ref13$format = _ref13.format, format = _ref13$format === void 0 ? "arrayBuffer" : _ref13$format, _ref13$chunked = _ref13.chunked, chunked = _ref13$chunked === void 0 ? false : _ref13$chunked, chunkSize = _ref13.chunkSize, _ref13$clientSideDecr = _ref13.clientSideDecryption, clientSideDecryption = _ref13$clientSideDecr === void 0 ? false : _ref13$clientSideDecr, callback = _ref13.callback;
1107
+ ValidateParameters({
1108
+ libraryId: libraryId,
1109
+ objectId: objectId,
1110
+ versionHash: versionHash
1111
+ });
1112
+ ValidatePresence("filePath", filePath);
1113
+
1114
+ if (versionHash) {
1115
+ objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1116
+ }
1251
1117
 
1252
- if (!_context14.t0) {
1253
- _context14.next = 29;
1254
- break;
1255
- }
1118
+ _context14.next = 6;
1119
+ return _regeneratorRuntime.awrap(this.ContentObjectMetadata({
1120
+ libraryId: libraryId,
1121
+ objectId: objectId,
1122
+ versionHash: versionHash,
1123
+ writeToken: writeToken,
1124
+ metadataSubtree: UrlJoin("files", filePath)
1125
+ }));
1126
+
1127
+ case 6:
1128
+ fileInfo = _context14.sent;
1129
+ encrypted = fileInfo && fileInfo["."].encryption && fileInfo["."].encryption.scheme === "cgck";
1130
+ encryption = encrypted ? "cgck" : undefined;
1131
+ path = encrypted && !clientSideDecryption ? UrlJoin("q", writeToken || versionHash || objectId, "rep", "files_download", filePath) : UrlJoin("q", writeToken || versionHash || objectId, "files", filePath);
1132
+ _context14.next = 12;
1133
+ return _regeneratorRuntime.awrap(this.authClient.AuthorizationHeader({
1134
+ libraryId: libraryId,
1135
+ objectId: objectId,
1136
+ versionHash: versionHash,
1137
+ encryption: encryption
1138
+ }));
1139
+
1140
+ case 12:
1141
+ headers = _context14.sent;
1142
+ headers.Accept = "*/*"; // If not owner, indicate re-encryption
1143
+
1144
+ ownerCapKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(this.signer.address));
1145
+ _context14.next = 17;
1146
+ return _regeneratorRuntime.awrap(this.ContentObjectMetadata({
1147
+ libraryId: libraryId,
1148
+ objectId: objectId,
1149
+ metadataSubtree: ownerCapKey
1150
+ }));
1151
+
1152
+ case 17:
1153
+ ownerCap = _context14.sent;
1154
+ _context14.t1 = encrypted;
1155
+
1156
+ if (!_context14.t1) {
1157
+ _context14.next = 26;
1158
+ break;
1159
+ }
1256
1160
 
1257
- _context14.t0 = !ownerCap;
1161
+ _context14.t2 = this.utils;
1162
+ _context14.t3 = this.signer.address;
1163
+ _context14.next = 24;
1164
+ return _regeneratorRuntime.awrap(this.ContentObjectOwner({
1165
+ objectId: objectId
1166
+ }));
1258
1167
 
1259
- case 29:
1260
- if (!_context14.t0) {
1261
- _context14.next = 31;
1262
- break;
1263
- }
1168
+ case 24:
1169
+ _context14.t4 = _context14.sent;
1170
+ _context14.t1 = !_context14.t2.EqualAddress.call(_context14.t2, _context14.t3, _context14.t4);
1264
1171
 
1265
- headers["X-Content-Fabric-Decryption-Mode"] = "reencrypt";
1172
+ case 26:
1173
+ _context14.t0 = _context14.t1;
1266
1174
 
1267
- case 31:
1268
- // If using server side decryption, specify in header
1269
- if (encrypted && !clientSideDecryption) {
1270
- headers["X-Content-Fabric-Decryption-Mode"] = "decrypt"; // rep/files_download endpoint doesn't currently support Range header
1271
-
1272
- chunkSize = Number.MAX_SAFE_INTEGER;
1273
- }
1175
+ if (!_context14.t0) {
1176
+ _context14.next = 29;
1177
+ break;
1178
+ }
1274
1179
 
1275
- bytesTotal = fileInfo["."].size;
1180
+ _context14.t0 = !ownerCap;
1276
1181
 
1277
- if (!(encrypted && clientSideDecryption)) {
1278
- _context14.next = 51;
1279
- break;
1280
- }
1281
-
1282
- _context14.t5 = this;
1283
- _context14.next = 37;
1284
- return this.EncryptionConk({
1285
- libraryId: libraryId,
1286
- objectId: objectId,
1287
- versionHash: versionHash,
1288
- download: true
1289
- });
1182
+ case 29:
1183
+ if (!_context14.t0) {
1184
+ _context14.next = 31;
1185
+ break;
1186
+ }
1290
1187
 
1291
- case 37:
1292
- _context14.t6 = _context14.sent;
1293
- _context14.t7 = path;
1294
- _context14.t8 = bytesTotal;
1295
- _context14.t9 = headers;
1296
- _context14.t10 = callback;
1297
- _context14.t11 = format;
1298
- _context14.t12 = clientSideDecryption;
1299
- _context14.t13 = chunked;
1300
- _context14.t14 = {
1301
- conk: _context14.t6,
1302
- downloadPath: _context14.t7,
1303
- bytesTotal: _context14.t8,
1304
- headers: _context14.t9,
1305
- callback: _context14.t10,
1306
- format: _context14.t11,
1307
- clientSideDecryption: _context14.t12,
1308
- chunked: _context14.t13
1309
- };
1310
- _context14.next = 48;
1311
- return _context14.t5.DownloadEncrypted.call(_context14.t5, _context14.t14);
1188
+ headers["X-Content-Fabric-Decryption-Mode"] = "reencrypt";
1312
1189
 
1313
- case 48:
1314
- return _context14.abrupt("return", _context14.sent);
1190
+ case 31:
1191
+ // If using server side decryption, specify in header
1192
+ if (encrypted && !clientSideDecryption) {
1193
+ headers["X-Content-Fabric-Decryption-Mode"] = "decrypt"; // rep/files_download endpoint doesn't currently support Range header
1315
1194
 
1316
- case 51:
1317
- if (!chunkSize) {
1318
- chunkSize = 10000000;
1319
- }
1195
+ chunkSize = Number.MAX_SAFE_INTEGER;
1196
+ }
1320
1197
 
1321
- _context14.prev = 52;
1322
- _context14.next = 55;
1323
- return this.Download({
1324
- downloadPath: path,
1325
- bytesTotal: bytesTotal,
1326
- headers: headers,
1327
- callback: callback,
1328
- format: format,
1329
- chunked: chunked,
1330
- chunkSize: chunkSize
1331
- });
1198
+ bytesTotal = fileInfo["."].size;
1332
1199
 
1333
- case 55:
1334
- return _context14.abrupt("return", _context14.sent);
1200
+ if (!(encrypted && clientSideDecryption)) {
1201
+ _context14.next = 53;
1202
+ break;
1203
+ }
1335
1204
 
1336
- case 58:
1337
- _context14.prev = 58;
1338
- _context14.t15 = _context14["catch"](52);
1205
+ _context14.t5 = _regeneratorRuntime;
1206
+ _context14.t6 = this;
1207
+ _context14.next = 38;
1208
+ return _regeneratorRuntime.awrap(this.EncryptionConk({
1209
+ libraryId: libraryId,
1210
+ objectId: objectId,
1211
+ versionHash: versionHash,
1212
+ download: true
1213
+ }));
1214
+
1215
+ case 38:
1216
+ _context14.t7 = _context14.sent;
1217
+ _context14.t8 = path;
1218
+ _context14.t9 = bytesTotal;
1219
+ _context14.t10 = headers;
1220
+ _context14.t11 = callback;
1221
+ _context14.t12 = format;
1222
+ _context14.t13 = clientSideDecryption;
1223
+ _context14.t14 = chunked;
1224
+ _context14.t15 = {
1225
+ conk: _context14.t7,
1226
+ downloadPath: _context14.t8,
1227
+ bytesTotal: _context14.t9,
1228
+ headers: _context14.t10,
1229
+ callback: _context14.t11,
1230
+ format: _context14.t12,
1231
+ clientSideDecryption: _context14.t13,
1232
+ chunked: _context14.t14
1233
+ };
1234
+ _context14.t16 = _context14.t6.DownloadEncrypted.call(_context14.t6, _context14.t15);
1235
+ _context14.next = 50;
1236
+ return _context14.t5.awrap.call(_context14.t5, _context14.t16);
1237
+
1238
+ case 50:
1239
+ return _context14.abrupt("return", _context14.sent);
1240
+
1241
+ case 53:
1242
+ if (!chunkSize) {
1243
+ chunkSize = 10000000;
1244
+ }
1339
1245
 
1340
- if (!(encrypted && !clientSideDecryption)) {
1341
- _context14.next = 62;
1342
- break;
1343
- }
1246
+ _context14.prev = 54;
1247
+ _context14.next = 57;
1248
+ return _regeneratorRuntime.awrap(this.Download({
1249
+ downloadPath: path,
1250
+ bytesTotal: bytesTotal,
1251
+ headers: headers,
1252
+ callback: callback,
1253
+ format: format,
1254
+ chunked: chunked,
1255
+ chunkSize: chunkSize
1256
+ }));
1257
+
1258
+ case 57:
1259
+ return _context14.abrupt("return", _context14.sent);
1260
+
1261
+ case 60:
1262
+ _context14.prev = 60;
1263
+ _context14.t17 = _context14["catch"](54);
1264
+
1265
+ if (!(encrypted && !clientSideDecryption)) {
1266
+ _context14.next = 64;
1267
+ break;
1268
+ }
1344
1269
 
1345
- return _context14.abrupt("return", this.DownloadFile(_objectSpread(_objectSpread({}, _args14[0]), {}, {
1346
- clientSideDecryption: true
1347
- })));
1270
+ return _context14.abrupt("return", this.DownloadFile(_objectSpread({}, _args14[0], {
1271
+ clientSideDecryption: true
1272
+ })));
1348
1273
 
1349
- case 62:
1350
- throw _context14.t15;
1274
+ case 64:
1275
+ throw _context14.t17;
1351
1276
 
1352
- case 63:
1353
- case "end":
1354
- return _context14.stop();
1355
- }
1277
+ case 65:
1278
+ case "end":
1279
+ return _context14.stop();
1356
1280
  }
1357
- }, _callee14, this, [[52, 58]]);
1358
- }));
1359
-
1360
- return function (_x15) {
1361
- return _ref25.apply(this, arguments);
1362
- };
1363
- }();
1281
+ }
1282
+ }, null, this, [[54, 60]]);
1283
+ };
1364
1284
  /* Parts */
1365
1285
 
1366
1286
  /**
@@ -1377,63 +1297,59 @@ exports.DownloadFile = /*#__PURE__*/function () {
1377
1297
  */
1378
1298
 
1379
1299
 
1380
- exports.ContentParts = /*#__PURE__*/function () {
1381
- var _ref27 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref26) {
1382
- var libraryId, objectId, versionHash, path, response;
1383
- return _regeneratorRuntime.wrap(function _callee15$(_context15) {
1384
- while (1) {
1385
- switch (_context15.prev = _context15.next) {
1386
- case 0:
1387
- libraryId = _ref26.libraryId, objectId = _ref26.objectId, versionHash = _ref26.versionHash;
1388
- ValidateParameters({
1389
- libraryId: libraryId,
1390
- objectId: objectId,
1391
- versionHash: versionHash
1392
- });
1393
- this.Log("Retrieving parts: ".concat(libraryId, " ").concat(objectId || versionHash));
1394
-
1395
- if (versionHash) {
1396
- objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1397
- }
1398
-
1399
- path = UrlJoin("q", versionHash || objectId, "parts");
1400
- _context15.t0 = this.utils;
1401
- _context15.t1 = this.HttpClient;
1402
- _context15.next = 9;
1403
- return this.authClient.AuthorizationHeader({
1404
- libraryId: libraryId,
1405
- objectId: objectId,
1406
- versionHash: versionHash
1407
- });
1300
+ exports.ContentParts = function _callee13(_ref14) {
1301
+ var libraryId, objectId, versionHash, path, response;
1302
+ return _regeneratorRuntime.async(function _callee13$(_context15) {
1303
+ while (1) {
1304
+ switch (_context15.prev = _context15.next) {
1305
+ case 0:
1306
+ libraryId = _ref14.libraryId, objectId = _ref14.objectId, versionHash = _ref14.versionHash;
1307
+ ValidateParameters({
1308
+ libraryId: libraryId,
1309
+ objectId: objectId,
1310
+ versionHash: versionHash
1311
+ });
1312
+ this.Log("Retrieving parts: ".concat(libraryId, " ").concat(objectId || versionHash));
1313
+
1314
+ if (versionHash) {
1315
+ objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1316
+ }
1408
1317
 
1409
- case 9:
1410
- _context15.t2 = _context15.sent;
1411
- _context15.t3 = path;
1412
- _context15.t4 = {
1413
- headers: _context15.t2,
1414
- method: "GET",
1415
- path: _context15.t3
1416
- };
1417
- _context15.t5 = _context15.t1.Request.call(_context15.t1, _context15.t4);
1418
- _context15.next = 15;
1419
- return _context15.t0.ResponseToJson.call(_context15.t0, _context15.t5);
1420
-
1421
- case 15:
1422
- response = _context15.sent;
1423
- return _context15.abrupt("return", response.parts);
1424
-
1425
- case 17:
1426
- case "end":
1427
- return _context15.stop();
1428
- }
1318
+ path = UrlJoin("q", versionHash || objectId, "parts");
1319
+ _context15.t0 = _regeneratorRuntime;
1320
+ _context15.t1 = this.utils;
1321
+ _context15.t2 = this.HttpClient;
1322
+ _context15.next = 10;
1323
+ return _regeneratorRuntime.awrap(this.authClient.AuthorizationHeader({
1324
+ libraryId: libraryId,
1325
+ objectId: objectId,
1326
+ versionHash: versionHash
1327
+ }));
1328
+
1329
+ case 10:
1330
+ _context15.t3 = _context15.sent;
1331
+ _context15.t4 = path;
1332
+ _context15.t5 = {
1333
+ headers: _context15.t3,
1334
+ method: "GET",
1335
+ path: _context15.t4
1336
+ };
1337
+ _context15.t6 = _context15.t2.Request.call(_context15.t2, _context15.t5);
1338
+ _context15.t7 = _context15.t1.ResponseToJson.call(_context15.t1, _context15.t6);
1339
+ _context15.next = 17;
1340
+ return _context15.t0.awrap.call(_context15.t0, _context15.t7);
1341
+
1342
+ case 17:
1343
+ response = _context15.sent;
1344
+ return _context15.abrupt("return", response.parts);
1345
+
1346
+ case 19:
1347
+ case "end":
1348
+ return _context15.stop();
1429
1349
  }
1430
- }, _callee15, this);
1431
- }));
1432
-
1433
- return function (_x16) {
1434
- return _ref27.apply(this, arguments);
1435
- };
1436
- }();
1350
+ }
1351
+ }, null, this);
1352
+ };
1437
1353
  /**
1438
1354
  * Get information on a specific part
1439
1355
  *
@@ -1449,63 +1365,59 @@ exports.ContentParts = /*#__PURE__*/function () {
1449
1365
  */
1450
1366
 
1451
1367
 
1452
- exports.ContentPart = /*#__PURE__*/function () {
1453
- var _ref29 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(_ref28) {
1454
- var libraryId, objectId, versionHash, partHash, path;
1455
- return _regeneratorRuntime.wrap(function _callee16$(_context16) {
1456
- while (1) {
1457
- switch (_context16.prev = _context16.next) {
1458
- case 0:
1459
- libraryId = _ref28.libraryId, objectId = _ref28.objectId, versionHash = _ref28.versionHash, partHash = _ref28.partHash;
1460
- ValidateParameters({
1461
- libraryId: libraryId,
1462
- objectId: objectId,
1463
- versionHash: versionHash
1464
- });
1465
- ValidatePartHash(partHash);
1466
- this.Log("Retrieving part: ".concat(libraryId, " ").concat(objectId || versionHash, " ").concat(partHash));
1467
-
1468
- if (versionHash) {
1469
- objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1470
- }
1471
-
1472
- path = UrlJoin("q", versionHash || objectId, "parts", partHash);
1473
- _context16.t0 = this.utils;
1474
- _context16.t1 = this.HttpClient;
1475
- _context16.next = 10;
1476
- return this.authClient.AuthorizationHeader({
1477
- libraryId: libraryId,
1478
- objectId: objectId,
1479
- versionHash: versionHash
1480
- });
1481
-
1482
- case 10:
1483
- _context16.t2 = _context16.sent;
1484
- _context16.t3 = path;
1485
- _context16.t4 = {
1486
- headers: _context16.t2,
1487
- method: "GET",
1488
- path: _context16.t3
1489
- };
1490
- _context16.t5 = _context16.t1.Request.call(_context16.t1, _context16.t4);
1491
- _context16.next = 16;
1492
- return _context16.t0.ResponseToJson.call(_context16.t0, _context16.t5);
1493
-
1494
- case 16:
1495
- return _context16.abrupt("return", _context16.sent);
1368
+ exports.ContentPart = function _callee14(_ref15) {
1369
+ var libraryId, objectId, versionHash, partHash, path;
1370
+ return _regeneratorRuntime.async(function _callee14$(_context16) {
1371
+ while (1) {
1372
+ switch (_context16.prev = _context16.next) {
1373
+ case 0:
1374
+ libraryId = _ref15.libraryId, objectId = _ref15.objectId, versionHash = _ref15.versionHash, partHash = _ref15.partHash;
1375
+ ValidateParameters({
1376
+ libraryId: libraryId,
1377
+ objectId: objectId,
1378
+ versionHash: versionHash
1379
+ });
1380
+ ValidatePartHash(partHash);
1381
+ this.Log("Retrieving part: ".concat(libraryId, " ").concat(objectId || versionHash, " ").concat(partHash));
1382
+
1383
+ if (versionHash) {
1384
+ objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1385
+ }
1496
1386
 
1497
- case 17:
1498
- case "end":
1499
- return _context16.stop();
1500
- }
1387
+ path = UrlJoin("q", versionHash || objectId, "parts", partHash);
1388
+ _context16.t0 = _regeneratorRuntime;
1389
+ _context16.t1 = this.utils;
1390
+ _context16.t2 = this.HttpClient;
1391
+ _context16.next = 11;
1392
+ return _regeneratorRuntime.awrap(this.authClient.AuthorizationHeader({
1393
+ libraryId: libraryId,
1394
+ objectId: objectId,
1395
+ versionHash: versionHash
1396
+ }));
1397
+
1398
+ case 11:
1399
+ _context16.t3 = _context16.sent;
1400
+ _context16.t4 = path;
1401
+ _context16.t5 = {
1402
+ headers: _context16.t3,
1403
+ method: "GET",
1404
+ path: _context16.t4
1405
+ };
1406
+ _context16.t6 = _context16.t2.Request.call(_context16.t2, _context16.t5);
1407
+ _context16.t7 = _context16.t1.ResponseToJson.call(_context16.t1, _context16.t6);
1408
+ _context16.next = 18;
1409
+ return _context16.t0.awrap.call(_context16.t0, _context16.t7);
1410
+
1411
+ case 18:
1412
+ return _context16.abrupt("return", _context16.sent);
1413
+
1414
+ case 19:
1415
+ case "end":
1416
+ return _context16.stop();
1501
1417
  }
1502
- }, _callee16, this);
1503
- }));
1504
-
1505
- return function (_x17) {
1506
- return _ref29.apply(this, arguments);
1507
- };
1508
- }();
1418
+ }
1419
+ }, null, this);
1420
+ };
1509
1421
  /**
1510
1422
  * Download a part from a content object. The fromByte and range parameters can be used to specify a
1511
1423
  * specific section of the part to download.
@@ -1532,416 +1444,394 @@ exports.ContentPart = /*#__PURE__*/function () {
1532
1444
  */
1533
1445
 
1534
1446
 
1535
- exports.DownloadPart = /*#__PURE__*/function () {
1536
- var _ref31 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref30) {
1537
- var libraryId, objectId, versionHash, writeToken, partHash, _ref30$format, format, _ref30$chunked, chunked, _ref30$chunkSize, chunkSize, callback, encrypted, encryption, path, headers, bytesTotal;
1538
-
1539
- return _regeneratorRuntime.wrap(function _callee17$(_context17) {
1540
- while (1) {
1541
- switch (_context17.prev = _context17.next) {
1542
- case 0:
1543
- libraryId = _ref30.libraryId, objectId = _ref30.objectId, versionHash = _ref30.versionHash, writeToken = _ref30.writeToken, partHash = _ref30.partHash, _ref30$format = _ref30.format, format = _ref30$format === void 0 ? "arrayBuffer" : _ref30$format, _ref30$chunked = _ref30.chunked, chunked = _ref30$chunked === void 0 ? false : _ref30$chunked, _ref30$chunkSize = _ref30.chunkSize, chunkSize = _ref30$chunkSize === void 0 ? 10000000 : _ref30$chunkSize, callback = _ref30.callback;
1544
- ValidateParameters({
1545
- libraryId: libraryId,
1546
- objectId: objectId,
1547
- versionHash: versionHash
1548
- });
1549
- ValidatePartHash(partHash);
1550
-
1551
- if (versionHash) {
1552
- objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1553
- }
1554
-
1555
- encrypted = partHash.startsWith("hqpe");
1556
- encryption = encrypted ? "cgck" : undefined;
1557
- path = UrlJoin("q", writeToken || versionHash || objectId, "data", partHash);
1558
- _context17.next = 9;
1559
- return this.authClient.AuthorizationHeader({
1560
- libraryId: libraryId,
1561
- objectId: objectId,
1562
- versionHash: versionHash,
1563
- encryption: encryption
1564
- });
1565
-
1566
- case 9:
1567
- headers = _context17.sent;
1568
- _context17.next = 12;
1569
- return this.ContentPart({
1570
- libraryId: libraryId,
1571
- objectId: objectId,
1572
- versionHash: versionHash,
1573
- partHash: partHash
1574
- });
1575
-
1576
- case 12:
1577
- bytesTotal = _context17.sent.part.size;
1578
-
1579
- if (!encrypted) {
1580
- _context17.next = 37;
1581
- break;
1582
- }
1583
-
1584
- _context17.t0 = this.utils;
1585
- _context17.t1 = this.signer.address;
1586
- _context17.next = 18;
1587
- return this.ContentObjectOwner({
1588
- objectId: objectId
1589
- });
1590
-
1591
- case 18:
1592
- _context17.t2 = _context17.sent;
1447
+ exports.DownloadPart = function _callee15(_ref16) {
1448
+ var libraryId, objectId, versionHash, writeToken, partHash, _ref16$format, format, _ref16$chunked, chunked, _ref16$chunkSize, chunkSize, callback, encrypted, encryption, path, headers, bytesTotal;
1593
1449
 
1594
- if (_context17.t0.EqualAddress.call(_context17.t0, _context17.t1, _context17.t2)) {
1595
- _context17.next = 21;
1596
- break;
1597
- }
1450
+ return _regeneratorRuntime.async(function _callee15$(_context17) {
1451
+ while (1) {
1452
+ switch (_context17.prev = _context17.next) {
1453
+ case 0:
1454
+ libraryId = _ref16.libraryId, objectId = _ref16.objectId, versionHash = _ref16.versionHash, writeToken = _ref16.writeToken, partHash = _ref16.partHash, _ref16$format = _ref16.format, format = _ref16$format === void 0 ? "arrayBuffer" : _ref16$format, _ref16$chunked = _ref16.chunked, chunked = _ref16$chunked === void 0 ? false : _ref16$chunked, _ref16$chunkSize = _ref16.chunkSize, chunkSize = _ref16$chunkSize === void 0 ? 10000000 : _ref16$chunkSize, callback = _ref16.callback;
1455
+ ValidateParameters({
1456
+ libraryId: libraryId,
1457
+ objectId: objectId,
1458
+ versionHash: versionHash
1459
+ });
1460
+ ValidatePartHash(partHash);
1598
1461
 
1599
- headers["X-Content-Fabric-Decryption-Mode"] = "reencrypt";
1600
-
1601
- case 21:
1602
- _context17.t3 = this;
1603
- _context17.next = 24;
1604
- return this.EncryptionConk({
1605
- libraryId: libraryId,
1606
- objectId: objectId,
1607
- download: true
1608
- });
1462
+ if (versionHash) {
1463
+ objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1464
+ }
1609
1465
 
1610
- case 24:
1611
- _context17.t4 = _context17.sent;
1612
- _context17.t5 = path;
1613
- _context17.t6 = bytesTotal;
1614
- _context17.t7 = headers;
1615
- _context17.t8 = callback;
1616
- _context17.t9 = format;
1617
- _context17.t10 = chunked;
1618
- _context17.t11 = {
1619
- conk: _context17.t4,
1620
- downloadPath: _context17.t5,
1621
- bytesTotal: _context17.t6,
1622
- headers: _context17.t7,
1623
- callback: _context17.t8,
1624
- format: _context17.t9,
1625
- chunked: _context17.t10
1626
- };
1627
- _context17.next = 34;
1628
- return _context17.t3.DownloadEncrypted.call(_context17.t3, _context17.t11);
1466
+ encrypted = partHash.startsWith("hqpe");
1467
+ encryption = encrypted ? "cgck" : undefined;
1468
+ path = UrlJoin("q", writeToken || versionHash || objectId, "data", partHash);
1469
+ _context17.next = 9;
1470
+ return _regeneratorRuntime.awrap(this.authClient.AuthorizationHeader({
1471
+ libraryId: libraryId,
1472
+ objectId: objectId,
1473
+ versionHash: versionHash,
1474
+ encryption: encryption
1475
+ }));
1476
+
1477
+ case 9:
1478
+ headers = _context17.sent;
1479
+ _context17.next = 12;
1480
+ return _regeneratorRuntime.awrap(this.ContentPart({
1481
+ libraryId: libraryId,
1482
+ objectId: objectId,
1483
+ versionHash: versionHash,
1484
+ partHash: partHash
1485
+ }));
1486
+
1487
+ case 12:
1488
+ bytesTotal = _context17.sent.part.size;
1489
+
1490
+ if (!encrypted) {
1491
+ _context17.next = 39;
1492
+ break;
1493
+ }
1629
1494
 
1630
- case 34:
1631
- return _context17.abrupt("return", _context17.sent);
1495
+ _context17.t0 = this.utils;
1496
+ _context17.t1 = this.signer.address;
1497
+ _context17.next = 18;
1498
+ return _regeneratorRuntime.awrap(this.ContentObjectOwner({
1499
+ objectId: objectId
1500
+ }));
1632
1501
 
1633
- case 37:
1634
- _context17.next = 39;
1635
- return this.Download({
1636
- downloadPath: path,
1637
- bytesTotal: bytesTotal,
1638
- headers: headers,
1639
- callback: callback,
1640
- format: format,
1641
- chunked: chunked,
1642
- chunkSize: chunkSize
1643
- });
1502
+ case 18:
1503
+ _context17.t2 = _context17.sent;
1644
1504
 
1645
- case 39:
1646
- return _context17.abrupt("return", _context17.sent);
1505
+ if (_context17.t0.EqualAddress.call(_context17.t0, _context17.t1, _context17.t2)) {
1506
+ _context17.next = 21;
1507
+ break;
1508
+ }
1647
1509
 
1648
- case 40:
1649
- case "end":
1650
- return _context17.stop();
1651
- }
1510
+ headers["X-Content-Fabric-Decryption-Mode"] = "reencrypt";
1511
+
1512
+ case 21:
1513
+ _context17.t3 = _regeneratorRuntime;
1514
+ _context17.t4 = this;
1515
+ _context17.next = 25;
1516
+ return _regeneratorRuntime.awrap(this.EncryptionConk({
1517
+ libraryId: libraryId,
1518
+ objectId: objectId,
1519
+ download: true
1520
+ }));
1521
+
1522
+ case 25:
1523
+ _context17.t5 = _context17.sent;
1524
+ _context17.t6 = path;
1525
+ _context17.t7 = bytesTotal;
1526
+ _context17.t8 = headers;
1527
+ _context17.t9 = callback;
1528
+ _context17.t10 = format;
1529
+ _context17.t11 = chunked;
1530
+ _context17.t12 = {
1531
+ conk: _context17.t5,
1532
+ downloadPath: _context17.t6,
1533
+ bytesTotal: _context17.t7,
1534
+ headers: _context17.t8,
1535
+ callback: _context17.t9,
1536
+ format: _context17.t10,
1537
+ chunked: _context17.t11
1538
+ };
1539
+ _context17.t13 = _context17.t4.DownloadEncrypted.call(_context17.t4, _context17.t12);
1540
+ _context17.next = 36;
1541
+ return _context17.t3.awrap.call(_context17.t3, _context17.t13);
1542
+
1543
+ case 36:
1544
+ return _context17.abrupt("return", _context17.sent);
1545
+
1546
+ case 39:
1547
+ _context17.next = 41;
1548
+ return _regeneratorRuntime.awrap(this.Download({
1549
+ downloadPath: path,
1550
+ bytesTotal: bytesTotal,
1551
+ headers: headers,
1552
+ callback: callback,
1553
+ format: format,
1554
+ chunked: chunked,
1555
+ chunkSize: chunkSize
1556
+ }));
1557
+
1558
+ case 41:
1559
+ return _context17.abrupt("return", _context17.sent);
1560
+
1561
+ case 42:
1562
+ case "end":
1563
+ return _context17.stop();
1652
1564
  }
1653
- }, _callee17, this);
1654
- }));
1655
-
1656
- return function (_x18) {
1657
- return _ref31.apply(this, arguments);
1658
- };
1659
- }();
1660
-
1661
- exports.Download = /*#__PURE__*/function () {
1662
- var _ref33 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(_ref32) {
1663
- var downloadPath, headers, bytesTotal, _ref32$chunked, chunked, _ref32$chunkSize, chunkSize, callback, _ref32$format, format, outputChunks, bytesFinished, totalChunks, i, response;
1664
-
1665
- return _regeneratorRuntime.wrap(function _callee18$(_context18) {
1666
- while (1) {
1667
- switch (_context18.prev = _context18.next) {
1668
- case 0:
1669
- downloadPath = _ref32.downloadPath, headers = _ref32.headers, bytesTotal = _ref32.bytesTotal, _ref32$chunked = _ref32.chunked, chunked = _ref32$chunked === void 0 ? false : _ref32$chunked, _ref32$chunkSize = _ref32.chunkSize, chunkSize = _ref32$chunkSize === void 0 ? 2000000 : _ref32$chunkSize, callback = _ref32.callback, _ref32$format = _ref32.format, format = _ref32$format === void 0 ? "arrayBuffer" : _ref32$format;
1670
-
1671
- if (!(chunked && !callback)) {
1672
- _context18.next = 3;
1673
- break;
1674
- }
1565
+ }
1566
+ }, null, this);
1567
+ };
1675
1568
 
1676
- throw Error("No callback specified for chunked download");
1569
+ exports.Download = function _callee16(_ref17) {
1570
+ var downloadPath, headers, bytesTotal, _ref17$chunked, chunked, _ref17$chunkSize, chunkSize, callback, _ref17$format, format, outputChunks, bytesFinished, totalChunks, i, response;
1677
1571
 
1678
- case 3:
1679
- if (!chunked) {
1680
- outputChunks = [];
1681
- } // Download file in chunks
1572
+ return _regeneratorRuntime.async(function _callee16$(_context18) {
1573
+ while (1) {
1574
+ switch (_context18.prev = _context18.next) {
1575
+ case 0:
1576
+ downloadPath = _ref17.downloadPath, headers = _ref17.headers, bytesTotal = _ref17.bytesTotal, _ref17$chunked = _ref17.chunked, chunked = _ref17$chunked === void 0 ? false : _ref17$chunked, _ref17$chunkSize = _ref17.chunkSize, chunkSize = _ref17$chunkSize === void 0 ? 2000000 : _ref17$chunkSize, callback = _ref17.callback, _ref17$format = _ref17.format, format = _ref17$format === void 0 ? "arrayBuffer" : _ref17$format;
1682
1577
 
1578
+ if (!(chunked && !callback)) {
1579
+ _context18.next = 3;
1580
+ break;
1581
+ }
1683
1582
 
1684
- bytesFinished = 0;
1685
- totalChunks = Math.ceil(bytesTotal / chunkSize);
1686
- i = 0;
1583
+ throw Error("No callback specified for chunked download");
1687
1584
 
1688
- case 7:
1689
- if (!(i < totalChunks)) {
1690
- _context18.next = 35;
1691
- break;
1692
- }
1585
+ case 3:
1586
+ if (!chunked) {
1587
+ outputChunks = [];
1588
+ } // Download file in chunks
1693
1589
 
1694
- headers["Range"] = "bytes=".concat(bytesFinished, "-").concat(bytesFinished + chunkSize - 1);
1695
- _context18.next = 11;
1696
- return this.HttpClient.Request({
1697
- path: downloadPath,
1698
- headers: headers,
1699
- method: "GET"
1700
- });
1701
-
1702
- case 11:
1703
- response = _context18.sent;
1704
- bytesFinished = Math.min(bytesFinished + chunkSize, bytesTotal);
1705
1590
 
1706
- if (!chunked) {
1707
- _context18.next = 24;
1708
- break;
1709
- }
1591
+ bytesFinished = 0;
1592
+ totalChunks = Math.ceil(bytesTotal / chunkSize);
1593
+ i = 0;
1710
1594
 
1711
- _context18.t0 = callback;
1712
- _context18.t1 = bytesFinished;
1713
- _context18.t2 = bytesTotal;
1714
- _context18.next = 19;
1715
- return this.utils.ResponseToFormat(format, response);
1716
-
1717
- case 19:
1718
- _context18.t3 = _context18.sent;
1719
- _context18.t4 = {
1720
- bytesFinished: _context18.t1,
1721
- bytesTotal: _context18.t2,
1722
- chunk: _context18.t3
1723
- };
1724
- (0, _context18.t0)(_context18.t4);
1725
- _context18.next = 32;
1595
+ case 7:
1596
+ if (!(i < totalChunks)) {
1597
+ _context18.next = 35;
1726
1598
  break;
1599
+ }
1727
1600
 
1728
- case 24:
1729
- _context18.t5 = outputChunks;
1730
- _context18.t6 = Buffer;
1731
- _context18.next = 28;
1732
- return response.arrayBuffer();
1601
+ headers["Range"] = "bytes=".concat(bytesFinished, "-").concat(bytesFinished + chunkSize - 1);
1602
+ _context18.next = 11;
1603
+ return _regeneratorRuntime.awrap(this.HttpClient.Request({
1604
+ path: downloadPath,
1605
+ headers: headers,
1606
+ method: "GET"
1607
+ }));
1733
1608
 
1734
- case 28:
1735
- _context18.t7 = _context18.sent;
1736
- _context18.t8 = _context18.t6.from.call(_context18.t6, _context18.t7);
1609
+ case 11:
1610
+ response = _context18.sent;
1611
+ bytesFinished = Math.min(bytesFinished + chunkSize, bytesTotal);
1737
1612
 
1738
- _context18.t5.push.call(_context18.t5, _context18.t8);
1613
+ if (!chunked) {
1614
+ _context18.next = 24;
1615
+ break;
1616
+ }
1739
1617
 
1740
- if (callback) {
1741
- callback({
1742
- bytesFinished: bytesFinished,
1743
- bytesTotal: bytesTotal
1744
- });
1745
- }
1618
+ _context18.t0 = callback;
1619
+ _context18.t1 = bytesFinished;
1620
+ _context18.t2 = bytesTotal;
1621
+ _context18.next = 19;
1622
+ return _regeneratorRuntime.awrap(this.utils.ResponseToFormat(format, response));
1623
+
1624
+ case 19:
1625
+ _context18.t3 = _context18.sent;
1626
+ _context18.t4 = {
1627
+ bytesFinished: _context18.t1,
1628
+ bytesTotal: _context18.t2,
1629
+ chunk: _context18.t3
1630
+ };
1631
+ (0, _context18.t0)(_context18.t4);
1632
+ _context18.next = 32;
1633
+ break;
1634
+
1635
+ case 24:
1636
+ _context18.t5 = outputChunks;
1637
+ _context18.t6 = Buffer;
1638
+ _context18.next = 28;
1639
+ return _regeneratorRuntime.awrap(response.arrayBuffer());
1640
+
1641
+ case 28:
1642
+ _context18.t7 = _context18.sent;
1643
+ _context18.t8 = _context18.t6.from.call(_context18.t6, _context18.t7);
1644
+
1645
+ _context18.t5.push.call(_context18.t5, _context18.t8);
1646
+
1647
+ if (callback) {
1648
+ callback({
1649
+ bytesFinished: bytesFinished,
1650
+ bytesTotal: bytesTotal
1651
+ });
1652
+ }
1746
1653
 
1747
- case 32:
1748
- i++;
1749
- _context18.next = 7;
1750
- break;
1654
+ case 32:
1655
+ i++;
1656
+ _context18.next = 7;
1657
+ break;
1751
1658
 
1752
- case 35:
1753
- if (chunked) {
1754
- _context18.next = 39;
1755
- break;
1756
- }
1659
+ case 35:
1660
+ if (chunked) {
1661
+ _context18.next = 39;
1662
+ break;
1663
+ }
1757
1664
 
1758
- _context18.next = 38;
1759
- return this.utils.ResponseToFormat(format, new Response(Buffer.concat(outputChunks)));
1665
+ _context18.next = 38;
1666
+ return _regeneratorRuntime.awrap(this.utils.ResponseToFormat(format, new Response(Buffer.concat(outputChunks))));
1760
1667
 
1761
- case 38:
1762
- return _context18.abrupt("return", _context18.sent);
1668
+ case 38:
1669
+ return _context18.abrupt("return", _context18.sent);
1763
1670
 
1764
- case 39:
1765
- case "end":
1766
- return _context18.stop();
1767
- }
1671
+ case 39:
1672
+ case "end":
1673
+ return _context18.stop();
1768
1674
  }
1769
- }, _callee18, this);
1770
- }));
1675
+ }
1676
+ }, null, this);
1677
+ };
1771
1678
 
1772
- return function (_x19) {
1773
- return _ref33.apply(this, arguments);
1774
- };
1775
- }();
1679
+ exports.DownloadEncrypted = function _callee18(_ref18) {
1680
+ var _this2 = this;
1776
1681
 
1777
- exports.DownloadEncrypted = /*#__PURE__*/function () {
1778
- var _ref35 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(_ref34) {
1779
- var _this2 = this;
1682
+ var conk, downloadPath, bytesTotal, headers, callback, _ref18$format, format, _ref18$chunked, chunked, isReencryption, chunkSize, bytesFinished, outputChunks, stream, totalChunks, i, response;
1780
1683
 
1781
- var conk, downloadPath, bytesTotal, headers, callback, _ref34$format, format, _ref34$chunked, chunked, isReencryption, chunkSize, bytesFinished, outputChunks, stream, totalChunks, i, response;
1684
+ return _regeneratorRuntime.async(function _callee18$(_context20) {
1685
+ while (1) {
1686
+ switch (_context20.prev = _context20.next) {
1687
+ case 0:
1688
+ conk = _ref18.conk, downloadPath = _ref18.downloadPath, bytesTotal = _ref18.bytesTotal, headers = _ref18.headers, callback = _ref18.callback, _ref18$format = _ref18.format, format = _ref18$format === void 0 ? "arrayBuffer" : _ref18$format, _ref18$chunked = _ref18.chunked, chunked = _ref18$chunked === void 0 ? false : _ref18$chunked;
1782
1689
 
1783
- return _regeneratorRuntime.wrap(function _callee20$(_context20) {
1784
- while (1) {
1785
- switch (_context20.prev = _context20.next) {
1786
- case 0:
1787
- conk = _ref34.conk, downloadPath = _ref34.downloadPath, bytesTotal = _ref34.bytesTotal, headers = _ref34.headers, callback = _ref34.callback, _ref34$format = _ref34.format, format = _ref34$format === void 0 ? "arrayBuffer" : _ref34$format, _ref34$chunked = _ref34.chunked, chunked = _ref34$chunked === void 0 ? false : _ref34$chunked;
1690
+ if (!(chunked && !callback)) {
1691
+ _context20.next = 3;
1692
+ break;
1693
+ }
1788
1694
 
1789
- if (!(chunked && !callback)) {
1790
- _context20.next = 3;
1791
- break;
1792
- }
1695
+ throw Error("No callback specified for chunked download");
1696
+
1697
+ case 3:
1698
+ // Must align chunk size with encryption block size
1699
+ isReencryption = conk.public_key.startsWith("ktpk");
1700
+ chunkSize = this.Crypto.EncryptedBlockSize(1000000, isReencryption);
1701
+ bytesFinished = 0;
1702
+ format = format.toLowerCase();
1703
+ outputChunks = []; // Set up decryption stream
1704
+
1705
+ _context20.next = 10;
1706
+ return _regeneratorRuntime.awrap(this.Crypto.OpenDecryptionStream(conk));
1707
+
1708
+ case 10:
1709
+ stream = _context20.sent;
1710
+ stream.on("data", function _callee17(chunk) {
1711
+ var arrayBuffer;
1712
+ return _regeneratorRuntime.async(function _callee17$(_context19) {
1713
+ while (1) {
1714
+ switch (_context19.prev = _context19.next) {
1715
+ case 0:
1716
+ if (!chunked) {
1717
+ _context19.next = 13;
1718
+ break;
1719
+ }
1793
1720
 
1794
- throw Error("No callback specified for chunked download");
1795
-
1796
- case 3:
1797
- // Must align chunk size with encryption block size
1798
- isReencryption = conk.public_key.startsWith("ktpk");
1799
- chunkSize = this.Crypto.EncryptedBlockSize(1000000, isReencryption);
1800
- bytesFinished = 0;
1801
- format = format.toLowerCase();
1802
- outputChunks = []; // Set up decryption stream
1803
-
1804
- _context20.next = 10;
1805
- return this.Crypto.OpenDecryptionStream(conk);
1806
-
1807
- case 10:
1808
- stream = _context20.sent;
1809
- stream.on("data", /*#__PURE__*/function () {
1810
- var _ref36 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(chunk) {
1811
- var arrayBuffer;
1812
- return _regeneratorRuntime.wrap(function _callee19$(_context19) {
1813
- while (1) {
1814
- switch (_context19.prev = _context19.next) {
1815
- case 0:
1816
- if (!chunked) {
1817
- _context19.next = 13;
1818
- break;
1819
- }
1820
-
1821
- if (!(format !== "buffer")) {
1822
- _context19.next = 10;
1823
- break;
1824
- }
1825
-
1826
- arrayBuffer = chunk.buffer.slice(chunk.byteOffset, chunk.byteOffset + chunk.byteLength);
1827
-
1828
- if (!(format === "arraybuffer")) {
1829
- _context19.next = 7;
1830
- break;
1831
- }
1832
-
1833
- chunk = arrayBuffer;
1834
- _context19.next = 10;
1835
- break;
1836
-
1837
- case 7:
1838
- _context19.next = 9;
1839
- return _this2.utils.ResponseToFormat(format, new Response(arrayBuffer));
1840
-
1841
- case 9:
1842
- chunk = _context19.sent;
1843
-
1844
- case 10:
1845
- callback({
1846
- bytesFinished: bytesFinished,
1847
- bytesTotal: bytesTotal,
1848
- chunk: chunk
1849
- });
1850
- _context19.next = 15;
1851
- break;
1852
-
1853
- case 13:
1854
- if (callback) {
1855
- callback({
1856
- bytesFinished: bytesFinished,
1857
- bytesTotal: bytesTotal
1858
- });
1859
- }
1860
-
1861
- outputChunks.push(chunk);
1862
-
1863
- case 15:
1864
- case "end":
1865
- return _context19.stop();
1721
+ if (!(format !== "buffer")) {
1722
+ _context19.next = 10;
1723
+ break;
1866
1724
  }
1867
- }
1868
- }, _callee19);
1869
- }));
1870
1725
 
1871
- return function (_x21) {
1872
- return _ref36.apply(this, arguments);
1873
- };
1874
- }());
1875
- totalChunks = Math.ceil(bytesTotal / chunkSize);
1876
- i = 0;
1877
-
1878
- case 14:
1879
- if (!(i < totalChunks)) {
1880
- _context20.next = 30;
1881
- break;
1882
- }
1726
+ arrayBuffer = chunk.buffer.slice(chunk.byteOffset, chunk.byteOffset + chunk.byteLength);
1883
1727
 
1884
- headers["Range"] = "bytes=".concat(bytesFinished, "-").concat(bytesFinished + chunkSize - 1);
1885
- _context20.next = 18;
1886
- return this.HttpClient.Request({
1887
- headers: headers,
1888
- method: "GET",
1889
- path: downloadPath
1890
- });
1728
+ if (!(format === "arraybuffer")) {
1729
+ _context19.next = 7;
1730
+ break;
1731
+ }
1891
1732
 
1892
- case 18:
1893
- response = _context20.sent;
1894
- bytesFinished = Math.min(bytesFinished + chunkSize, bytesTotal);
1895
- _context20.t0 = stream;
1896
- _context20.t1 = Uint8Array;
1897
- _context20.next = 24;
1898
- return response.arrayBuffer();
1733
+ chunk = arrayBuffer;
1734
+ _context19.next = 10;
1735
+ break;
1736
+
1737
+ case 7:
1738
+ _context19.next = 9;
1739
+ return _regeneratorRuntime.awrap(_this2.utils.ResponseToFormat(format, new Response(arrayBuffer)));
1740
+
1741
+ case 9:
1742
+ chunk = _context19.sent;
1743
+
1744
+ case 10:
1745
+ callback({
1746
+ bytesFinished: bytesFinished,
1747
+ bytesTotal: bytesTotal,
1748
+ chunk: chunk
1749
+ });
1750
+ _context19.next = 15;
1751
+ break;
1752
+
1753
+ case 13:
1754
+ if (callback) {
1755
+ callback({
1756
+ bytesFinished: bytesFinished,
1757
+ bytesTotal: bytesTotal
1758
+ });
1759
+ }
1899
1760
 
1900
- case 24:
1901
- _context20.t2 = _context20.sent;
1902
- _context20.t3 = new _context20.t1(_context20.t2);
1761
+ outputChunks.push(chunk);
1903
1762
 
1904
- _context20.t0.write.call(_context20.t0, _context20.t3);
1763
+ case 15:
1764
+ case "end":
1765
+ return _context19.stop();
1766
+ }
1767
+ }
1768
+ });
1769
+ });
1770
+ totalChunks = Math.ceil(bytesTotal / chunkSize);
1771
+ i = 0;
1905
1772
 
1906
- case 27:
1907
- i++;
1908
- _context20.next = 14;
1773
+ case 14:
1774
+ if (!(i < totalChunks)) {
1775
+ _context20.next = 30;
1909
1776
  break;
1777
+ }
1910
1778
 
1911
- case 30:
1912
- // Wait for decryption to complete
1913
- stream.end();
1914
- _context20.next = 33;
1915
- return new Promise(function (resolve) {
1916
- return stream.on("finish", function () {
1917
- resolve();
1918
- });
1779
+ headers["Range"] = "bytes=".concat(bytesFinished, "-").concat(bytesFinished + chunkSize - 1);
1780
+ _context20.next = 18;
1781
+ return _regeneratorRuntime.awrap(this.HttpClient.Request({
1782
+ headers: headers,
1783
+ method: "GET",
1784
+ path: downloadPath
1785
+ }));
1786
+
1787
+ case 18:
1788
+ response = _context20.sent;
1789
+ bytesFinished = Math.min(bytesFinished + chunkSize, bytesTotal);
1790
+ _context20.t0 = stream;
1791
+ _context20.t1 = Uint8Array;
1792
+ _context20.next = 24;
1793
+ return _regeneratorRuntime.awrap(response.arrayBuffer());
1794
+
1795
+ case 24:
1796
+ _context20.t2 = _context20.sent;
1797
+ _context20.t3 = new _context20.t1(_context20.t2);
1798
+
1799
+ _context20.t0.write.call(_context20.t0, _context20.t3);
1800
+
1801
+ case 27:
1802
+ i++;
1803
+ _context20.next = 14;
1804
+ break;
1805
+
1806
+ case 30:
1807
+ // Wait for decryption to complete
1808
+ stream.end();
1809
+ _context20.next = 33;
1810
+ return _regeneratorRuntime.awrap(new Promise(function (resolve) {
1811
+ return stream.on("finish", function () {
1812
+ resolve();
1919
1813
  });
1814
+ }));
1920
1815
 
1921
- case 33:
1922
- if (chunked) {
1923
- _context20.next = 37;
1924
- break;
1925
- }
1816
+ case 33:
1817
+ if (chunked) {
1818
+ _context20.next = 37;
1819
+ break;
1820
+ }
1926
1821
 
1927
- _context20.next = 36;
1928
- return this.utils.ResponseToFormat(format, new Response(Buffer.concat(outputChunks)));
1822
+ _context20.next = 36;
1823
+ return _regeneratorRuntime.awrap(this.utils.ResponseToFormat(format, new Response(Buffer.concat(outputChunks))));
1929
1824
 
1930
- case 36:
1931
- return _context20.abrupt("return", _context20.sent);
1825
+ case 36:
1826
+ return _context20.abrupt("return", _context20.sent);
1932
1827
 
1933
- case 37:
1934
- case "end":
1935
- return _context20.stop();
1936
- }
1828
+ case 37:
1829
+ case "end":
1830
+ return _context20.stop();
1937
1831
  }
1938
- }, _callee20, this);
1939
- }));
1940
-
1941
- return function (_x20) {
1942
- return _ref35.apply(this, arguments);
1943
- };
1944
- }();
1832
+ }
1833
+ }, null, this);
1834
+ };
1945
1835
  /**
1946
1836
  * Create a part upload draft
1947
1837
  *
@@ -1957,61 +1847,57 @@ exports.DownloadEncrypted = /*#__PURE__*/function () {
1957
1847
  */
1958
1848
 
1959
1849
 
1960
- exports.CreatePart = /*#__PURE__*/function () {
1961
- var _ref38 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(_ref37) {
1962
- var libraryId, objectId, writeToken, encryption, path, openResponse;
1963
- return _regeneratorRuntime.wrap(function _callee21$(_context21) {
1964
- while (1) {
1965
- switch (_context21.prev = _context21.next) {
1966
- case 0:
1967
- libraryId = _ref37.libraryId, objectId = _ref37.objectId, writeToken = _ref37.writeToken, encryption = _ref37.encryption;
1968
- ValidateParameters({
1969
- libraryId: libraryId,
1970
- objectId: objectId
1971
- });
1972
- ValidateWriteToken(writeToken);
1973
- path = UrlJoin("q", writeToken, "parts");
1974
- _context21.t0 = this.utils;
1975
- _context21.t1 = this.HttpClient;
1976
- _context21.next = 8;
1977
- return this.authClient.AuthorizationHeader({
1978
- libraryId: libraryId,
1979
- objectId: objectId,
1980
- update: true,
1981
- encryption: encryption
1982
- });
1983
-
1984
- case 8:
1985
- _context21.t2 = _context21.sent;
1986
- _context21.t3 = path;
1987
- _context21.t4 = {
1988
- headers: _context21.t2,
1989
- method: "POST",
1990
- path: _context21.t3,
1991
- bodyType: "BINARY",
1992
- body: "",
1993
- failover: false
1994
- };
1995
- _context21.t5 = _context21.t1.Request.call(_context21.t1, _context21.t4);
1996
- _context21.next = 14;
1997
- return _context21.t0.ResponseToJson.call(_context21.t0, _context21.t5);
1998
-
1999
- case 14:
2000
- openResponse = _context21.sent;
2001
- return _context21.abrupt("return", openResponse.part.write_token);
2002
-
2003
- case 16:
2004
- case "end":
2005
- return _context21.stop();
2006
- }
1850
+ exports.CreatePart = function _callee19(_ref19) {
1851
+ var libraryId, objectId, writeToken, encryption, path, openResponse;
1852
+ return _regeneratorRuntime.async(function _callee19$(_context21) {
1853
+ while (1) {
1854
+ switch (_context21.prev = _context21.next) {
1855
+ case 0:
1856
+ libraryId = _ref19.libraryId, objectId = _ref19.objectId, writeToken = _ref19.writeToken, encryption = _ref19.encryption;
1857
+ ValidateParameters({
1858
+ libraryId: libraryId,
1859
+ objectId: objectId
1860
+ });
1861
+ ValidateWriteToken(writeToken);
1862
+ path = UrlJoin("q", writeToken, "parts");
1863
+ _context21.t0 = _regeneratorRuntime;
1864
+ _context21.t1 = this.utils;
1865
+ _context21.t2 = this.HttpClient;
1866
+ _context21.next = 9;
1867
+ return _regeneratorRuntime.awrap(this.authClient.AuthorizationHeader({
1868
+ libraryId: libraryId,
1869
+ objectId: objectId,
1870
+ update: true,
1871
+ encryption: encryption
1872
+ }));
1873
+
1874
+ case 9:
1875
+ _context21.t3 = _context21.sent;
1876
+ _context21.t4 = path;
1877
+ _context21.t5 = {
1878
+ headers: _context21.t3,
1879
+ method: "POST",
1880
+ path: _context21.t4,
1881
+ bodyType: "BINARY",
1882
+ body: "",
1883
+ failover: false
1884
+ };
1885
+ _context21.t6 = _context21.t2.Request.call(_context21.t2, _context21.t5);
1886
+ _context21.t7 = _context21.t1.ResponseToJson.call(_context21.t1, _context21.t6);
1887
+ _context21.next = 16;
1888
+ return _context21.t0.awrap.call(_context21.t0, _context21.t7);
1889
+
1890
+ case 16:
1891
+ openResponse = _context21.sent;
1892
+ return _context21.abrupt("return", openResponse.part.write_token);
1893
+
1894
+ case 18:
1895
+ case "end":
1896
+ return _context21.stop();
2007
1897
  }
2008
- }, _callee21, this);
2009
- }));
2010
-
2011
- return function (_x22) {
2012
- return _ref38.apply(this, arguments);
2013
- };
2014
- }();
1898
+ }
1899
+ }, null, this);
1900
+ };
2015
1901
  /**
2016
1902
  * Upload data to an open part draft
2017
1903
  *
@@ -2029,80 +1915,77 @@ exports.CreatePart = /*#__PURE__*/function () {
2029
1915
  */
2030
1916
 
2031
1917
 
2032
- exports.UploadPartChunk = /*#__PURE__*/function () {
2033
- var _ref40 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(_ref39) {
2034
- var libraryId, objectId, writeToken, partWriteToken, chunk, encryption, conk, path;
2035
- return _regeneratorRuntime.wrap(function _callee22$(_context22) {
2036
- while (1) {
2037
- switch (_context22.prev = _context22.next) {
2038
- case 0:
2039
- libraryId = _ref39.libraryId, objectId = _ref39.objectId, writeToken = _ref39.writeToken, partWriteToken = _ref39.partWriteToken, chunk = _ref39.chunk, encryption = _ref39.encryption;
2040
- ValidateParameters({
2041
- libraryId: libraryId,
2042
- objectId: objectId
2043
- });
2044
- ValidateWriteToken(writeToken);
2045
-
2046
- if (!(encryption && encryption !== "none")) {
2047
- _context22.next = 10;
2048
- break;
2049
- }
1918
+ exports.UploadPartChunk = function _callee20(_ref20) {
1919
+ var libraryId, objectId, writeToken, partWriteToken, chunk, encryption, _conk, path;
2050
1920
 
2051
- _context22.next = 6;
2052
- return this.EncryptionConk({
2053
- libraryId: libraryId,
2054
- objectId: objectId,
2055
- writeToken: writeToken
2056
- });
1921
+ return _regeneratorRuntime.async(function _callee20$(_context22) {
1922
+ while (1) {
1923
+ switch (_context22.prev = _context22.next) {
1924
+ case 0:
1925
+ libraryId = _ref20.libraryId, objectId = _ref20.objectId, writeToken = _ref20.writeToken, partWriteToken = _ref20.partWriteToken, chunk = _ref20.chunk, encryption = _ref20.encryption;
1926
+ ValidateParameters({
1927
+ libraryId: libraryId,
1928
+ objectId: objectId
1929
+ });
1930
+ ValidateWriteToken(writeToken);
2057
1931
 
2058
- case 6:
2059
- conk = _context22.sent;
2060
- _context22.next = 9;
2061
- return this.Crypto.Encrypt(conk, chunk);
2062
-
2063
- case 9:
2064
- chunk = _context22.sent;
2065
-
2066
- case 10:
2067
- path = UrlJoin("q", writeToken, "parts");
2068
- _context22.t0 = this.utils;
2069
- _context22.t1 = this.HttpClient;
2070
- _context22.next = 15;
2071
- return this.authClient.AuthorizationHeader({
2072
- libraryId: libraryId,
2073
- objectId: objectId,
2074
- update: true,
2075
- encryption: encryption
2076
- });
1932
+ if (!(encryption && encryption !== "none")) {
1933
+ _context22.next = 10;
1934
+ break;
1935
+ }
2077
1936
 
2078
- case 15:
2079
- _context22.t2 = _context22.sent;
2080
- _context22.t3 = UrlJoin(path, partWriteToken);
2081
- _context22.t4 = chunk;
2082
- _context22.t5 = {
2083
- headers: _context22.t2,
2084
- method: "POST",
2085
- path: _context22.t3,
2086
- body: _context22.t4,
2087
- bodyType: "BINARY",
2088
- failover: false
2089
- };
2090
- _context22.t6 = _context22.t1.Request.call(_context22.t1, _context22.t5);
2091
- _context22.next = 22;
2092
- return _context22.t0.ResponseToJson.call(_context22.t0, _context22.t6);
2093
-
2094
- case 22:
2095
- case "end":
2096
- return _context22.stop();
2097
- }
1937
+ _context22.next = 6;
1938
+ return _regeneratorRuntime.awrap(this.EncryptionConk({
1939
+ libraryId: libraryId,
1940
+ objectId: objectId,
1941
+ writeToken: writeToken
1942
+ }));
1943
+
1944
+ case 6:
1945
+ _conk = _context22.sent;
1946
+ _context22.next = 9;
1947
+ return _regeneratorRuntime.awrap(this.Crypto.Encrypt(_conk, chunk));
1948
+
1949
+ case 9:
1950
+ chunk = _context22.sent;
1951
+
1952
+ case 10:
1953
+ path = UrlJoin("q", writeToken, "parts");
1954
+ _context22.t0 = _regeneratorRuntime;
1955
+ _context22.t1 = this.utils;
1956
+ _context22.t2 = this.HttpClient;
1957
+ _context22.next = 16;
1958
+ return _regeneratorRuntime.awrap(this.authClient.AuthorizationHeader({
1959
+ libraryId: libraryId,
1960
+ objectId: objectId,
1961
+ update: true,
1962
+ encryption: encryption
1963
+ }));
1964
+
1965
+ case 16:
1966
+ _context22.t3 = _context22.sent;
1967
+ _context22.t4 = UrlJoin(path, partWriteToken);
1968
+ _context22.t5 = chunk;
1969
+ _context22.t6 = {
1970
+ headers: _context22.t3,
1971
+ method: "POST",
1972
+ path: _context22.t4,
1973
+ body: _context22.t5,
1974
+ bodyType: "BINARY",
1975
+ failover: false
1976
+ };
1977
+ _context22.t7 = _context22.t2.Request.call(_context22.t2, _context22.t6);
1978
+ _context22.t8 = _context22.t1.ResponseToJson.call(_context22.t1, _context22.t7);
1979
+ _context22.next = 24;
1980
+ return _context22.t0.awrap.call(_context22.t0, _context22.t8);
1981
+
1982
+ case 24:
1983
+ case "end":
1984
+ return _context22.stop();
2098
1985
  }
2099
- }, _callee22, this);
2100
- }));
2101
-
2102
- return function (_x23) {
2103
- return _ref40.apply(this, arguments);
2104
- };
2105
- }();
1986
+ }
1987
+ }, null, this);
1988
+ };
2106
1989
  /**
2107
1990
  * Finalize an open part draft
2108
1991
  *
@@ -2119,64 +2002,62 @@ exports.UploadPartChunk = /*#__PURE__*/function () {
2119
2002
  */
2120
2003
 
2121
2004
 
2122
- exports.FinalizePart = /*#__PURE__*/function () {
2123
- var _ref42 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23(_ref41) {
2124
- var libraryId, objectId, writeToken, partWriteToken, encryption, path;
2125
- return _regeneratorRuntime.wrap(function _callee23$(_context23) {
2126
- while (1) {
2127
- switch (_context23.prev = _context23.next) {
2128
- case 0:
2129
- libraryId = _ref41.libraryId, objectId = _ref41.objectId, writeToken = _ref41.writeToken, partWriteToken = _ref41.partWriteToken, encryption = _ref41.encryption;
2130
- ValidateParameters({
2131
- libraryId: libraryId,
2132
- objectId: objectId
2133
- });
2134
- ValidateWriteToken(writeToken);
2135
- path = UrlJoin("q", writeToken, "parts");
2136
- _context23.t0 = this.utils;
2137
- _context23.t1 = this.HttpClient;
2138
- _context23.next = 8;
2139
- return this.authClient.AuthorizationHeader({
2140
- libraryId: libraryId,
2141
- objectId: objectId,
2142
- update: true,
2143
- encryption: encryption
2144
- });
2145
-
2146
- case 8:
2147
- _context23.t2 = _context23.sent;
2148
- _context23.t3 = UrlJoin(path, partWriteToken);
2149
- _context23.t4 = {
2150
- headers: _context23.t2,
2151
- method: "POST",
2152
- path: _context23.t3,
2153
- bodyType: "BINARY",
2154
- body: "",
2155
- failover: false
2156
- };
2157
- _context23.next = 13;
2158
- return _context23.t1.Request.call(_context23.t1, _context23.t4);
2159
-
2160
- case 13:
2161
- _context23.t5 = _context23.sent;
2162
- _context23.next = 16;
2163
- return _context23.t0.ResponseToJson.call(_context23.t0, _context23.t5);
2164
-
2165
- case 16:
2166
- return _context23.abrupt("return", _context23.sent);
2167
-
2168
- case 17:
2169
- case "end":
2170
- return _context23.stop();
2171
- }
2005
+ exports.FinalizePart = function _callee21(_ref21) {
2006
+ var libraryId, objectId, writeToken, partWriteToken, encryption, path;
2007
+ return _regeneratorRuntime.async(function _callee21$(_context23) {
2008
+ while (1) {
2009
+ switch (_context23.prev = _context23.next) {
2010
+ case 0:
2011
+ libraryId = _ref21.libraryId, objectId = _ref21.objectId, writeToken = _ref21.writeToken, partWriteToken = _ref21.partWriteToken, encryption = _ref21.encryption;
2012
+ ValidateParameters({
2013
+ libraryId: libraryId,
2014
+ objectId: objectId
2015
+ });
2016
+ ValidateWriteToken(writeToken);
2017
+ path = UrlJoin("q", writeToken, "parts");
2018
+ _context23.t0 = _regeneratorRuntime;
2019
+ _context23.t1 = this.utils;
2020
+ _context23.t2 = _regeneratorRuntime;
2021
+ _context23.t3 = this.HttpClient;
2022
+ _context23.next = 10;
2023
+ return _regeneratorRuntime.awrap(this.authClient.AuthorizationHeader({
2024
+ libraryId: libraryId,
2025
+ objectId: objectId,
2026
+ update: true,
2027
+ encryption: encryption
2028
+ }));
2029
+
2030
+ case 10:
2031
+ _context23.t4 = _context23.sent;
2032
+ _context23.t5 = UrlJoin(path, partWriteToken);
2033
+ _context23.t6 = {
2034
+ headers: _context23.t4,
2035
+ method: "POST",
2036
+ path: _context23.t5,
2037
+ bodyType: "BINARY",
2038
+ body: "",
2039
+ failover: false
2040
+ };
2041
+ _context23.t7 = _context23.t3.Request.call(_context23.t3, _context23.t6);
2042
+ _context23.next = 16;
2043
+ return _context23.t2.awrap.call(_context23.t2, _context23.t7);
2044
+
2045
+ case 16:
2046
+ _context23.t8 = _context23.sent;
2047
+ _context23.t9 = _context23.t1.ResponseToJson.call(_context23.t1, _context23.t8);
2048
+ _context23.next = 20;
2049
+ return _context23.t0.awrap.call(_context23.t0, _context23.t9);
2050
+
2051
+ case 20:
2052
+ return _context23.abrupt("return", _context23.sent);
2053
+
2054
+ case 21:
2055
+ case "end":
2056
+ return _context23.stop();
2172
2057
  }
2173
- }, _callee23, this);
2174
- }));
2175
-
2176
- return function (_x24) {
2177
- return _ref42.apply(this, arguments);
2178
- };
2179
- }();
2058
+ }
2059
+ }, null, this);
2060
+ };
2180
2061
  /**
2181
2062
  * Upload part to an object draft
2182
2063
  *
@@ -2200,96 +2081,90 @@ exports.FinalizePart = /*#__PURE__*/function () {
2200
2081
  */
2201
2082
 
2202
2083
 
2203
- exports.UploadPart = /*#__PURE__*/function () {
2204
- var _ref44 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee24(_ref43) {
2205
- var libraryId, objectId, writeToken, data, _ref43$encryption, encryption, _ref43$chunkSize, chunkSize, callback, partWriteToken, size, i, chunk;
2206
-
2207
- return _regeneratorRuntime.wrap(function _callee24$(_context24) {
2208
- while (1) {
2209
- switch (_context24.prev = _context24.next) {
2210
- case 0:
2211
- libraryId = _ref43.libraryId, objectId = _ref43.objectId, writeToken = _ref43.writeToken, data = _ref43.data, _ref43$encryption = _ref43.encryption, encryption = _ref43$encryption === void 0 ? "none" : _ref43$encryption, _ref43$chunkSize = _ref43.chunkSize, chunkSize = _ref43$chunkSize === void 0 ? 10000000 : _ref43$chunkSize, callback = _ref43.callback;
2212
- ValidateParameters({
2213
- libraryId: libraryId,
2214
- objectId: objectId
2215
- });
2216
- ValidateWriteToken(writeToken);
2217
- _context24.next = 5;
2218
- return this.CreatePart({
2219
- libraryId: libraryId,
2220
- objectId: objectId,
2221
- writeToken: writeToken,
2222
- encryption: encryption
2223
- });
2224
-
2225
- case 5:
2226
- partWriteToken = _context24.sent;
2227
- size = data.length || data.byteLength || data.size;
2228
-
2229
- if (callback) {
2230
- callback({
2231
- bytesFinished: 0,
2232
- bytesTotal: size
2233
- });
2234
- }
2235
-
2236
- i = 0;
2237
-
2238
- case 9:
2239
- if (!(i < size)) {
2240
- _context24.next = 17;
2241
- break;
2242
- }
2243
-
2244
- chunk = data.slice(i, i + chunkSize);
2245
- _context24.next = 13;
2246
- return this.UploadPartChunk({
2247
- libraryId: libraryId,
2248
- objectId: objectId,
2249
- writeToken: writeToken,
2250
- partWriteToken: partWriteToken,
2251
- chunk: chunk,
2252
- encryption: encryption
2084
+ exports.UploadPart = function _callee22(_ref22) {
2085
+ var libraryId, objectId, writeToken, data, _ref22$encryption, encryption, _ref22$chunkSize, chunkSize, callback, partWriteToken, size, i, chunk;
2086
+
2087
+ return _regeneratorRuntime.async(function _callee22$(_context24) {
2088
+ while (1) {
2089
+ switch (_context24.prev = _context24.next) {
2090
+ case 0:
2091
+ libraryId = _ref22.libraryId, objectId = _ref22.objectId, writeToken = _ref22.writeToken, data = _ref22.data, _ref22$encryption = _ref22.encryption, encryption = _ref22$encryption === void 0 ? "none" : _ref22$encryption, _ref22$chunkSize = _ref22.chunkSize, chunkSize = _ref22$chunkSize === void 0 ? 10000000 : _ref22$chunkSize, callback = _ref22.callback;
2092
+ ValidateParameters({
2093
+ libraryId: libraryId,
2094
+ objectId: objectId
2095
+ });
2096
+ ValidateWriteToken(writeToken);
2097
+ _context24.next = 5;
2098
+ return _regeneratorRuntime.awrap(this.CreatePart({
2099
+ libraryId: libraryId,
2100
+ objectId: objectId,
2101
+ writeToken: writeToken,
2102
+ encryption: encryption
2103
+ }));
2104
+
2105
+ case 5:
2106
+ partWriteToken = _context24.sent;
2107
+ size = data.length || data.byteLength || data.size;
2108
+
2109
+ if (callback) {
2110
+ callback({
2111
+ bytesFinished: 0,
2112
+ bytesTotal: size
2253
2113
  });
2114
+ }
2254
2115
 
2255
- case 13:
2256
- if (callback) {
2257
- callback({
2258
- bytesFinished: Math.min(i + chunkSize, size),
2259
- bytesTotal: size
2260
- });
2261
- }
2116
+ i = 0;
2262
2117
 
2263
- case 14:
2264
- i += chunkSize;
2265
- _context24.next = 9;
2118
+ case 9:
2119
+ if (!(i < size)) {
2120
+ _context24.next = 17;
2266
2121
  break;
2122
+ }
2267
2123
 
2268
- case 17:
2269
- _context24.next = 19;
2270
- return this.FinalizePart({
2271
- libraryId: libraryId,
2272
- objectId: objectId,
2273
- writeToken: writeToken,
2274
- partWriteToken: partWriteToken,
2275
- encryption: encryption
2124
+ chunk = data.slice(i, i + chunkSize);
2125
+ _context24.next = 13;
2126
+ return _regeneratorRuntime.awrap(this.UploadPartChunk({
2127
+ libraryId: libraryId,
2128
+ objectId: objectId,
2129
+ writeToken: writeToken,
2130
+ partWriteToken: partWriteToken,
2131
+ chunk: chunk,
2132
+ encryption: encryption
2133
+ }));
2134
+
2135
+ case 13:
2136
+ if (callback) {
2137
+ callback({
2138
+ bytesFinished: Math.min(i + chunkSize, size),
2139
+ bytesTotal: size
2276
2140
  });
2141
+ }
2277
2142
 
2278
- case 19:
2279
- return _context24.abrupt("return", _context24.sent);
2280
-
2281
- case 20:
2282
- case "end":
2283
- return _context24.stop();
2284
- }
2143
+ case 14:
2144
+ i += chunkSize;
2145
+ _context24.next = 9;
2146
+ break;
2147
+
2148
+ case 17:
2149
+ _context24.next = 19;
2150
+ return _regeneratorRuntime.awrap(this.FinalizePart({
2151
+ libraryId: libraryId,
2152
+ objectId: objectId,
2153
+ writeToken: writeToken,
2154
+ partWriteToken: partWriteToken,
2155
+ encryption: encryption
2156
+ }));
2157
+
2158
+ case 19:
2159
+ return _context24.abrupt("return", _context24.sent);
2160
+
2161
+ case 20:
2162
+ case "end":
2163
+ return _context24.stop();
2285
2164
  }
2286
- }, _callee24, this);
2287
- }));
2288
-
2289
- return function (_x25) {
2290
- return _ref44.apply(this, arguments);
2291
- };
2292
- }();
2165
+ }
2166
+ }, null, this);
2167
+ };
2293
2168
  /**
2294
2169
  * Delete the specified part from a content draft
2295
2170
  *
@@ -2303,50 +2178,46 @@ exports.UploadPart = /*#__PURE__*/function () {
2303
2178
  */
2304
2179
 
2305
2180
 
2306
- exports.DeletePart = /*#__PURE__*/function () {
2307
- var _ref46 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee25(_ref45) {
2308
- var libraryId, objectId, writeToken, partHash, path;
2309
- return _regeneratorRuntime.wrap(function _callee25$(_context25) {
2310
- while (1) {
2311
- switch (_context25.prev = _context25.next) {
2312
- case 0:
2313
- libraryId = _ref45.libraryId, objectId = _ref45.objectId, writeToken = _ref45.writeToken, partHash = _ref45.partHash;
2314
- ValidateParameters({
2315
- libraryId: libraryId,
2316
- objectId: objectId
2317
- });
2318
- ValidateWriteToken(writeToken);
2319
- ValidatePartHash(partHash);
2320
- path = UrlJoin("q", writeToken, "parts", partHash);
2321
- _context25.t0 = this.HttpClient;
2322
- _context25.next = 8;
2323
- return this.authClient.AuthorizationHeader({
2324
- libraryId: libraryId,
2325
- objectId: objectId,
2326
- update: true
2327
- });
2328
-
2329
- case 8:
2330
- _context25.t1 = _context25.sent;
2331
- _context25.t2 = path;
2332
- _context25.t3 = {
2333
- headers: _context25.t1,
2334
- method: "DELETE",
2335
- path: _context25.t2,
2336
- failover: false
2337
- };
2338
- _context25.next = 13;
2339
- return _context25.t0.Request.call(_context25.t0, _context25.t3);
2340
-
2341
- case 13:
2342
- case "end":
2343
- return _context25.stop();
2344
- }
2181
+ exports.DeletePart = function _callee23(_ref23) {
2182
+ var libraryId, objectId, writeToken, partHash, path;
2183
+ return _regeneratorRuntime.async(function _callee23$(_context25) {
2184
+ while (1) {
2185
+ switch (_context25.prev = _context25.next) {
2186
+ case 0:
2187
+ libraryId = _ref23.libraryId, objectId = _ref23.objectId, writeToken = _ref23.writeToken, partHash = _ref23.partHash;
2188
+ ValidateParameters({
2189
+ libraryId: libraryId,
2190
+ objectId: objectId
2191
+ });
2192
+ ValidateWriteToken(writeToken);
2193
+ ValidatePartHash(partHash);
2194
+ path = UrlJoin("q", writeToken, "parts", partHash);
2195
+ _context25.t0 = _regeneratorRuntime;
2196
+ _context25.t1 = this.HttpClient;
2197
+ _context25.next = 9;
2198
+ return _regeneratorRuntime.awrap(this.authClient.AuthorizationHeader({
2199
+ libraryId: libraryId,
2200
+ objectId: objectId,
2201
+ update: true
2202
+ }));
2203
+
2204
+ case 9:
2205
+ _context25.t2 = _context25.sent;
2206
+ _context25.t3 = path;
2207
+ _context25.t4 = {
2208
+ headers: _context25.t2,
2209
+ method: "DELETE",
2210
+ path: _context25.t3,
2211
+ failover: false
2212
+ };
2213
+ _context25.t5 = _context25.t1.Request.call(_context25.t1, _context25.t4);
2214
+ _context25.next = 15;
2215
+ return _context25.t0.awrap.call(_context25.t0, _context25.t5);
2216
+
2217
+ case 15:
2218
+ case "end":
2219
+ return _context25.stop();
2345
2220
  }
2346
- }, _callee25, this);
2347
- }));
2348
-
2349
- return function (_x26) {
2350
- return _ref46.apply(this, arguments);
2351
- };
2352
- }();
2221
+ }
2222
+ }, null, this);
2223
+ };