@super-protocol/sdk-js 0.15.0 → 0.15.2-beta.0
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.
- package/build/TIIGenerator.js +129 -239
- package/build/connectors/BaseConnector.js +17 -47
- package/build/connectors/BlockchainConnector.js +222 -348
- package/build/connectors/BlockchainEventsListener.js +38 -92
- package/build/contracts/app.json +466 -35
- package/build/crypto/Crypto.js +63 -135
- package/build/crypto/index.js +1 -1
- package/build/crypto/nodejs/AES.js +62 -119
- package/build/crypto/nodejs/ARIA.js +61 -118
- package/build/crypto/nodejs/ECIES.js +51 -87
- package/build/crypto/nodejs/NativeCrypto.js +64 -118
- package/build/crypto/nodejs/RSA-Hybrid.js +54 -113
- package/build/index.d.ts +5 -0
- package/build/index.js +14 -2
- package/build/logger.d.ts +3 -1
- package/build/logger.js +2 -2
- package/build/models/EtlModel.js +65 -114
- package/build/models/Offer.js +227 -462
- package/build/models/Order.d.ts +4 -0
- package/build/models/Order.js +326 -559
- package/build/models/Provider.d.ts +2 -0
- package/build/models/Provider.js +74 -153
- package/build/models/TCB.js +67 -171
- package/build/models/TeeOffer.d.ts +1 -0
- package/build/models/TeeOffer.js +389 -731
- package/build/proto/Compression.js +20 -21
- package/build/proto/TRI.js +46 -50
- package/build/proto/TeeProperties.js +60 -66
- package/build/providers/storage/ChunksDownloadDecorator.d.ts +1 -1
- package/build/providers/storage/ChunksDownloadDecorator.js +125 -235
- package/build/providers/storage/IStorageProvider.d.ts +1 -1
- package/build/providers/storage/S3StorageProvider.js +173 -298
- package/build/providers/storage/StorageAdapter.d.ts +60 -0
- package/build/providers/storage/StorageAdapter.js +322 -0
- package/build/providers/storage/StorageContentWriter.d.ts +46 -0
- package/build/providers/storage/StorageContentWriter.js +182 -0
- package/build/providers/storage/StorageKeyValueAdapter.d.ts +23 -0
- package/build/providers/storage/StorageKeyValueAdapter.js +157 -0
- package/build/providers/storage/StorageMetadataReader.d.ts +20 -0
- package/build/providers/storage/StorageMetadataReader.js +67 -0
- package/build/providers/storage/StorjAdapter.d.ts +19 -0
- package/build/providers/storage/StorjAdapter.js +73 -0
- package/build/providers/storage/StorjStorageProvider.js +138 -315
- package/build/providers/storage/getStorageProvider.js +7 -7
- package/build/providers/storage/types.d.ts +7 -0
- package/build/providers/storage/types.js +2 -0
- package/build/staticModels/ActiveOffers.js +32 -100
- package/build/staticModels/ActiveOrders.js +42 -120
- package/build/staticModels/BaseStaticModel.js +7 -10
- package/build/staticModels/Consensus.d.ts +4 -1
- package/build/staticModels/Consensus.js +164 -220
- package/build/staticModels/Deposits.js +109 -201
- package/build/staticModels/Marks.js +21 -82
- package/build/staticModels/ModelPackager.js +34 -84
- package/build/staticModels/Offers.js +140 -266
- package/build/staticModels/Orders.d.ts +1 -0
- package/build/staticModels/Orders.js +286 -429
- package/build/staticModels/ProviderRegistry.js +114 -225
- package/build/staticModels/Superpro.js +17 -63
- package/build/staticModels/SuperproToken.js +90 -169
- package/build/staticModels/TeeOffers.js +220 -416
- package/build/store.js +2 -2
- package/build/types/HardwareInfo.js +2 -2
- package/build/types/Order.js +4 -4
- package/build/types/Provider.js +1 -1
- package/build/types/TeeOfferInfo.js +1 -1
- package/build/types/TeeOfferOption.js +2 -2
- package/build/types/TeeOfferSlot.js +2 -2
- package/build/types/ValueOfferSlot.js +3 -3
- package/build/utils/Monitoring.js +24 -28
- package/build/utils/NonceTracker.js +56 -121
- package/build/utils/PubSub.d.ts +9 -0
- package/build/utils/PubSub.js +36 -0
- package/build/utils/TxManager.js +121 -215
- package/build/utils/compressors/GzipCompressor.js +13 -50
- package/build/utils/compressors/UncompressedCompressor.js +10 -13
- package/build/utils/helpers/tryWithInterval.js +34 -78
- package/build/utils/resourceLoaders/BaseResourceLoader.js +26 -78
- package/build/utils/resourceLoaders/StorageProviderLoader.js +33 -97
- package/build/utils/resourceLoaders/UrlResourceLoader.js +29 -93
- package/build/utils/resourceLoaders/getResourceLoader.js +6 -6
- package/build/utils.js +60 -105
- package/package.json +4 -1
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -23,33 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
9
|
});
|
|
25
10
|
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
11
|
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
54
12
|
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
55
13
|
var m = o[Symbol.asyncIterator], i;
|
|
@@ -59,228 +17,160 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
59
17
|
};
|
|
60
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
19
|
exports.DownloadDecorator = exports.createDownloadChunkMethodWithRetry = exports.downloadChunkMethod = void 0;
|
|
62
|
-
|
|
63
|
-
function generateChunks(dataSize, chunkSize, startOffset) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
length: chunkSize > dataSize - offset ? Number(dataSize - offset) : chunkSize,
|
|
77
|
-
dataSize: dataSize,
|
|
78
|
-
chunk: chunk++,
|
|
79
|
-
chunksCount: Math.ceil(Number(dataSize / BigInt(chunkSize))),
|
|
80
|
-
}];
|
|
81
|
-
case 2:
|
|
82
|
-
_a.sent();
|
|
83
|
-
offset += BigInt(chunkSize);
|
|
84
|
-
return [3 /*break*/, 1];
|
|
85
|
-
case 3: return [2 /*return*/];
|
|
86
|
-
}
|
|
87
|
-
});
|
|
20
|
+
const stream_1 = require("stream");
|
|
21
|
+
function* generateChunks(dataSize, chunkSize, startOffset = BigInt(0)) {
|
|
22
|
+
let chunk = 0;
|
|
23
|
+
let offset = startOffset;
|
|
24
|
+
while (dataSize > offset) {
|
|
25
|
+
yield {
|
|
26
|
+
offset,
|
|
27
|
+
length: chunkSize > dataSize - offset ? Number(dataSize - offset) : chunkSize,
|
|
28
|
+
dataSize,
|
|
29
|
+
chunk: chunk++,
|
|
30
|
+
chunksCount: Math.ceil(Number(dataSize / BigInt(chunkSize))),
|
|
31
|
+
};
|
|
32
|
+
offset += BigInt(chunkSize);
|
|
33
|
+
}
|
|
88
34
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
var _this = _super.call(this, {
|
|
35
|
+
class ChunkedReadableTransform extends stream_1.Transform {
|
|
36
|
+
constructor(downloadChunk, params) {
|
|
37
|
+
super({
|
|
93
38
|
objectMode: true,
|
|
94
39
|
highWaterMark: params.concurrency,
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
return _this;
|
|
40
|
+
});
|
|
41
|
+
this.downloadChunk = downloadChunk;
|
|
98
42
|
}
|
|
99
|
-
|
|
100
|
-
|
|
43
|
+
_transform(chunk, encoding, callback) {
|
|
44
|
+
const resultPromise = this.downloadChunk(chunk);
|
|
101
45
|
callback(null, {
|
|
102
|
-
resultPromise
|
|
103
|
-
chunk
|
|
46
|
+
resultPromise,
|
|
47
|
+
chunk,
|
|
104
48
|
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
function ChainedChunksReadableTransform(progressListener) {
|
|
111
|
-
var _this = _super.call(this, {
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
class ChainedChunksReadableTransform extends stream_1.Transform {
|
|
52
|
+
constructor(progressListener) {
|
|
53
|
+
super({
|
|
112
54
|
objectMode: true,
|
|
113
55
|
highWaterMark: 1,
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
return _this;
|
|
56
|
+
});
|
|
57
|
+
this.progressListener = progressListener;
|
|
117
58
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
obj.resultPromise.then(function (data) {
|
|
59
|
+
_transform(obj, encoding, callback) {
|
|
60
|
+
obj.resultPromise.then((data) => {
|
|
121
61
|
callback(null, data);
|
|
122
|
-
if (
|
|
123
|
-
|
|
62
|
+
if (this.progressListener) {
|
|
63
|
+
this.progressListener(Number(obj.chunk.dataSize), Number(obj.chunk.offset) + obj.chunk.length);
|
|
124
64
|
}
|
|
125
|
-
},
|
|
65
|
+
}, (err) => {
|
|
126
66
|
callback(err);
|
|
127
67
|
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
var
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
_a = true, dataStream_1 = __asyncValues(dataStream);
|
|
149
|
-
_e.label = 3;
|
|
150
|
-
case 3: return [4 /*yield*/, dataStream_1.next()];
|
|
151
|
-
case 4:
|
|
152
|
-
if (!(dataStream_1_1 = _e.sent(), _b = dataStream_1_1.done, !_b)) return [3 /*break*/, 6];
|
|
153
|
-
_d = dataStream_1_1.value;
|
|
154
|
-
_a = false;
|
|
155
|
-
try {
|
|
156
|
-
data = _d;
|
|
157
|
-
data.copy(buffer, position);
|
|
158
|
-
position += data.length;
|
|
159
|
-
if (position > chunk.length) {
|
|
160
|
-
throw new Error("Chunk buffer is overflow, read data is more than requested for chunk");
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
finally {
|
|
164
|
-
_a = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const downloadChunkMethod = (provider, objectPath, chunk) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
var _a, e_1, _b, _c;
|
|
72
|
+
let position = 0;
|
|
73
|
+
const buffer = Buffer.alloc(chunk.length);
|
|
74
|
+
const dataStream = yield provider.downloadFile(objectPath, {
|
|
75
|
+
offset: Number(chunk.offset),
|
|
76
|
+
length: chunk.length,
|
|
77
|
+
});
|
|
78
|
+
try {
|
|
79
|
+
for (var _d = true, dataStream_1 = __asyncValues(dataStream), dataStream_1_1; dataStream_1_1 = yield dataStream_1.next(), _a = dataStream_1_1.done, !_a;) {
|
|
80
|
+
_c = dataStream_1_1.value;
|
|
81
|
+
_d = false;
|
|
82
|
+
try {
|
|
83
|
+
const data = _c;
|
|
84
|
+
data.copy(buffer, position);
|
|
85
|
+
position += data.length;
|
|
86
|
+
if (position > chunk.length) {
|
|
87
|
+
throw new Error("Chunk buffer is overflow, read data is more than requested for chunk");
|
|
165
88
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
e_1_1 = _e.sent();
|
|
171
|
-
e_1 = { error: e_1_1 };
|
|
172
|
-
return [3 /*break*/, 13];
|
|
173
|
-
case 8:
|
|
174
|
-
_e.trys.push([8, , 11, 12]);
|
|
175
|
-
if (!(!_a && !_b && (_c = dataStream_1.return))) return [3 /*break*/, 10];
|
|
176
|
-
return [4 /*yield*/, _c.call(dataStream_1)];
|
|
177
|
-
case 9:
|
|
178
|
-
_e.sent();
|
|
179
|
-
_e.label = 10;
|
|
180
|
-
case 10: return [3 /*break*/, 12];
|
|
181
|
-
case 11:
|
|
182
|
-
if (e_1) throw e_1.error;
|
|
183
|
-
return [7 /*endfinally*/];
|
|
184
|
-
case 12: return [7 /*endfinally*/];
|
|
185
|
-
case 13: return [2 /*return*/, buffer];
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
_d = true;
|
|
92
|
+
}
|
|
186
93
|
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
94
|
+
}
|
|
95
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
96
|
+
finally {
|
|
97
|
+
try {
|
|
98
|
+
if (!_d && !_a && (_b = dataStream_1.return)) yield _b.call(dataStream_1);
|
|
99
|
+
}
|
|
100
|
+
finally { if (e_1) throw e_1.error; }
|
|
101
|
+
}
|
|
102
|
+
return buffer;
|
|
103
|
+
});
|
|
189
104
|
exports.downloadChunkMethod = downloadChunkMethod;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
retryCount = retryMaxCount;
|
|
199
|
-
_a.label = 1;
|
|
200
|
-
case 1:
|
|
201
|
-
if (!(retryCount > 0)) return [3 /*break*/, 8];
|
|
202
|
-
_a.label = 2;
|
|
203
|
-
case 2:
|
|
204
|
-
_a.trys.push([2, 4, , 5]);
|
|
205
|
-
return [4 /*yield*/, downloadChunkMethod(provider, objectPath, chunk)];
|
|
206
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
207
|
-
case 4:
|
|
208
|
-
error_1 = _a.sent();
|
|
209
|
-
return [3 /*break*/, 5];
|
|
210
|
-
case 5:
|
|
211
|
-
retryCount--;
|
|
212
|
-
if (onRetry) {
|
|
213
|
-
onRetry(null, chunk, retryCount);
|
|
214
|
-
}
|
|
215
|
-
if (!(retryCount !== 0)) return [3 /*break*/, 7];
|
|
216
|
-
return [4 /*yield*/, new Promise(function (resolve, reject) { return setTimeout(resolve, retryWaitTime()); })];
|
|
217
|
-
case 6:
|
|
218
|
-
_a.sent();
|
|
219
|
-
_a.label = 7;
|
|
220
|
-
case 7: return [3 /*break*/, 1];
|
|
221
|
-
case 8: throw new Error("Max retry attempts was reached for object path ".concat(objectPath, ", offset ").concat(chunk.offset, ", length ").concat(chunk.length
|
|
222
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
223
|
-
));
|
|
105
|
+
const createDownloadChunkMethodWithRetry = (downloadChunkMethod, { retryMaxCount = 3, retryWaitTimeFactory = () => () => 1000, onRetry } = {}) => {
|
|
106
|
+
return (provider, objectPath, chunk) => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
|
+
const retryWaitTime = retryWaitTimeFactory();
|
|
108
|
+
//let lastError: unknown = null;
|
|
109
|
+
let retryCount = retryMaxCount;
|
|
110
|
+
while (retryCount > 0) {
|
|
111
|
+
try {
|
|
112
|
+
return yield downloadChunkMethod(provider, objectPath, chunk);
|
|
224
113
|
}
|
|
225
|
-
|
|
226
|
-
|
|
114
|
+
catch (error) {
|
|
115
|
+
//lastError = error;
|
|
116
|
+
}
|
|
117
|
+
retryCount--;
|
|
118
|
+
if (onRetry) {
|
|
119
|
+
onRetry(null, chunk, retryCount);
|
|
120
|
+
}
|
|
121
|
+
if (retryCount !== 0) {
|
|
122
|
+
yield new Promise((resolve, reject) => setTimeout(resolve, retryWaitTime()));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
throw new Error(`Max retry attempts was reached for object path ${objectPath}, offset ${chunk.offset}, length ${chunk.length
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
127
|
+
}`);
|
|
128
|
+
});
|
|
227
129
|
};
|
|
228
130
|
exports.createDownloadChunkMethodWithRetry = createDownloadChunkMethodWithRetry;
|
|
229
|
-
|
|
230
|
-
|
|
131
|
+
class DownloadDecorator {
|
|
132
|
+
constructor(provider, chunkDownloaderMethod, options) {
|
|
231
133
|
this.provider = provider;
|
|
232
134
|
this.chunkDownloaderMethod = chunkDownloaderMethod;
|
|
233
135
|
this.options = options;
|
|
234
136
|
}
|
|
235
|
-
|
|
137
|
+
uploadFile(inputStream, remotePath, contentLength, progressListener) {
|
|
236
138
|
return this.provider.uploadFile(inputStream, remotePath, contentLength, progressListener);
|
|
237
|
-
}
|
|
238
|
-
|
|
139
|
+
}
|
|
140
|
+
downloadFile(remotePath, config, progressListener) {
|
|
239
141
|
var _a;
|
|
240
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
case 1:
|
|
252
|
-
objectSize = _b.sent();
|
|
253
|
-
chunksStream = stream_1.Readable.from(generateChunks(BigInt(objectSize), this.options.chunkSize, offset));
|
|
254
|
-
downloadStream = new ChunkedReadableTransform(function (chunk) { return __awaiter(_this, void 0, void 0, function () {
|
|
255
|
-
return __generator(this, function (_a) {
|
|
256
|
-
return [2 /*return*/, this.chunkDownloaderMethod(this.provider, remotePath, chunk)];
|
|
257
|
-
});
|
|
258
|
-
}); }, {
|
|
259
|
-
concurrency: this.options.concurrency,
|
|
260
|
-
});
|
|
261
|
-
chainedStream = new ChainedChunksReadableTransform(progressListener);
|
|
262
|
-
return [2 /*return*/, chunksStream
|
|
263
|
-
.pipe(downloadStream)
|
|
264
|
-
.on("error", function (error) {
|
|
265
|
-
chainedStream.emit("error", error);
|
|
266
|
-
})
|
|
267
|
-
.pipe(chainedStream)];
|
|
268
|
-
}
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
if (config === null || config === void 0 ? void 0 : config.length) {
|
|
144
|
+
return this.provider.downloadFile(remotePath, config, progressListener);
|
|
145
|
+
}
|
|
146
|
+
const offset = BigInt((_a = this.options.offset) !== null && _a !== void 0 ? _a : 0);
|
|
147
|
+
const objectSize = yield this.provider.getObjectSize(remotePath);
|
|
148
|
+
const chunksStream = stream_1.Readable.from(generateChunks(BigInt(objectSize), this.options.chunkSize, offset));
|
|
149
|
+
const downloadStream = new ChunkedReadableTransform((chunk) => __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
return this.chunkDownloaderMethod(this.provider, remotePath, chunk);
|
|
151
|
+
}), {
|
|
152
|
+
concurrency: this.options.concurrency,
|
|
269
153
|
});
|
|
154
|
+
const chainedStream = new ChainedChunksReadableTransform(progressListener);
|
|
155
|
+
return chunksStream
|
|
156
|
+
.pipe(downloadStream)
|
|
157
|
+
.on("error", (error) => {
|
|
158
|
+
chainedStream.emit("error", error);
|
|
159
|
+
})
|
|
160
|
+
.pipe(chainedStream);
|
|
270
161
|
});
|
|
271
|
-
}
|
|
272
|
-
|
|
162
|
+
}
|
|
163
|
+
deleteObject(remotePath) {
|
|
273
164
|
return this.provider.deleteObject(remotePath);
|
|
274
|
-
}
|
|
275
|
-
|
|
165
|
+
}
|
|
166
|
+
listObjects(remotePath) {
|
|
276
167
|
return this.provider.listObjects(remotePath);
|
|
277
|
-
}
|
|
278
|
-
|
|
168
|
+
}
|
|
169
|
+
getObjectSize(remotePath) {
|
|
279
170
|
return this.provider.getObjectSize(remotePath);
|
|
280
|
-
}
|
|
281
|
-
|
|
171
|
+
}
|
|
172
|
+
getLastModified(remotePath) {
|
|
282
173
|
return this.provider.getLastModified(remotePath);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
}());
|
|
174
|
+
}
|
|
175
|
+
}
|
|
286
176
|
exports.DownloadDecorator = DownloadDecorator;
|
|
@@ -11,5 +11,5 @@ export default interface IStorageProvider {
|
|
|
11
11
|
deleteObject(remotePath: string): Promise<void>;
|
|
12
12
|
listObjects(remotePath: string): Promise<StorageObject[]>;
|
|
13
13
|
getObjectSize(remotePath: string): Promise<number>;
|
|
14
|
-
getLastModified(remotePath: string): Promise<Date>;
|
|
14
|
+
getLastModified(remotePath: string): Promise<Date | null>;
|
|
15
15
|
}
|