@did-space/core 0.5.4 → 0.5.6

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.
@@ -21,6 +21,7 @@ const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
21
21
  const isUndefined_1 = __importDefault(require("lodash/isUndefined"));
22
22
  const omit_1 = __importDefault(require("lodash/omit"));
23
23
  const xbytes_1 = __importDefault(require("xbytes"));
24
+ const lodash_1 = require("lodash");
24
25
  const configuration_1 = require("../configuration");
25
26
  const model_1 = require("../model");
26
27
  const utils_1 = require("../utils");
@@ -366,7 +367,8 @@ class ObjectSpace {
366
367
  if (!(0, utils_1.isDirectory)(key) && !(0, stream_1.isStream)(data)) {
367
368
  options.hash = options.hash || (yield (0, utils_1.getHash)(data));
368
369
  options.size = options.size || (0, utils_1.getSize)(data);
369
- if (!options.hash || !options.size) {
370
+ // @note: size 可能是空的
371
+ if (!options.hash || !(0, lodash_1.isNumber)(options.size)) {
370
372
  throw new Error('Hash and size cannot be empty');
371
373
  }
372
374
  }
@@ -1,5 +1,12 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Readable } from 'stream';
3
4
  export declare function isStream(data: any): boolean;
4
5
  export declare function stringToStream(str: string): Readable;
5
- export declare const streamToString: (stream: any) => Promise<string>;
6
+ /**
7
+ * @see https://stackoverflow.com/a/78087909
8
+ * @param stream
9
+ * @param encoding
10
+ * @returns
11
+ */
12
+ export declare const streamToString: (stream: any, encoding?: BufferEncoding) => Promise<string>;
@@ -1,8 +1,18 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.streamToString = exports.stringToStream = exports.isStream = void 0;
4
13
  const stream_1 = require("stream");
5
14
  const lodash_1 = require("lodash");
15
+ const consumers_1 = require("node:stream/consumers");
6
16
  function isStream(data) {
7
17
  return data instanceof stream_1.Stream || data instanceof stream_1.Readable || (0, lodash_1.isFunction)(data === null || data === void 0 ? void 0 : data.pipe);
8
18
  }
@@ -14,10 +24,14 @@ function stringToStream(str) {
14
24
  return stream;
15
25
  }
16
26
  exports.stringToStream = stringToStream;
17
- const streamToString = (stream) => new Promise((resolve, reject) => {
18
- const chunks = [];
19
- stream.on('data', (chunk) => chunks.push(chunk));
20
- stream.on('error', reject);
21
- stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
27
+ /**
28
+ * @see https://stackoverflow.com/a/78087909
29
+ * @param stream
30
+ * @param encoding
31
+ * @returns
32
+ */
33
+ const streamToString = (stream, encoding) => __awaiter(void 0, void 0, void 0, function* () {
34
+ const data = yield (0, consumers_1.buffer)(stream);
35
+ return data.toString(encoding);
22
36
  });
23
37
  exports.streamToString = streamToString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@did-space/core",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@arcblock/ipfs-only-hash": "^0.0.2",
40
- "@arcblock/validator": "^1.18.123",
40
+ "@arcblock/validator": "^1.18.126",
41
41
  "dayjs": "^1.11.11",
42
42
  "debug": "^4.3.5",
43
43
  "hasha": "^5.2.2",
@@ -51,15 +51,15 @@
51
51
  "xbytes": "^1.9.1"
52
52
  },
53
53
  "devDependencies": {
54
- "@arcblock/eslint-config-ts": "^0.2.4",
54
+ "@arcblock/eslint-config-ts": "^0.3.2",
55
55
  "@types/jest": "^28.1.8",
56
56
  "@types/node": "18.19.31",
57
- "@typescript-eslint/eslint-plugin": "^7.13.1",
57
+ "@typescript-eslint/eslint-plugin": "^7.16.1",
58
58
  "eslint": "^8.57.0",
59
59
  "jest": "^29.7.0",
60
60
  "lint-staged": "^13.3.0",
61
61
  "ts-jest": "^28.0.8",
62
62
  "typescript": "^4.9.5"
63
63
  },
64
- "gitHead": "b6d4209c37efd6a43cb8fc3a710a49c0341a0e6d"
64
+ "gitHead": "896033285c7f7be59b7bf196636bd8ad04b2dd73"
65
65
  }