@ethersphere/bee-js 6.9.0 → 7.0.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/README.md +107 -65
- package/dist/cjs/bee.js +533 -6
- package/dist/cjs/chunk/cac.js +3 -3
- package/dist/cjs/chunk/soc.js +5 -5
- package/dist/cjs/chunk/span.js +2 -6
- package/dist/cjs/feed/identifier.js +2 -2
- package/dist/cjs/feed/index.js +7 -8
- package/dist/cjs/feed/retrievable.js +2 -2
- package/dist/cjs/index.js +1 -3
- package/dist/cjs/modules/bytes.js +3 -3
- package/dist/cjs/modules/bzz.js +9 -20
- package/dist/cjs/modules/chunk.js +2 -2
- package/dist/cjs/modules/debug/balance.js +4 -4
- package/dist/cjs/modules/debug/chequebook.js +8 -8
- package/dist/cjs/modules/debug/chunk.js +2 -19
- package/dist/cjs/modules/debug/settlements.js +2 -2
- package/dist/cjs/modules/debug/stake.js +3 -3
- package/dist/cjs/modules/debug/states.js +4 -19
- package/dist/cjs/modules/debug/status.js +15 -32
- package/dist/cjs/modules/debug/tag.js +1 -1
- package/dist/cjs/modules/debug/transactions.js +4 -4
- package/dist/cjs/modules/feed.js +6 -7
- package/dist/cjs/modules/pinning.js +4 -4
- package/dist/cjs/modules/pss.js +1 -1
- package/dist/cjs/modules/soc.js +1 -1
- package/dist/cjs/modules/status.js +1 -1
- package/dist/cjs/modules/stewardship.js +1 -1
- package/dist/cjs/package.json +4 -0
- package/dist/cjs/types/index.js +5 -1
- package/dist/cjs/utils/collection.js +7 -22
- package/dist/cjs/utils/collection.node.js +2 -1
- package/dist/cjs/utils/data.browser.js +1 -49
- package/dist/cjs/utils/error.js +2 -6
- package/dist/cjs/utils/eth.js +1 -1
- package/dist/cjs/utils/expose.js +1 -8
- package/dist/cjs/utils/file.js +2 -2
- package/dist/cjs/utils/http.js +6 -25
- package/dist/cjs/utils/tar-uploader.browser.js +26 -0
- package/dist/cjs/utils/tar-uploader.js +27 -0
- package/dist/cjs/utils/tar-writer.browser.js +17 -0
- package/dist/cjs/utils/tar-writer.js +21 -0
- package/dist/cjs/utils/tar.browser.js +65 -0
- package/dist/cjs/utils/tar.js +47 -21
- package/dist/cjs/utils/type.js +7 -3
- package/dist/cjs/utils/url.js +1 -6
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +0 -42
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +533 -9
- package/dist/mjs/chunk/cac.js +4 -4
- package/dist/mjs/chunk/soc.js +6 -6
- package/dist/mjs/chunk/span.js +2 -6
- package/dist/mjs/feed/identifier.js +2 -2
- package/dist/mjs/feed/index.js +7 -11
- package/dist/mjs/feed/retrievable.js +2 -2
- package/dist/mjs/index.js +1 -2
- package/dist/mjs/modules/bytes.js +3 -3
- package/dist/mjs/modules/bzz.js +8 -20
- package/dist/mjs/modules/chunk.js +2 -2
- package/dist/mjs/modules/debug/balance.js +4 -4
- package/dist/mjs/modules/debug/chequebook.js +8 -8
- package/dist/mjs/modules/debug/chunk.js +1 -17
- package/dist/mjs/modules/debug/settlements.js +2 -2
- package/dist/mjs/modules/debug/stake.js +3 -3
- package/dist/mjs/modules/debug/states.js +4 -19
- package/dist/mjs/modules/debug/status.js +15 -34
- package/dist/mjs/modules/debug/tag.js +1 -1
- package/dist/mjs/modules/debug/transactions.js +4 -4
- package/dist/mjs/modules/feed.js +6 -7
- package/dist/mjs/modules/pinning.js +4 -4
- package/dist/mjs/modules/pss.js +1 -1
- package/dist/mjs/modules/soc.js +1 -1
- package/dist/mjs/modules/status.js +1 -1
- package/dist/mjs/modules/stewardship.js +1 -1
- package/dist/mjs/package.json +6 -2
- package/dist/mjs/types/index.js +4 -0
- package/dist/mjs/utils/collection.js +7 -22
- package/dist/mjs/utils/collection.node.js +2 -1
- package/dist/mjs/utils/data.browser.js +0 -57
- package/dist/mjs/utils/error.js +2 -6
- package/dist/mjs/utils/eth.js +1 -1
- package/dist/mjs/utils/expose.js +0 -1
- package/dist/mjs/utils/http.js +5 -2
- package/dist/mjs/utils/tar-uploader.browser.js +22 -0
- package/dist/mjs/utils/tar-uploader.js +23 -0
- package/dist/mjs/utils/tar-writer.browser.js +12 -0
- package/dist/mjs/utils/tar-writer.js +16 -0
- package/dist/mjs/utils/tar.browser.js +61 -0
- package/dist/mjs/utils/tar.js +45 -16
- package/dist/mjs/utils/type.js +4 -1
- package/dist/mjs/utils/url.js +1 -6
- package/dist/types/bee.d.ts +305 -4
- package/dist/types/chunk/soc.d.ts +2 -2
- package/dist/types/feed/identifier.d.ts +1 -1
- package/dist/types/feed/index.d.ts +1 -1
- package/dist/types/index.d.ts +1 -3
- package/dist/types/modules/bytes.d.ts +3 -3
- package/dist/types/modules/bzz.d.ts +14 -6
- package/dist/types/modules/chunk.d.ts +2 -2
- package/dist/types/modules/debug/balance.d.ts +4 -4
- package/dist/types/modules/debug/chequebook.d.ts +8 -8
- package/dist/types/modules/debug/chunk.d.ts +1 -10
- package/dist/types/modules/debug/settlements.d.ts +2 -2
- package/dist/types/modules/debug/stake.d.ts +3 -3
- package/dist/types/modules/debug/states.d.ts +3 -3
- package/dist/types/modules/debug/status.d.ts +10 -20
- package/dist/types/modules/debug/tag.d.ts +1 -1
- package/dist/types/modules/debug/transactions.d.ts +4 -4
- package/dist/types/modules/feed.d.ts +6 -9
- package/dist/types/modules/pinning.d.ts +4 -4
- package/dist/types/modules/pss.d.ts +1 -1
- package/dist/types/modules/soc.d.ts +1 -1
- package/dist/types/modules/status.d.ts +1 -1
- package/dist/types/modules/stewardship.d.ts +1 -1
- package/dist/types/types/debug.d.ts +0 -3
- package/dist/types/types/index.d.ts +9 -17
- package/dist/types/utils/collection.browser.d.ts +1 -1
- package/dist/types/utils/collection.d.ts +3 -3
- package/dist/types/utils/collection.node.d.ts +1 -1
- package/dist/types/utils/data.browser.d.ts +0 -7
- package/dist/types/utils/data.d.ts +1 -2
- package/dist/types/utils/error.d.ts +2 -7
- package/dist/types/utils/eth.d.ts +1 -1
- package/dist/types/utils/expose.d.ts +0 -1
- package/dist/types/utils/tar-uploader.browser.d.ts +4 -0
- package/dist/types/utils/tar-uploader.d.ts +4 -0
- package/dist/types/utils/tar-writer.browser.d.ts +3 -0
- package/dist/types/utils/tar-writer.d.ts +3 -0
- package/dist/types/utils/tar.browser.d.ts +9 -0
- package/dist/types/utils/tar.d.ts +10 -2
- package/dist/types/utils/type.d.ts +4 -1
- package/package.json +4 -19
- package/dist/cjs/bee-debug.js +0 -590
- package/dist/cjs/chunk/serialize.js +0 -19
- package/dist/cjs/utils/stream.js +0 -146
- package/dist/cjs/utils/uint64.js +0 -29
- package/dist/mjs/bee-debug.js +0 -560
- package/dist/mjs/chunk/serialize.js +0 -15
- package/dist/mjs/utils/stream.js +0 -129
- package/dist/mjs/utils/uint64.js +0 -22
- package/dist/types/bee-debug.d.ts +0 -323
- package/dist/types/chunk/serialize.d.ts +0 -6
- package/dist/types/utils/stream.d.ts +0 -40
- package/dist/types/utils/uint64.d.ts +0 -4
package/dist/cjs/modules/feed.js
CHANGED
|
@@ -8,18 +8,17 @@ const feedEndpoint = 'feeds';
|
|
|
8
8
|
/**
|
|
9
9
|
* Create an initial feed root manifest
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
11
|
+
* @param requestOptions Options for making requests
|
|
12
12
|
* @param owner Owner's ethereum address in hex
|
|
13
13
|
* @param topic Topic in hex
|
|
14
14
|
* @param postageBatchId Postage BatchId to be used to create the Feed Manifest
|
|
15
15
|
* @param options Additional options, like type (default: 'sequence')
|
|
16
16
|
*/
|
|
17
|
-
async function createFeedManifest(requestOptions, owner, topic, postageBatchId
|
|
17
|
+
async function createFeedManifest(requestOptions, owner, topic, postageBatchId) {
|
|
18
18
|
const response = await (0, http_1.http)(requestOptions, {
|
|
19
19
|
method: 'post',
|
|
20
20
|
responseType: 'json',
|
|
21
21
|
url: `${feedEndpoint}/${owner}/${topic}`,
|
|
22
|
-
params: options,
|
|
23
22
|
headers: (0, headers_1.extractUploadHeaders)(postageBatchId),
|
|
24
23
|
});
|
|
25
24
|
return response.data.reference;
|
|
@@ -47,10 +46,10 @@ function readFeedUpdateHeaders(headers) {
|
|
|
47
46
|
* the reference it contains along with its index and the
|
|
48
47
|
* index of the subsequent update.
|
|
49
48
|
*
|
|
50
|
-
* @param
|
|
51
|
-
* @param owner
|
|
52
|
-
* @param topic
|
|
53
|
-
* @param options
|
|
49
|
+
* @param requestOptions Options for making requests
|
|
50
|
+
* @param owner Owner's ethereum address in hex
|
|
51
|
+
* @param topic Topic in hex
|
|
52
|
+
* @param options Additional options, like index, at, type
|
|
54
53
|
*/
|
|
55
54
|
async function fetchLatestFeedUpdate(requestOptions, owner, topic, options) {
|
|
56
55
|
const response = await (0, http_1.http)(requestOptions, {
|
|
@@ -6,7 +6,7 @@ const PINNING_ENDPOINT = 'pins';
|
|
|
6
6
|
/**
|
|
7
7
|
* Pin data with given reference
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
9
|
+
* @param requestOptions Options for making requests
|
|
10
10
|
* @param reference Bee data reference
|
|
11
11
|
*/
|
|
12
12
|
async function pin(requestOptions, reference) {
|
|
@@ -20,7 +20,7 @@ exports.pin = pin;
|
|
|
20
20
|
/**
|
|
21
21
|
* Unpin data with given reference
|
|
22
22
|
*
|
|
23
|
-
* @param
|
|
23
|
+
* @param requestOptions Options for making requests
|
|
24
24
|
* @param reference Bee data reference
|
|
25
25
|
*/
|
|
26
26
|
async function unpin(requestOptions, reference) {
|
|
@@ -34,7 +34,7 @@ exports.unpin = unpin;
|
|
|
34
34
|
/**
|
|
35
35
|
* Get pin status for specific address.
|
|
36
36
|
*
|
|
37
|
-
* @param
|
|
37
|
+
* @param requestOptions Options for making requests
|
|
38
38
|
* @param reference
|
|
39
39
|
* @throws Error if given address is not pinned
|
|
40
40
|
*/
|
|
@@ -50,7 +50,7 @@ exports.getPin = getPin;
|
|
|
50
50
|
/**
|
|
51
51
|
* Get list of all pins
|
|
52
52
|
*
|
|
53
|
-
* @param
|
|
53
|
+
* @param requestOptions Options for making requests
|
|
54
54
|
*/
|
|
55
55
|
async function getAllPins(requestOptions) {
|
|
56
56
|
const response = await (0, http_1.http)(requestOptions, {
|
package/dist/cjs/modules/pss.js
CHANGED
|
@@ -11,7 +11,7 @@ const endpoint = 'pss';
|
|
|
11
11
|
/**
|
|
12
12
|
* Send to recipient or target with Postal Service for Swarm
|
|
13
13
|
*
|
|
14
|
-
* @param
|
|
14
|
+
* @param requestOptions Options for making requests
|
|
15
15
|
* @param topic Topic name
|
|
16
16
|
* @param target Target message address prefix
|
|
17
17
|
* @param data
|
package/dist/cjs/modules/soc.js
CHANGED
|
@@ -7,7 +7,7 @@ const socEndpoint = 'soc';
|
|
|
7
7
|
/**
|
|
8
8
|
* Upload single owner chunk (SOC) to a Bee node
|
|
9
9
|
*
|
|
10
|
-
* @param
|
|
10
|
+
* @param requestOptions Options for making requests
|
|
11
11
|
* @param owner Owner's ethereum address in hex
|
|
12
12
|
* @param identifier Arbitrary identifier in hex
|
|
13
13
|
* @param signature Signature in hex
|
|
@@ -5,7 +5,7 @@ const http_1 = require("../utils/http");
|
|
|
5
5
|
/**
|
|
6
6
|
* Ping the base bee URL. If connection was not successful throw error
|
|
7
7
|
*
|
|
8
|
-
* @param
|
|
8
|
+
* @param requestOptions Options for making requests
|
|
9
9
|
*/
|
|
10
10
|
async function checkConnection(requestOptions) {
|
|
11
11
|
await (0, http_1.http)(requestOptions, {
|
|
@@ -5,7 +5,7 @@ const http_1 = require("../utils/http");
|
|
|
5
5
|
const stewardshipEndpoint = 'stewardship';
|
|
6
6
|
/**
|
|
7
7
|
* Reupload locally pinned data
|
|
8
|
-
* @param
|
|
8
|
+
* @param requestOptions Options for making requests
|
|
9
9
|
* @param reference
|
|
10
10
|
* @param options
|
|
11
11
|
* @throws BeeResponseError if not locally pinned or invalid data
|
package/dist/cjs/package.json
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
"type": "commonjs",
|
|
3
3
|
"browser": {
|
|
4
4
|
"stream": false,
|
|
5
|
+
"fs": false,
|
|
6
|
+
"./utils/tar.js": "./utils/tar.browser.js",
|
|
7
|
+
"./utils/tar-writer.js": "./utils/tar-writer.browser.js",
|
|
8
|
+
"./utils/tar-uploader.js": "./utils/tar-uploader.browser.js",
|
|
5
9
|
"./utils/data.js": "./utils/data.browser.js",
|
|
6
10
|
"./utils/collection.node.js": "./utils/collection.browser.js"
|
|
7
11
|
}
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.SIGNATURE_BYTES_LENGTH = exports.SIGNATURE_HEX_LENGTH = exports.TOPIC_HEX_LENGTH = exports.TOPIC_BYTES_LENGTH = exports.RedundancyStrategy = exports.RedundancyLevel = exports.FEED_INDEX_HEX_LENGTH = exports.TAGS_LIMIT_MAX = exports.TAGS_LIMIT_MIN = exports.STAMPS_DEPTH_MAX = exports.STAMPS_DEPTH_MIN = exports.ENCRYPTED_REFERENCE_BYTES_LENGTH = exports.REFERENCE_BYTES_LENGTH = exports.ENCRYPTED_REFERENCE_HEX_LENGTH = exports.REFERENCE_HEX_LENGTH = exports.BATCH_ID_HEX_LENGTH = exports.PUBKEY_HEX_LENGTH = exports.PSS_TARGET_HEX_LENGTH_MAX = exports.ADDRESS_HEX_LENGTH = exports.CHUNK_SIZE = exports.BRANCHES = exports.SECTION_SIZE = exports.SPAN_SIZE = void 0;
|
|
17
|
+
exports.SIGNATURE_BYTES_LENGTH = exports.SIGNATURE_HEX_LENGTH = exports.TOPIC_HEX_LENGTH = exports.TOPIC_BYTES_LENGTH = exports.RedundancyStrategy = exports.RedundancyLevel = exports.FEED_INDEX_HEX_LENGTH = exports.TAGS_LIMIT_MAX = exports.TAGS_LIMIT_MIN = exports.STAMPS_DEPTH_MAX = exports.STAMPS_AMOUNT_MIN = exports.STAMPS_DEPTH_MIN = exports.ENCRYPTED_REFERENCE_BYTES_LENGTH = exports.REFERENCE_BYTES_LENGTH = exports.ENCRYPTED_REFERENCE_HEX_LENGTH = exports.REFERENCE_HEX_LENGTH = exports.BATCH_ID_HEX_LENGTH = exports.PUBKEY_HEX_LENGTH = exports.PSS_TARGET_HEX_LENGTH_MAX = exports.ADDRESS_HEX_LENGTH = exports.CHUNK_SIZE = exports.BRANCHES = exports.SECTION_SIZE = exports.SPAN_SIZE = void 0;
|
|
18
18
|
__exportStar(require("./debug"), exports);
|
|
19
19
|
exports.SPAN_SIZE = 8;
|
|
20
20
|
exports.SECTION_SIZE = 32;
|
|
@@ -32,6 +32,10 @@ exports.ENCRYPTED_REFERENCE_BYTES_LENGTH = 64;
|
|
|
32
32
|
* Minimal depth that can be used for creation of postage batch
|
|
33
33
|
*/
|
|
34
34
|
exports.STAMPS_DEPTH_MIN = 17;
|
|
35
|
+
/**
|
|
36
|
+
* Minimal amount that can be used for creation of postage batch
|
|
37
|
+
*/
|
|
38
|
+
exports.STAMPS_AMOUNT_MIN = 24000 * 24 * 60 * 12;
|
|
35
39
|
/**
|
|
36
40
|
* Maximal depth that can be used for creation of postage batch
|
|
37
41
|
*/
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCollectionSize = exports.makeCollectionFromFileList = exports.assertCollection = exports.isCollection = void 0;
|
|
4
4
|
const error_1 = require("./error");
|
|
5
|
-
const file_1 = require("./file");
|
|
6
|
-
const type_1 = require("./type");
|
|
7
5
|
function isCollection(data) {
|
|
8
6
|
if (!Array.isArray(data)) {
|
|
9
7
|
return false;
|
|
10
8
|
}
|
|
11
|
-
return data.every(entry => typeof entry === 'object' && entry.
|
|
9
|
+
return data.every(entry => typeof entry === 'object' && entry.path && entry.size);
|
|
12
10
|
}
|
|
13
11
|
exports.isCollection = isCollection;
|
|
14
12
|
function assertCollection(data) {
|
|
@@ -27,17 +25,11 @@ function makeFilePath(file) {
|
|
|
27
25
|
throw new TypeError('file is not valid File object');
|
|
28
26
|
}
|
|
29
27
|
async function makeCollectionFromFileList(fileList) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
path: makeFilePath(file),
|
|
36
|
-
data: new Uint8Array(await (0, file_1.fileArrayBuffer)(file)),
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return collection;
|
|
28
|
+
return Array.from(fileList).map(file => ({
|
|
29
|
+
path: makeFilePath(file),
|
|
30
|
+
size: file.size,
|
|
31
|
+
file,
|
|
32
|
+
}));
|
|
41
33
|
}
|
|
42
34
|
exports.makeCollectionFromFileList = makeCollectionFromFileList;
|
|
43
35
|
/**
|
|
@@ -47,13 +39,6 @@ exports.makeCollectionFromFileList = makeCollectionFromFileList;
|
|
|
47
39
|
* @returns size in bytes
|
|
48
40
|
*/
|
|
49
41
|
function getCollectionSize(fileList) {
|
|
50
|
-
|
|
51
|
-
for (let i = 0; i < fileList.length; i++) {
|
|
52
|
-
const file = fileList[i];
|
|
53
|
-
if (file) {
|
|
54
|
-
sum += file.size;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return sum;
|
|
42
|
+
return Array.from(fileList).reduce((sum, file) => sum + file.size, 0);
|
|
58
43
|
}
|
|
59
44
|
exports.getCollectionSize = getCollectionSize;
|
|
@@ -33,7 +33,8 @@ async function buildCollectionRelative(dir, relativePath) {
|
|
|
33
33
|
if (entry.isFile()) {
|
|
34
34
|
collection.push({
|
|
35
35
|
path: entryPath,
|
|
36
|
-
|
|
36
|
+
size: (await fs_1.default.promises.stat(fullPath)).size,
|
|
37
|
+
fsPath: fullPath,
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
else if (entry.isDirectory()) {
|
|
@@ -1,54 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prepareWebsocketData =
|
|
4
|
-
const stream_1 = require("./stream");
|
|
5
|
-
/**
|
|
6
|
-
* Validates input and converts to Uint8Array
|
|
7
|
-
*
|
|
8
|
-
* @param data any string, ArrayBuffer or Uint8Array
|
|
9
|
-
*/
|
|
10
|
-
async function prepareData(data) {
|
|
11
|
-
if (typeof data === 'string')
|
|
12
|
-
return new Blob([data], { type: 'text/plain' });
|
|
13
|
-
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
14
|
-
return new Blob([data], { type: 'application/octet-stream' });
|
|
15
|
-
}
|
|
16
|
-
if (data instanceof Blob) {
|
|
17
|
-
return data;
|
|
18
|
-
}
|
|
19
|
-
// Currently it is not possible to stream requests from browsers
|
|
20
|
-
// there are already first experiments on this field (Chromium)
|
|
21
|
-
// but till it is fully implemented across browsers-land we have to
|
|
22
|
-
// buffer the data before sending the requests.
|
|
23
|
-
if ((0, stream_1.isNodeReadable)(data)) {
|
|
24
|
-
return new Promise(resolve => {
|
|
25
|
-
const buffers = [];
|
|
26
|
-
data.on('data', d => {
|
|
27
|
-
buffers.push(d);
|
|
28
|
-
});
|
|
29
|
-
data.on('end', () => {
|
|
30
|
-
resolve(new Blob(buffers, { type: 'application/octet-stream' }));
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
if ((0, stream_1.isReadableStream)(data)) {
|
|
35
|
-
return new Promise(async (resolve) => {
|
|
36
|
-
const reader = data.getReader();
|
|
37
|
-
const buffers = [];
|
|
38
|
-
let done, value;
|
|
39
|
-
do {
|
|
40
|
-
;
|
|
41
|
-
({ done, value } = await reader.read());
|
|
42
|
-
if (!done) {
|
|
43
|
-
buffers.push(value);
|
|
44
|
-
}
|
|
45
|
-
} while (!done);
|
|
46
|
-
resolve(new Blob(buffers, { type: 'application/octet-stream' }));
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
throw new TypeError('unknown data type');
|
|
50
|
-
}
|
|
51
|
-
exports.prepareData = prepareData;
|
|
3
|
+
exports.prepareWebsocketData = void 0;
|
|
52
4
|
async function prepareWebsocketData(data) {
|
|
53
5
|
if (typeof data === 'string')
|
|
54
6
|
return new TextEncoder().encode(data);
|
package/dist/cjs/utils/error.js
CHANGED
|
@@ -15,14 +15,10 @@ class BeeArgumentError extends BeeError {
|
|
|
15
15
|
}
|
|
16
16
|
exports.BeeArgumentError = BeeArgumentError;
|
|
17
17
|
class BeeResponseError extends BeeError {
|
|
18
|
-
constructor(message,
|
|
18
|
+
constructor(message, status, statusText) {
|
|
19
19
|
super(message);
|
|
20
|
-
this.code = code;
|
|
21
|
-
this.axiosStatus = axiosStatus;
|
|
22
20
|
this.status = status;
|
|
23
|
-
this.
|
|
24
|
-
this.request = request;
|
|
25
|
-
this.response = response;
|
|
21
|
+
this.statusText = statusText;
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
24
|
exports.BeeResponseError = BeeResponseError;
|
package/dist/cjs/utils/eth.js
CHANGED
|
@@ -7,8 +7,8 @@ exports.makeEthereumWalletSigner = exports.ethToSwarmAddress = exports.fromLittl
|
|
|
7
7
|
// For ESM compatibility
|
|
8
8
|
const js_sha3_1 = __importDefault(require("js-sha3"));
|
|
9
9
|
const { keccak256, sha3_256 } = js_sha3_1.default;
|
|
10
|
-
const hex_1 = require("./hex");
|
|
11
10
|
const bytes_1 = require("./bytes");
|
|
11
|
+
const hex_1 = require("./hex");
|
|
12
12
|
const ETH_ADDR_BYTES_LENGTH = 20;
|
|
13
13
|
const ETH_ADDR_HEX_LENGTH = 40;
|
|
14
14
|
function makeEthAddress(address) {
|
package/dist/cjs/utils/expose.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRedundancyStats = exports.getRedundancyStat = exports.approximateOverheadForRedundancyLevel = exports.getStampUsage = exports.getStampTtlSeconds = exports.getStampMaximumCapacityBytes = exports.getStampEffectiveBytes = exports.getStampCostInPlur = exports.getStampCostInBzz = exports.getDepthForCapacity = exports.getAmountForTtl = exports.makeMaxTarget = exports.keccak256Hash = exports.
|
|
3
|
+
exports.getRedundancyStats = exports.getRedundancyStat = exports.approximateOverheadForRedundancyLevel = exports.getStampUsage = exports.getStampTtlSeconds = exports.getStampMaximumCapacityBytes = exports.getStampEffectiveBytes = exports.getStampCostInPlur = exports.getStampCostInBzz = exports.getDepthForCapacity = exports.getAmountForTtl = exports.makeMaxTarget = exports.keccak256Hash = exports.toLittleEndian = exports.makeHexEthAddress = exports.makeEthereumWalletSigner = exports.makeEthAddress = exports.isHexEthAddress = exports.fromLittleEndian = exports.ethToSwarmAddress = exports.makeHexString = exports.isHexString = exports.intToHex = exports.hexToBytes = exports.bytesToHex = exports.assertPrefixedHexString = exports.assertHexString = exports.isFlexBytes = exports.isBytes = exports.flexBytesAtOffset = exports.bytesEqual = exports.bytesAtOffset = exports.assertFlexBytes = exports.assertBytes = exports.getFolderSize = exports.getCollectionSize = void 0;
|
|
4
4
|
var collection_1 = require("./collection");
|
|
5
5
|
Object.defineProperty(exports, "getCollectionSize", { enumerable: true, get: function () { return collection_1.getCollectionSize; } });
|
|
6
6
|
var collection_node_1 = require("./collection.node");
|
|
@@ -29,13 +29,6 @@ Object.defineProperty(exports, "makeEthAddress", { enumerable: true, get: functi
|
|
|
29
29
|
Object.defineProperty(exports, "makeEthereumWalletSigner", { enumerable: true, get: function () { return eth_1.makeEthereumWalletSigner; } });
|
|
30
30
|
Object.defineProperty(exports, "makeHexEthAddress", { enumerable: true, get: function () { return eth_1.makeHexEthAddress; } });
|
|
31
31
|
Object.defineProperty(exports, "toLittleEndian", { enumerable: true, get: function () { return eth_1.toLittleEndian; } });
|
|
32
|
-
var stream_1 = require("./stream");
|
|
33
|
-
Object.defineProperty(exports, "isNodeReadable", { enumerable: true, get: function () { return stream_1.isNodeReadable; } });
|
|
34
|
-
Object.defineProperty(exports, "isReadable", { enumerable: true, get: function () { return stream_1.isReadable; } });
|
|
35
|
-
Object.defineProperty(exports, "isReadableStream", { enumerable: true, get: function () { return stream_1.isReadableStream; } });
|
|
36
|
-
Object.defineProperty(exports, "normalizeToReadableStream", { enumerable: true, get: function () { return stream_1.normalizeToReadableStream; } });
|
|
37
|
-
Object.defineProperty(exports, "readableNodeToWeb", { enumerable: true, get: function () { return stream_1.readableNodeToWeb; } });
|
|
38
|
-
Object.defineProperty(exports, "readableWebToNode", { enumerable: true, get: function () { return stream_1.readableWebToNode; } });
|
|
39
32
|
var hash_1 = require("./hash");
|
|
40
33
|
Object.defineProperty(exports, "keccak256Hash", { enumerable: true, get: function () { return hash_1.keccak256Hash; } });
|
|
41
34
|
var pss_1 = require("./pss");
|
package/dist/cjs/utils/file.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fileArrayBuffer = exports.isFile = void 0;
|
|
2
4
|
/**
|
|
3
5
|
* Compatibility functions for working with File API objects
|
|
4
6
|
*
|
|
5
7
|
* https://developer.mozilla.org/en-US/docs/Web/API/File
|
|
6
8
|
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.fileArrayBuffer = exports.isFile = void 0;
|
|
9
9
|
function isFile(file) {
|
|
10
10
|
// browser
|
|
11
11
|
if (typeof File === 'function') {
|
package/dist/cjs/utils/http.js
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
6
|
exports.http = exports.DEFAULT_HTTP_CONFIG = void 0;
|
|
27
|
-
const axios_1 =
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
28
8
|
const cafe_utility_1 = require("cafe-utility");
|
|
29
9
|
const index_1 = require("../index");
|
|
10
|
+
const { AxiosError } = axios_1.default;
|
|
30
11
|
exports.DEFAULT_HTTP_CONFIG = {
|
|
31
12
|
headers: {
|
|
32
13
|
accept: 'application/json, text/plain, */*',
|
|
@@ -48,8 +29,8 @@ async function http(options, config) {
|
|
|
48
29
|
return response;
|
|
49
30
|
}
|
|
50
31
|
catch (e) {
|
|
51
|
-
if (e instanceof
|
|
52
|
-
throw new index_1.BeeResponseError(e.message, e.
|
|
32
|
+
if (e instanceof AxiosError) {
|
|
33
|
+
throw new index_1.BeeResponseError(e.message, e.status, e.code);
|
|
53
34
|
}
|
|
54
35
|
throw e;
|
|
55
36
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uploadTar = void 0;
|
|
4
|
+
const bzz_1 = require("../modules/bzz");
|
|
5
|
+
const http_1 = require("./http");
|
|
6
|
+
const tar_1 = require("./tar");
|
|
7
|
+
const tar_writer_1 = require("./tar-writer");
|
|
8
|
+
const bzzEndpoint = 'bzz';
|
|
9
|
+
async function uploadTar(requestOptions, collection, postageBatchId, options) {
|
|
10
|
+
const tarStream = new tar_1.TarStream();
|
|
11
|
+
await (0, tar_writer_1.writeTar)(collection, tarStream);
|
|
12
|
+
await tarStream.end();
|
|
13
|
+
const response = await (0, http_1.http)(requestOptions, {
|
|
14
|
+
method: 'post',
|
|
15
|
+
url: bzzEndpoint,
|
|
16
|
+
data: tarStream.output,
|
|
17
|
+
responseType: 'json',
|
|
18
|
+
headers: {
|
|
19
|
+
'content-type': 'application/x-tar',
|
|
20
|
+
'swarm-collection': 'true',
|
|
21
|
+
...(0, bzz_1.extractCollectionUploadHeaders)(postageBatchId, options),
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
return response;
|
|
25
|
+
}
|
|
26
|
+
exports.uploadTar = uploadTar;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uploadTar = void 0;
|
|
4
|
+
const bzz_1 = require("../modules/bzz");
|
|
5
|
+
const http_1 = require("./http");
|
|
6
|
+
const tar_1 = require("./tar");
|
|
7
|
+
const tar_writer_1 = require("./tar-writer");
|
|
8
|
+
const bzzEndpoint = 'bzz';
|
|
9
|
+
async function uploadTar(requestOptions, collection, postageBatchId, options) {
|
|
10
|
+
const tarStream = new tar_1.TarStream();
|
|
11
|
+
const responsePromise = (0, http_1.http)(requestOptions, {
|
|
12
|
+
method: 'post',
|
|
13
|
+
url: bzzEndpoint,
|
|
14
|
+
data: tarStream.output,
|
|
15
|
+
responseType: 'json',
|
|
16
|
+
headers: {
|
|
17
|
+
'content-type': 'application/x-tar',
|
|
18
|
+
'swarm-collection': 'true',
|
|
19
|
+
...(0, bzz_1.extractCollectionUploadHeaders)(postageBatchId, options),
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
await (0, tar_writer_1.writeTar)(collection, tarStream);
|
|
23
|
+
await tarStream.end();
|
|
24
|
+
const response = await responsePromise;
|
|
25
|
+
return response;
|
|
26
|
+
}
|
|
27
|
+
exports.uploadTar = uploadTar;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeTar = void 0;
|
|
4
|
+
const file_1 = require("./file");
|
|
5
|
+
async function writeTar(collection, tarStream) {
|
|
6
|
+
for (const item of collection) {
|
|
7
|
+
if (item.file) {
|
|
8
|
+
await tarStream.beginFile(item.path, item.file.size);
|
|
9
|
+
await tarStream.appendFile(new Uint8Array(await (0, file_1.fileArrayBuffer)(item.file)));
|
|
10
|
+
await tarStream.endFile();
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
throw new Error('Invalid collection item');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.writeTar = writeTar;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeTar = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
async function writeTar(collection, tarStream) {
|
|
6
|
+
for (const item of collection) {
|
|
7
|
+
await tarStream.beginFile(item.path, item.size);
|
|
8
|
+
if (item.fsPath) {
|
|
9
|
+
const stream = (0, fs_1.createReadStream)(item.fsPath);
|
|
10
|
+
for await (const chunk of stream) {
|
|
11
|
+
await tarStream.appendFile(chunk);
|
|
12
|
+
}
|
|
13
|
+
await tarStream.endFile();
|
|
14
|
+
stream.close();
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
throw new Error('Invalid collection item');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.writeTar = writeTar;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TarStream = void 0;
|
|
4
|
+
class TarStream {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.pieces = [];
|
|
7
|
+
this.currentFileSize = 0;
|
|
8
|
+
}
|
|
9
|
+
get output() {
|
|
10
|
+
return this.pieces.reduce((acc, piece) => {
|
|
11
|
+
const newAcc = new Uint8Array(acc.length + piece.length);
|
|
12
|
+
newAcc.set(acc);
|
|
13
|
+
newAcc.set(piece, acc.length);
|
|
14
|
+
return newAcc;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
async beginFile(path, size) {
|
|
18
|
+
const header = createHeader(path, size);
|
|
19
|
+
this.pieces.push(header);
|
|
20
|
+
this.currentFileSize = 0;
|
|
21
|
+
}
|
|
22
|
+
async appendFile(data) {
|
|
23
|
+
this.pieces.push(data);
|
|
24
|
+
this.currentFileSize += data.length;
|
|
25
|
+
}
|
|
26
|
+
async endFile() {
|
|
27
|
+
const padding = 512 - (this.currentFileSize % 512);
|
|
28
|
+
this.pieces.push(new Uint8Array(padding));
|
|
29
|
+
}
|
|
30
|
+
async end() {
|
|
31
|
+
this.pieces.push(createEndOfArchive());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.TarStream = TarStream;
|
|
35
|
+
function createHeader(path, size) {
|
|
36
|
+
const header = new Uint8Array(512); // Initialize header with zeros
|
|
37
|
+
const encoder = new TextEncoder();
|
|
38
|
+
function writeToBuffer(str, offset, length) {
|
|
39
|
+
const bytes = encoder.encode(str);
|
|
40
|
+
header.set(bytes.slice(0, length), offset);
|
|
41
|
+
}
|
|
42
|
+
writeToBuffer(path, 0, 100); // File name
|
|
43
|
+
writeToBuffer('0000777', 100, 8); // File mode
|
|
44
|
+
writeToBuffer('0001750', 108, 8); // UID
|
|
45
|
+
writeToBuffer('0001750', 116, 8); // GID
|
|
46
|
+
writeToBuffer(size.toString(8).padStart(11, '0') + ' ', 124, 12); // File size
|
|
47
|
+
writeToBuffer(Math.floor(Date.now() / 1000).toString(8) + ' ', 136, 12); // Mod time
|
|
48
|
+
writeToBuffer(' ', 148, 8); // Checksum placeholder
|
|
49
|
+
writeToBuffer('0', 156, 1); // Typeflag
|
|
50
|
+
writeToBuffer('ustar ', 257, 8); // Magic and version
|
|
51
|
+
for (let i = 345; i < 512; i++) {
|
|
52
|
+
header[i] = 0; // Fill remaining with zeros
|
|
53
|
+
}
|
|
54
|
+
// Calculate checksum
|
|
55
|
+
let checksum = 0;
|
|
56
|
+
for (let i = 0; i < 512; i++) {
|
|
57
|
+
checksum += header[i];
|
|
58
|
+
}
|
|
59
|
+
// Write checksum
|
|
60
|
+
writeToBuffer(checksum.toString(8).padStart(6, '0') + '\0 ', 148, 8);
|
|
61
|
+
return header;
|
|
62
|
+
}
|
|
63
|
+
function createEndOfArchive() {
|
|
64
|
+
return new Uint8Array(1024);
|
|
65
|
+
}
|
package/dist/cjs/utils/tar.js
CHANGED
|
@@ -1,25 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
3
|
+
exports.TarStream = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
class TarStream {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.output = new stream_1.PassThrough();
|
|
8
|
+
this.currentFileSize = 0;
|
|
9
|
+
}
|
|
10
|
+
async beginFile(path, size) {
|
|
11
|
+
const header = createHeader(path, size);
|
|
12
|
+
this.output.write(header);
|
|
13
|
+
this.currentFileSize = 0;
|
|
14
|
+
}
|
|
15
|
+
async appendFile(data) {
|
|
16
|
+
return new Promise(resolve => {
|
|
17
|
+
this.output.write(data, () => {
|
|
18
|
+
resolve();
|
|
19
|
+
});
|
|
20
|
+
this.currentFileSize += data.length;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async endFile() {
|
|
24
|
+
const padding = 512 - (this.currentFileSize % 512);
|
|
25
|
+
this.output.write(Buffer.alloc(padding, 0));
|
|
22
26
|
}
|
|
23
|
-
|
|
27
|
+
async end() {
|
|
28
|
+
this.output.write(createEndOfArchive());
|
|
29
|
+
this.output.end();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.TarStream = TarStream;
|
|
33
|
+
function createHeader(path, size) {
|
|
34
|
+
const header = Buffer.alloc(512, 0); // Initialize header with zeros
|
|
35
|
+
header.write(path, 0, 100); // File name
|
|
36
|
+
header.write('0000777', 100, 8); // File mode
|
|
37
|
+
header.write('0001750', 108, 8); // UID
|
|
38
|
+
header.write('0001750', 116, 8); // GID
|
|
39
|
+
header.write(size.toString(8).padStart(11, '0') + ' ', 124, 12); // File size
|
|
40
|
+
header.write(Math.floor(new Date().getTime() / 1000).toString(8) + ' ', 136, 12); // Mod time
|
|
41
|
+
header.write(' ', 148, 8); // Checksum placeholder
|
|
42
|
+
header.write('0', 156, 1); // Typeflag
|
|
43
|
+
header.write('ustar ', 257, 8); // Magic and version
|
|
44
|
+
header.write('0'.repeat(8 * 12), 345, 8 * 12); // Fill remaining with zeros
|
|
45
|
+
const checksum = header.reduce((sum, elem) => sum + elem, 0);
|
|
46
|
+
header.write(checksum.toString(8).padStart(6, '0') + '\0 ', 148, 8); // Write checksum
|
|
47
|
+
return header;
|
|
48
|
+
}
|
|
49
|
+
function createEndOfArchive() {
|
|
50
|
+
return Buffer.alloc(1024, 0);
|
|
24
51
|
}
|
|
25
|
-
exports.makeTar = makeTar;
|
package/dist/cjs/utils/type.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertTransactionOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.addCidConversionFunction = exports.makeReferenceOrEns = exports.assertReferenceOrEns = exports.assertReference = exports.assertPositiveInteger = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isUint8Array = void 0;
|
|
3
|
+
exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertTransactionOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.addCidConversionFunction = exports.makeReferenceOrEns = exports.assertReferenceOrEns = exports.assertReference = exports.assertPositiveInteger = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isUint8Array = exports.isReadable = void 0;
|
|
4
4
|
const swarm_cid_1 = require("@ethersphere/swarm-cid");
|
|
5
|
+
const stream_1 = require("stream");
|
|
5
6
|
const types_1 = require("../types");
|
|
6
7
|
const error_1 = require("./error");
|
|
7
8
|
const file_1 = require("./file");
|
|
8
9
|
const hex_1 = require("./hex");
|
|
9
|
-
|
|
10
|
+
function isReadable(obj) {
|
|
11
|
+
return typeof stream_1.Readable !== 'undefined' && obj instanceof stream_1.Readable;
|
|
12
|
+
}
|
|
13
|
+
exports.isReadable = isReadable;
|
|
10
14
|
function isUint8Array(obj) {
|
|
11
15
|
return obj instanceof Uint8Array;
|
|
12
16
|
}
|
|
@@ -346,7 +350,7 @@ exports.assertData = assertData;
|
|
|
346
350
|
* @throws TypeError if not valid
|
|
347
351
|
*/
|
|
348
352
|
function assertFileData(value) {
|
|
349
|
-
if (typeof value !== 'string' && !(value instanceof Uint8Array) && !(0, file_1.isFile)(value) && !
|
|
353
|
+
if (typeof value !== 'string' && !(value instanceof Uint8Array) && !(0, file_1.isFile)(value) && !isReadable(value)) {
|
|
350
354
|
throw new TypeError('Data must be either string, Readable, Uint8Array or File!');
|
|
351
355
|
}
|
|
352
356
|
}
|