@zenfs/dom 0.0.4 → 0.0.5

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/dist/fetch.js CHANGED
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  /**
11
2
  * Contains utility methods for network I/O (using fetch)
12
3
  */
@@ -18,33 +9,29 @@ export const fetchIsAvailable = typeof fetch !== 'undefined' && fetch !== null;
18
9
  function convertError(e) {
19
10
  throw new ApiError(ErrorCode.EIO, e.message);
20
11
  }
21
- export function fetchFile(p, type) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const response = yield fetch(p).catch(convertError);
24
- if (!response.ok) {
25
- throw new ApiError(ErrorCode.EIO, `fetch error: response returned code ${response.status}`);
26
- }
27
- switch (type) {
28
- case 'buffer':
29
- const arrayBuffer = yield response.arrayBuffer().catch(convertError);
30
- return new Uint8Array(arrayBuffer);
31
- case 'json':
32
- return response.json().catch(convertError);
33
- default:
34
- throw new ApiError(ErrorCode.EINVAL, 'Invalid download type: ' + type);
35
- }
36
- });
12
+ export async function fetchFile(p, type) {
13
+ const response = await fetch(p).catch(convertError);
14
+ if (!response.ok) {
15
+ throw new ApiError(ErrorCode.EIO, `fetch error: response returned code ${response.status}`);
16
+ }
17
+ switch (type) {
18
+ case 'buffer':
19
+ const arrayBuffer = await response.arrayBuffer().catch(convertError);
20
+ return new Uint8Array(arrayBuffer);
21
+ case 'json':
22
+ return response.json().catch(convertError);
23
+ default:
24
+ throw new ApiError(ErrorCode.EINVAL, 'Invalid download type: ' + type);
25
+ }
37
26
  }
38
27
  /**
39
28
  * Asynchronously retrieves the size of the given file in bytes.
40
29
  * @hidden
41
30
  */
42
- export function fetchFileSize(p) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- const response = yield fetch(p, { method: 'HEAD' }).catch(convertError);
45
- if (!response.ok) {
46
- throw new ApiError(ErrorCode.EIO, `fetch HEAD error: response returned code ${response.status}`);
47
- }
48
- return parseInt(response.headers.get('Content-Length') || '-1', 10);
49
- });
31
+ export async function fetchFileSize(p) {
32
+ const response = await fetch(p, { method: 'HEAD' }).catch(convertError);
33
+ if (!response.ok) {
34
+ throw new ApiError(ErrorCode.EIO, `fetch HEAD error: response returned code ${response.status}`);
35
+ }
36
+ return parseInt(response.headers.get('Content-Length') || '-1', 10);
50
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/dom",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "DOM backends for ZenFS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist",
@@ -51,6 +51,6 @@
51
51
  "typescript": "5.2.2"
52
52
  },
53
53
  "dependencies": {
54
- "@zenfs/core": "^0.0.11"
54
+ "@zenfs/core": "^0.1.0"
55
55
  }
56
56
  }