@did-space/core 0.5.52 → 0.5.54

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.
@@ -353,7 +353,7 @@ class ObjectSpace extends events_1.default {
353
353
  }
354
354
  if (!(0, utils_1.isDirectory)(key) && !(0, utils_1.isStream)(data)) {
355
355
  options.hash = options.hash || (yield (0, utils_1.getHash)(data));
356
- options.size = options.size || (0, utils_1.getSize)(data);
356
+ options.size = options.size || (yield (0, utils_1.getSize)(data));
357
357
  // @note: size 可能是空的
358
358
  if (!options.hash || !(0, lodash_1.isNumber)(options.size)) {
359
359
  throw new Error('Hash and size cannot be empty');
@@ -628,7 +628,7 @@ class ObjectSpace extends events_1.default {
628
628
  debug('createConfig.before', { spaceConfig });
629
629
  const data = js_yaml_1.default.dump(spaceConfig);
630
630
  const hash = yield (0, utils_1.getHash)(data);
631
- const size = (0, utils_1.getSize)(data);
631
+ const size = yield (0, utils_1.getSize)(data);
632
632
  debug('createConfig.$data', data);
633
633
  debug('createConfig.$hash', hash);
634
634
  debug('createConfig.$size', size);
@@ -1,5 +1,5 @@
1
1
  import { Data } from '../meta';
2
- export declare function getSize(data?: Data): number;
3
- export declare function isDirectory(key: string): boolean;
4
2
  export declare function isStream(data: any): boolean;
3
+ export declare function getSize(data?: Data): Promise<number>;
4
+ export declare function isDirectory(key: string): boolean;
5
5
  export declare function isValidData(data: Data): boolean;
@@ -1,26 +1,55 @@
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
- exports.isValidData = exports.isStream = exports.isDirectory = exports.getSize = void 0;
12
+ exports.isValidData = exports.isDirectory = exports.getSize = exports.isStream = void 0;
4
13
  const lodash_1 = require("lodash");
5
14
  const stream_1 = require("stream");
15
+ function isStream(data) {
16
+ return data instanceof stream_1.Stream || data instanceof stream_1.Readable || (0, lodash_1.isFunction)(data === null || data === void 0 ? void 0 : data.pipe);
17
+ }
18
+ exports.isStream = isStream;
19
+ // eslint-disable-next-line require-await
6
20
  function getSize(data = '') {
7
- if (typeof data === 'string') {
8
- return Buffer.byteLength(data, 'utf-8');
9
- }
10
- if (Buffer.isBuffer(data)) {
11
- return Buffer.byteLength(data);
12
- }
13
- throw new Error(`#getSize() Invalid data type: ${data}`);
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ if (typeof data === 'string') {
23
+ return Buffer.byteLength(data, 'utf-8');
24
+ }
25
+ if (Buffer.isBuffer(data)) {
26
+ return Buffer.byteLength(data);
27
+ }
28
+ if (isStream(data)) {
29
+ return new Promise((resolve, reject) => {
30
+ let size = 0;
31
+ // @ts-expect-error
32
+ data.on('data', (chunk) => {
33
+ size += chunk.length;
34
+ });
35
+ // @ts-expect-error
36
+ data.on('end', () => {
37
+ resolve(size);
38
+ });
39
+ // @ts-expect-error
40
+ data.on('error', (err) => {
41
+ reject(err);
42
+ });
43
+ });
44
+ }
45
+ throw new Error(`#getSize() Invalid data type: ${data}`);
46
+ });
14
47
  }
15
48
  exports.getSize = getSize;
16
49
  function isDirectory(key) {
17
50
  return key.endsWith('/');
18
51
  }
19
52
  exports.isDirectory = isDirectory;
20
- function isStream(data) {
21
- return data instanceof stream_1.Stream || data instanceof stream_1.Readable || (0, lodash_1.isFunction)(data === null || data === void 0 ? void 0 : data.pipe);
22
- }
23
- exports.isStream = isStream;
24
53
  function isValidData(data) {
25
54
  return (0, lodash_1.isString)(data) || (0, lodash_1.isBuffer)(data) || isStream(data);
26
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@did-space/core",
3
- "version": "0.5.52",
3
+ "version": "0.5.54",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -55,5 +55,5 @@
55
55
  "vite": "^5.4.8",
56
56
  "vitest": "^2.1.2"
57
57
  },
58
- "gitHead": "acfb63fde194e4a029c2666669f17e61a9dbf0d1"
58
+ "gitHead": "2cd344a1dbbc897c682ca5dad796b2849e15e082"
59
59
  }