koa-files 4.1.7 → 5.0.1

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/esm/utils/fs.d.ts CHANGED
@@ -1,12 +1,24 @@
1
1
  /**
2
2
  * @module fs
3
3
  */
4
- import fs, { Stats } from 'fs';
4
+ import { PathLike, Stats } from 'node:fs';
5
+ type Position = number | bigint | null;
6
+ type OpenMode = string | number | undefined;
7
+ interface Callback<T extends unknown[] = []> {
8
+ (error?: Error | null, ...rest: T): void;
9
+ }
5
10
  export interface FileSystem {
6
- stat: typeof fs.stat;
7
- open: typeof fs.open;
8
- read: typeof fs.read;
9
- close: typeof fs.close;
11
+ close(fd: number, callback?: Callback): void;
12
+ read<T extends ArrayBufferView>(
13
+ fd: number,
14
+ buffer: T,
15
+ offset: number,
16
+ length: number,
17
+ position: Position,
18
+ callback: Callback<[bytesRead: number, buffer: T]>
19
+ ): void;
20
+ stat(path: PathLike, callback: Callback<[stats: Stats]>): void;
21
+ open(path: PathLike, flags: OpenMode, callback: Callback<[fd: number]>): void;
10
22
  }
11
23
  /**
12
24
  * @function stat
@@ -15,3 +27,4 @@ export interface FileSystem {
15
27
  * @param path The file path.
16
28
  */
17
29
  export declare function stat(fs: FileSystem, path: string): Promise<Stats | null>;
30
+ export {};
package/esm/utils/fs.js CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
+ * @module koa-files
2
3
  * @package koa-files
3
4
  * @license MIT
4
- * @version 4.1.7
5
+ * @version 5.0.1
5
6
  * @author nuintun <nuintun@qq.com>
6
7
  * @description A static files serving middleware for koa.
7
8
  * @see https://github.com/nuintun/koa-files#readme
package/esm/utils/hash.js CHANGED
@@ -1,13 +1,14 @@
1
1
  /**
2
+ * @module koa-files
2
3
  * @package koa-files
3
4
  * @license MIT
4
- * @version 4.1.7
5
+ * @version 5.0.1
5
6
  * @author nuintun <nuintun@qq.com>
6
7
  * @description A static files serving middleware for koa.
7
8
  * @see https://github.com/nuintun/koa-files#readme
8
9
  */
9
10
 
10
- import { getRandomValues } from 'crypto';
11
+ import { getRandomValues } from 'node:crypto';
11
12
 
12
13
  /**
13
14
  * @module hash
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @module http
3
3
  */
4
- import { Stats } from 'fs';
5
4
  import { Context } from 'koa';
