@ethersphere/bee-js 3.3.2 → 3.3.4
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/LICENSE +24 -22
- package/dist/cjs/modules/debug/status.js +1 -1
- package/dist/cjs/utils/data.browser.js +6 -10
- package/dist/cjs/utils/data.js +4 -6
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-debug.js +294 -189
- package/dist/mjs/bee.js +316 -237
- package/dist/mjs/chunk/signer.js +46 -12
- package/dist/mjs/chunk/soc.js +71 -31
- package/dist/mjs/chunk/span.js +1 -1
- package/dist/mjs/feed/index.js +86 -42
- package/dist/mjs/feed/json.js +46 -10
- package/dist/mjs/index.js +2 -1
- package/dist/mjs/modules/bytes.js +61 -24
- package/dist/mjs/modules/bzz.js +96 -58
- package/dist/mjs/modules/chunk.js +51 -16
- package/dist/mjs/modules/debug/balance.js +60 -20
- package/dist/mjs/modules/debug/chequebook.js +115 -67
- package/dist/mjs/modules/debug/chunk.js +47 -11
- package/dist/mjs/modules/debug/connectivity.js +76 -32
- package/dist/mjs/modules/debug/settlements.js +46 -10
- package/dist/mjs/modules/debug/stamps.js +91 -47
- package/dist/mjs/modules/debug/states.js +48 -12
- package/dist/mjs/modules/debug/status.js +98 -50
- package/dist/mjs/modules/debug/tag.js +39 -5
- package/dist/mjs/modules/debug/transactions.js +65 -25
- package/dist/mjs/modules/feed.js +50 -16
- package/dist/mjs/modules/pinning.js +67 -27
- package/dist/mjs/modules/pss.js +44 -10
- package/dist/mjs/modules/soc.js +47 -14
- package/dist/mjs/modules/status.js +37 -3
- package/dist/mjs/modules/stewardship.js +46 -10
- package/dist/mjs/modules/tag.js +73 -31
- package/dist/mjs/utils/collection.browser.js +41 -4
- package/dist/mjs/utils/collection.js +45 -11
- package/dist/mjs/utils/collection.node.js +137 -42
- package/dist/mjs/utils/data.browser.js +88 -53
- package/dist/mjs/utils/data.js +57 -22
- package/dist/mjs/utils/error.js +0 -9
- package/dist/mjs/utils/eth.js +68 -32
- package/dist/mjs/utils/file.js +42 -8
- package/dist/mjs/utils/headers.js +4 -4
- package/dist/mjs/utils/http.js +110 -64
- package/dist/mjs/utils/merge.js +2 -2
- package/dist/mjs/utils/stream.js +0 -4
- package/dist/mjs/utils/type.js +6 -6
- package/dist/types/modules/debug/status.d.ts +1 -1
- package/dist/types/types/debug.d.ts +19 -0
- package/dist/types/utils/data.browser.d.ts +0 -1
- package/dist/types/utils/data.d.ts +2 -2
- package/package.json +14 -13
|
@@ -1,73 +1,108 @@
|
|
|
1
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) {
|
|
3
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
+
resolve(value);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) {
|
|
10
|
+
try {
|
|
11
|
+
step(generator.next(value));
|
|
12
|
+
} catch (e) {
|
|
13
|
+
reject(e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function rejected(value) {
|
|
18
|
+
try {
|
|
19
|
+
step(generator["throw"](value));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
reject(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function step(result) {
|
|
26
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
1
33
|
import { isNodeReadable, isReadableStream } from "./stream.js";
|
|
2
|
-
import Blob from 'cross-blob';
|
|
3
34
|
/**
|
|
4
35
|
* Validates input and converts to Uint8Array
|
|
5
36
|
*
|
|
6
37
|
* @param data any string, ArrayBuffer or Uint8Array
|
|
7
38
|
*/
|
|
8
39
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
15
|
-
return new Blob([data], {
|
|
16
|
-
type: 'application/octet-stream'
|
|
40
|
+
export function prepareData(data) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
if (typeof data === 'string') return new Blob([data], {
|
|
43
|
+
type: 'text/plain'
|
|
17
44
|
});
|
|
18
|
-
}
|
|
19
45
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// buffer the data before sending the requests.
|
|
46
|
+
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
47
|
+
return new Blob([data], {
|
|
48
|
+
type: 'application/octet-stream'
|
|
49
|
+
});
|
|
50
|
+
}
|
|
26
51
|
|
|
52
|
+
if (data instanceof Blob) {
|
|
53
|
+
return data;
|
|
54
|
+
} // Currently it is not possible to stream requests from browsers
|
|
55
|
+
// there are already first experiments on this field (Chromium)
|
|
56
|
+
// but till it is fully implemented across browsers-land we have to
|
|
57
|
+
// buffer the data before sending the requests.
|
|
27
58
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
59
|
+
|
|
60
|
+
if (isNodeReadable(data)) {
|
|
61
|
+
return new Promise(resolve => {
|
|
62
|
+
const buffers = [];
|
|
63
|
+
data.on('data', d => {
|
|
64
|
+
buffers.push(d);
|
|
65
|
+
});
|
|
66
|
+
data.on('end', () => {
|
|
67
|
+
resolve(new Blob(buffers, {
|
|
68
|
+
type: 'application/octet-stream'
|
|
69
|
+
}));
|
|
70
|
+
});
|
|
38
71
|
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
72
|
+
}
|
|
41
73
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
74
|
+
if (isReadableStream(data)) {
|
|
75
|
+
return new Promise(resolve => __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const reader = data.getReader();
|
|
77
|
+
const buffers = [];
|
|
78
|
+
let done, value;
|
|
47
79
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
80
|
+
do {
|
|
81
|
+
;
|
|
82
|
+
({
|
|
83
|
+
done,
|
|
84
|
+
value
|
|
85
|
+
} = yield reader.read());
|
|
54
86
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
87
|
+
if (!done) {
|
|
88
|
+
buffers.push(value);
|
|
89
|
+
}
|
|
90
|
+
} while (!done);
|
|
59
91
|
|
|
60
|
-
|
|
61
|
-
|
|
92
|
+
resolve(new Blob(buffers, {
|
|
93
|
+
type: 'application/octet-stream'
|
|
94
|
+
}));
|
|
62
95
|
}));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
96
|
+
}
|
|
65
97
|
|
|
66
|
-
|
|
98
|
+
throw new TypeError('unknown data type');
|
|
99
|
+
});
|
|
67
100
|
}
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
101
|
+
export function prepareWebsocketData(data) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
if (typeof data === 'string') return new TextEncoder().encode(data);
|
|
104
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
105
|
+
if (data instanceof Blob) return new Uint8Array(yield new Response(data).arrayBuffer());
|
|
106
|
+
throw new TypeError('unknown websocket data type');
|
|
107
|
+
});
|
|
73
108
|
}
|
package/dist/mjs/utils/data.js
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) {
|
|
3
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
+
resolve(value);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) {
|
|
10
|
+
try {
|
|
11
|
+
step(generator.next(value));
|
|
12
|
+
} catch (e) {
|
|
13
|
+
reject(e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function rejected(value) {
|
|
18
|
+
try {
|
|
19
|
+
step(generator["throw"](value));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
reject(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function step(result) {
|
|
26
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
import BlobPolyfill from 'fetch-blob';
|
|
2
34
|
import { isNodeReadable, isReadableStream, readableWebToNode } from "./stream.js";
|
|
3
35
|
/**
|
|
4
36
|
* Prepare data for valid input for node-fetch.
|
|
@@ -9,35 +41,38 @@ import { isNodeReadable, isReadableStream, readableWebToNode } from "./stream.js
|
|
|
9
41
|
* @param data any string, ArrayBuffer, Uint8Array or Readable
|
|
10
42
|
*/
|
|
11
43
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
18
|
-
return new Blob([data], {
|
|
19
|
-
type: 'application/octet-stream'
|
|
44
|
+
export function prepareData(data) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
if (typeof data === 'string') return new BlobPolyfill([data], {
|
|
47
|
+
type: 'text/plain'
|
|
20
48
|
});
|
|
21
|
-
}
|
|
22
49
|
|
|
23
|
-
|
|
50
|
+
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
51
|
+
return new BlobPolyfill([data], {
|
|
52
|
+
type: 'application/octet-stream'
|
|
53
|
+
});
|
|
54
|
+
}
|
|
24
55
|
|
|
25
|
-
|
|
26
|
-
return readableWebToNode(data);
|
|
27
|
-
}
|
|
56
|
+
if (data instanceof BlobPolyfill || isNodeReadable(data)) return data;
|
|
28
57
|
|
|
29
|
-
|
|
58
|
+
if (isReadableStream(data)) {
|
|
59
|
+
return readableWebToNode(data);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
throw new TypeError('unknown data type');
|
|
63
|
+
});
|
|
30
64
|
}
|
|
31
65
|
|
|
32
66
|
function isBufferArray(buffer) {
|
|
33
67
|
return Array.isArray(buffer) && buffer.length > 0 && buffer.every(data => data instanceof Buffer);
|
|
34
68
|
}
|
|
35
69
|
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
70
|
+
export function prepareWebsocketData(data) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
if (typeof data === 'string') return new TextEncoder().encode(data);
|
|
73
|
+
if (data instanceof Buffer) return new Uint8Array(data);
|
|
74
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
75
|
+
if (isBufferArray(data)) return new Uint8Array(Buffer.concat(data));
|
|
76
|
+
throw new TypeError('unknown websocket data type');
|
|
77
|
+
});
|
|
43
78
|
}
|
package/dist/mjs/utils/error.js
CHANGED
|
@@ -5,8 +5,6 @@ export class BeeError extends Error {
|
|
|
5
5
|
|
|
6
6
|
}
|
|
7
7
|
export class BeeArgumentError extends BeeError {
|
|
8
|
-
value;
|
|
9
|
-
|
|
10
8
|
constructor(message, value) {
|
|
11
9
|
super(message);
|
|
12
10
|
this.value = value;
|
|
@@ -14,12 +12,10 @@ export class BeeArgumentError extends BeeError {
|
|
|
14
12
|
|
|
15
13
|
}
|
|
16
14
|
export class BeeRequestError extends BeeError {
|
|
17
|
-
requestOptions;
|
|
18
15
|
/**
|
|
19
16
|
* @param message
|
|
20
17
|
* @param requestOptions KyOptions that were used to assemble the request. THIS MIGHT NOT BE COMPLETE! If custom Ky instance was used that has set defaults then these defaults are not visible in this object!
|
|
21
18
|
*/
|
|
22
|
-
|
|
23
19
|
constructor(message, requestOptions) {
|
|
24
20
|
super(message);
|
|
25
21
|
this.requestOptions = requestOptions;
|
|
@@ -27,10 +23,6 @@ export class BeeRequestError extends BeeError {
|
|
|
27
23
|
|
|
28
24
|
}
|
|
29
25
|
export class BeeResponseError extends BeeError {
|
|
30
|
-
status;
|
|
31
|
-
response;
|
|
32
|
-
responseBody;
|
|
33
|
-
requestOptions;
|
|
34
26
|
/**
|
|
35
27
|
* @param status HTTP status code number
|
|
36
28
|
* @param response Response returned from the server
|
|
@@ -38,7 +30,6 @@ export class BeeResponseError extends BeeError {
|
|
|
38
30
|
* @param requestOptions KyOptions that were used to assemble the request. THIS MIGHT NOT BE COMPLETE! If custom Ky instance was used that has set defaults then these defaults are not visible in this object!
|
|
39
31
|
* @param message
|
|
40
32
|
*/
|
|
41
|
-
|
|
42
33
|
constructor(status, response, responseBody, requestOptions, message) {
|
|
43
34
|
super(message);
|
|
44
35
|
this.status = status;
|
package/dist/mjs/utils/eth.js
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) {
|
|
3
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
+
resolve(value);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) {
|
|
10
|
+
try {
|
|
11
|
+
step(generator.next(value));
|
|
12
|
+
} catch (e) {
|
|
13
|
+
reject(e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function rejected(value) {
|
|
18
|
+
try {
|
|
19
|
+
step(generator["throw"](value));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
reject(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function step(result) {
|
|
26
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
}; // For ESM compatibility
|
|
32
|
+
|
|
33
|
+
|
|
2
34
|
import pkg from 'js-sha3';
|
|
3
35
|
const {
|
|
4
36
|
keccak256,
|
|
@@ -98,6 +130,8 @@ export function isHexEthAddress(address) {
|
|
|
98
130
|
*/
|
|
99
131
|
|
|
100
132
|
export function toLittleEndian(bigEndian, pad = 2) {
|
|
133
|
+
var _a;
|
|
134
|
+
|
|
101
135
|
if (!(Number.isInteger(pad) && pad >= 2 && pad % 2 === 0)) {
|
|
102
136
|
throw new TypeError('minimal padding for conversion needs to be positive even integer');
|
|
103
137
|
}
|
|
@@ -108,7 +142,7 @@ export function toLittleEndian(bigEndian, pad = 2) {
|
|
|
108
142
|
|
|
109
143
|
if (hexRep.length % 2 !== 0) hexRep = hexRep.padStart(hexRep.length + 1, '0'); // Match all two pairs in the hexstring, reverse the pairs and join it again
|
|
110
144
|
|
|
111
|
-
const littleEndian = hexRep.match(/../g)
|
|
145
|
+
const littleEndian = (_a = hexRep.match(/../g)) === null || _a === void 0 ? void 0 : _a.reverse().join('');
|
|
112
146
|
if (littleEndian) return littleEndian;
|
|
113
147
|
throw new Error('failed to convert');
|
|
114
148
|
}
|
|
@@ -162,38 +196,40 @@ export function ethToSwarmAddress(ethAddress, networkId = 1) {
|
|
|
162
196
|
* @param ethAddress Optional address of the account which the data should be signed with. If not specified `eth_requestAccounts` request is used to get the account address.
|
|
163
197
|
*/
|
|
164
198
|
|
|
165
|
-
export
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (typeof provider !== 'object' || provider === null) {
|
|
169
|
-
throw new TypeError('We need JsonRPC provider object!');
|
|
170
|
-
}
|
|
199
|
+
export function makeEthereumWalletSigner(provider, ethAddress) {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
let executorFnc;
|
|
171
202
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
executorFnc = provider.sendAsync;
|
|
176
|
-
} else {
|
|
177
|
-
throw new Error('Incompatible interface of given provider!');
|
|
178
|
-
}
|
|
203
|
+
if (typeof provider !== 'object' || provider === null) {
|
|
204
|
+
throw new TypeError('We need JsonRPC provider object!');
|
|
205
|
+
}
|
|
179
206
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
207
|
+
if (provider.request) {
|
|
208
|
+
executorFnc = provider.request;
|
|
209
|
+
} else if (provider.sendAsync) {
|
|
210
|
+
executorFnc = provider.sendAsync;
|
|
211
|
+
} else {
|
|
212
|
+
throw new Error('Incompatible interface of given provider!');
|
|
213
|
+
}
|
|
185
214
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
sign: async data => {
|
|
191
|
-
const result = await executorFnc({
|
|
192
|
-
jsonrpc: '2.0',
|
|
193
|
-
method: 'personal_sign',
|
|
194
|
-
params: ['0x' + data.hex(), '0x' + hexEthAddress]
|
|
195
|
-
});
|
|
196
|
-
return result;
|
|
215
|
+
if (!ethAddress) {
|
|
216
|
+
ethAddress = (yield executorFnc({
|
|
217
|
+
method: 'eth_requestAccounts'
|
|
218
|
+
}))[0];
|
|
197
219
|
}
|
|
198
|
-
|
|
220
|
+
|
|
221
|
+
const bytesEthAddress = makeEthAddress(ethAddress);
|
|
222
|
+
const hexEthAddress = makeHexEthAddress(ethAddress);
|
|
223
|
+
return {
|
|
224
|
+
address: bytesEthAddress,
|
|
225
|
+
sign: data => __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
const result = yield executorFnc({
|
|
227
|
+
jsonrpc: '2.0',
|
|
228
|
+
method: 'personal_sign',
|
|
229
|
+
params: ['0x' + data.hex(), '0x' + hexEthAddress]
|
|
230
|
+
});
|
|
231
|
+
return result;
|
|
232
|
+
})
|
|
233
|
+
};
|
|
234
|
+
});
|
|
199
235
|
}
|
package/dist/mjs/utils/file.js
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
3
3
|
*
|
|
4
4
|
* https://developer.mozilla.org/en-US/docs/Web/API/File
|
|
5
5
|
*/
|
|
6
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) {
|
|
8
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
9
|
+
resolve(value);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) {
|
|
15
|
+
try {
|
|
16
|
+
step(generator.next(value));
|
|
17
|
+
} catch (e) {
|
|
18
|
+
reject(e);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function rejected(value) {
|
|
23
|
+
try {
|
|
24
|
+
step(generator["throw"](value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function step(result) {
|
|
31
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
6
38
|
export function isFile(file) {
|
|
7
39
|
// browser
|
|
8
40
|
if (typeof File === 'function') {
|
|
@@ -20,17 +52,19 @@ export function isFile(file) {
|
|
|
20
52
|
* @param file A File object
|
|
21
53
|
*/
|
|
22
54
|
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
55
|
+
export function fileArrayBuffer(file) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
if (file.arrayBuffer) {
|
|
58
|
+
return file.arrayBuffer();
|
|
59
|
+
} // workaround for Safari where arrayBuffer is not supported on Files
|
|
27
60
|
|
|
28
61
|
|
|
29
|
-
|
|
30
|
-
|
|
62
|
+
return new Promise(resolve => {
|
|
63
|
+
const fr = new FileReader();
|
|
31
64
|
|
|
32
|
-
|
|
65
|
+
fr.onload = () => resolve(fr.result);
|
|
33
66
|
|
|
34
|
-
|
|
67
|
+
fr.readAsArrayBuffer(file);
|
|
68
|
+
});
|
|
35
69
|
});
|
|
36
70
|
}
|
|
@@ -50,9 +50,9 @@ export function extractUploadHeaders(postageBatchId, options) {
|
|
|
50
50
|
const headers = {
|
|
51
51
|
'swarm-postage-batch-id': postageBatchId
|
|
52
52
|
};
|
|
53
|
-
if (options
|
|
54
|
-
if (options
|
|
55
|
-
if (options
|
|
56
|
-
if (typeof options
|
|
53
|
+
if (options === null || options === void 0 ? void 0 : options.pin) headers['swarm-pin'] = String(options.pin);
|
|
54
|
+
if (options === null || options === void 0 ? void 0 : options.encrypt) headers['swarm-encrypt'] = String(options.encrypt);
|
|
55
|
+
if (options === null || options === void 0 ? void 0 : options.tag) headers['swarm-tag'] = String(options.tag);
|
|
56
|
+
if (typeof (options === null || options === void 0 ? void 0 : options.deferred) === 'boolean') headers['swarm-deferred-upload'] = options.deferred.toString();
|
|
57
57
|
return headers;
|
|
58
58
|
}
|