6
- import { Buffer } from 'buffer';
5
+ import { Stats } from 'node:fs';
6
+ import { Buffer } from 'node:buffer';
7
7
  export interface Range {
8
8
  offset: number;
9
9
  length: number;
package/esm/utils/http.js CHANGED
@@ -1,14 +1,15 @@
1
1
  /**
2
+ * @module koa-files
2
3
  * @package koa-files
3
4
  * @license MIT
4
- * @version 4.1.7
5
+ * @version 5.0.1
5
6
  * @author nuintun <nuintun@qq.com>
6
7
  * @description A static files serving middleware for koa.
7
8
  * @see https://github.com/nuintun/koa-files#readme
8
9
  */
9
10
 
10
- import { Buffer } from 'buffer';
11
11
  import { generate } from './hash.js';
12
+ import { Buffer } from 'node:buffer';
12
13
  import parseRange from 'range-parser';
13
14
 
14
15
  /**
@@ -24,7 +25,7 @@ const SINGLE_ETAG_RE = /^(?:W\/)?"[ !#-\x7E\x80-\xFF]+"$/;
24
25
  function decodeURI(URI) {
25
26
  try {
26
27
  return decodeURIComponent(URI);
27
- } catch (_a) {
28
+ } catch {
28
29
  return -1;
29
30
  }
30
31
  }
@@ -156,7 +157,9 @@ function parseRanges(context, stats) {
156
157
  const length = end - start + 1;
157
158
  const head = index > 0 ? '\r\n' : '';
158
159
  const contentRange = `Content-Range: bytes ${start}-${end}/${size}`;
159
- const prefix = Buffer.from(`${head}--${boundary}\r\n${contentType}\r\n${contentRange}\r\n\r\n`);
160
+ const prefix = Buffer.from(
161
+ `${head}--${boundary}\r\n${contentType}\r\n${contentRange}\r\n\r\n`
162
+ );
160
163
  // Compute Content-Length
161
164
  contentLength += prefix.length + length;
162
165
  // Cache range.
package/esm/utils/path.js CHANGED
@@ -1,13 +1,14 @@
1
1
  /**
2
+ * @module koa-files
2
3
  * @package koa-files
3
4
  * @license MIT
4
- * @version 4.1.7
5
+ * @version 5.0.1
5
6
  * @author nuintun <nuintun@qq.com>
6
7
  * @description A static files serving middleware for koa.
7
8
  * @see https://github.com/nuintun/koa-files#readme
8
9
  */
9
10
 
10
- import { relative, isAbsolute } from 'path';
11
+ import { relative, isAbsolute } from 'node:path';
11
12
 
12
13
  /**
13
14
  * @module path
package/esm/utils/type.js CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
+ * @module koa-files
2
3
  * @package koa-files
3
4
  * @license MIT
4
- * @version 4.1.7
5
+ * @version 5.0.1
5
6
  * @author nuintun <nuintun@qq.com>
6
7
  * @description A static files serving middleware for koa.
7
8
  * @see https://github.com/nuintun/koa-files#readme
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "koa-files",
3
- "version": "4.1.7",
3
+ "version": "5.0.1",
4
4
  "description": "A static files serving middleware for koa.",
5
5
  "type": "module",
6
- "main": "cjs/index.cjs",
7
- "module": "esm/index.js",
6
+ "sideEffects": false,
8
7
  "exports": {
9
8
  ".": {
10
9
  "import": "./esm/index.js",
@@ -31,7 +30,7 @@
31
30
  "middleware"
32
31
  ],
33
32
  "engines": {
34
- "node": ">=8.0.0"
33
+ "node": ">=18"
35
34
  },
36
35
  "author": {
37
36
  "name": "nuintun",
@@ -51,13 +50,13 @@
51
50
  "@rollup/plugin-typescript": "^12.3.0",
52
51
  "@types/etag": "^1.8.4",
53
52
  "@types/koa": "^3.0.2",
54
- "@types/node": "^25.5.0",
53
+ "@types/node": "^25.5.2",
55
54
  "@types/range-parser": "^1.2.7",
56
- "dts-paths": "^2.1.1",
57
- "koa": "^3.1.2",
55
+ "dts-paths": "^2.2.1",
56
+ "koa": "^3.2.0",
58
57
  "prettier": "^3.8.1",
59
58
  "rimraf": "^6.1.3",
60
- "rollup": "^4.60.0",
59
+ "rollup": "^4.60.1",
61
60
  "typescript": "^6.0.2"
62
61
  },
63
62
  "peerDependencies": {
@@ -65,12 +64,12 @@
65
64
  },
66
65
  "scripts": {
67
66
  "lint": "tsc --noEmit",
68
- "pretest": "pnpm build:main",
69
- "test": "node tests/index.js",
70
- "clean": "node tools/clean.js",
71
- "build:cjs": "rollup -c tools/rollup.cjs.js",
72
- "build:esm": "rollup -c tools/rollup.esm.js",
73
- "build:fix-types": "node tools/fix-types.js",
67
+ "pretest": "pnpm build",
68
+ "clean": "node tools/clean.ts",
69
+ "test": "node --test tests/index.ts",
70
+ "build:cjs": "rollup -c tools/rollup.cjs.ts",
71
+ "build:esm": "rollup -c tools/rollup.esm.ts",
72
+ "build:fix-types": "node tools/fix-types.ts",
74
73
  "build": "pnpm clean && pnpm build:main && pnpm format",
75
74
  "format": "prettier --write . --ignore-path .prettierignore",
76
75
  "build:main": "pnpm build:cjs && pnpm build:esm && pnpm build:fix-types"