koa-files 1.0.2 → 2.1.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 +10 -18
- package/cjs/Send.js +354 -0
- package/cjs/index.js +28 -0
- package/cjs/utils.js +138 -0
- package/esm/Send.js +352 -0
- package/esm/index.js +26 -0
- package/esm/utils.js +129 -0
- package/package.json +25 -14
- package/typings/Send.d.ts +69 -72
- package/typings/index.d.ts +3 -4
- package/.editorconfig +0 -39
- package/.prettierrc +0 -14
- package/index.js +0 -520
- package/rollup.config.js +0 -38
package/typings/Send.d.ts
CHANGED
|
@@ -4,82 +4,79 @@
|
|
|
4
4
|
* @author nuintun
|
|
5
5
|
*/
|
|
6
6
|
import { Context } from 'koa';
|
|
7
|
-
export declare type Ignore = false | ((path: string) => boolean);
|
|
8
7
|
export interface Options {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
lastModified?: boolean;
|
|
15
|
-
maxAge?: number;
|
|
8
|
+
etag?: boolean;
|
|
9
|
+
cacheControl?: string;
|
|
10
|
+
acceptRanges?: boolean;
|
|
11
|
+
lastModified?: boolean;
|
|
12
|
+
ignore?: (path: string) => boolean;
|
|
16
13
|
}
|
|
17
14
|
/**
|
|
18
15
|
* @class Send
|
|
19
16
|
*/
|
|
20
17
|
export default class Send {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
18
|
+
private ctx;
|
|
19
|
+
private root;
|
|
20
|
+
private options;
|
|
21
|
+
private path;
|
|
22
|
+
/**
|
|
23
|
+
* @constructor
|
|
24
|
+
* @param {Context} ctx
|
|
25
|
+
* @param {string} root
|
|
26
|
+
* @param {Options} options
|
|
27
|
+
*/
|
|
28
|
+
constructor(ctx: Context, root: string | undefined, options: Options);
|
|
29
|
+
/**
|
|
30
|
+
* @method isConditionalGET
|
|
31
|
+
* @returns {boolean}
|
|
32
|
+
*/
|
|
33
|
+
private isConditionalGET;
|
|
34
|
+
/**
|
|
35
|
+
* @method isPreconditionFailure
|
|
36
|
+
* @returns {boolean}
|
|
37
|
+
*/
|
|
38
|
+
private isPreconditionFailure;
|
|
39
|
+
/**
|
|
40
|
+
* @method isRangeFresh
|
|
41
|
+
* @returns {boolean}
|
|
42
|
+
*/
|
|
43
|
+
private isRangeFresh;
|
|
44
|
+
/**
|
|
45
|
+
* @method isIgnore
|
|
46
|
+
* @param {string} path
|
|
47
|
+
* @returns {boolean}
|
|
48
|
+
*/
|
|
49
|
+
private isIgnore;
|
|
50
|
+
/**
|
|
51
|
+
* @method parseRange
|
|
52
|
+
* @param {Stats} stats
|
|
53
|
+
* @returns {Ranges}
|
|
54
|
+
*/
|
|
55
|
+
private parseRange;
|
|
56
|
+
/**
|
|
57
|
+
* @method setupHeaders
|
|
58
|
+
* @param {string} path
|
|
59
|
+
* @param {Stats} stats
|
|
60
|
+
*/
|
|
61
|
+
private setupHeaders;
|
|
62
|
+
/**
|
|
63
|
+
* @method read
|
|
64
|
+
* @param {string} path
|
|
65
|
+
* @param {Range} range
|
|
66
|
+
* @param {PassThrough} buffer
|
|
67
|
+
* @param {boolean} end
|
|
68
|
+
* @returns {Promise<true>}
|
|
69
|
+
*/
|
|
70
|
+
private read;
|
|
71
|
+
/**
|
|
72
|
+
* @method send
|
|
73
|
+
* @param {string} path
|
|
74
|
+
* @param {Range[]} ranges
|
|
75
|
+
*/
|
|
76
|
+
private send;
|
|
77
|
+
/**
|
|
78
|
+
* @method response
|
|
79
|
+
* @returns {Promise<boolean>}
|
|
80
|
+
*/
|
|
81
|
+
response(): Promise<boolean>;
|
|
85
82
|
}
|
package/typings/index.d.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* @author nuintun
|
|
5
5
|
*/
|
|
6
6
|
import { Middleware } from 'koa';
|
|
7
|
-
import {
|
|
8
|
-
interface Options extends SendOptions {
|
|
9
|
-
|
|
7
|
+
import { Options as SendOptions } from './Send';
|
|
8
|
+
export interface Options extends SendOptions {
|
|
9
|
+
defer?: boolean;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* @function server
|
|
@@ -14,4 +14,3 @@ interface Options extends SendOptions {
|
|
|
14
14
|
* @param {Options} options
|
|
15
15
|
*/
|
|
16
16
|
export default function server(root: string, options?: Options): Middleware;
|
|
17
|
-
export { Options, Ignore };
|
package/.editorconfig
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# http://editorconfig.org
|
|
2
|
-
root = true
|
|
3
|
-
|
|
4
|
-
[*]
|
|
5
|
-
indent_style = space
|
|
6
|
-
indent_size = 2
|
|
7
|
-
end_of_line = lf
|
|
8
|
-
charset = utf-8
|
|
9
|
-
trim_trailing_whitespace = true
|
|
10
|
-
insert_final_newline = true
|
|
11
|
-
|
|
12
|
-
# Use 4 spaces for the Python files
|
|
13
|
-
[*.py]
|
|
14
|
-
indent_size = 4
|
|
15
|
-
max_line_length = 80
|
|
16
|
-
|
|
17
|
-
# The JSON files contain newlines inconsistently
|
|
18
|
-
[*.json]
|
|
19
|
-
insert_final_newline = ignore
|
|
20
|
-
|
|
21
|
-
# Minified JavaScript files shouldn't be changed
|
|
22
|
-
[*.min.js]
|
|
23
|
-
indent_style = ignore
|
|
24
|
-
insert_final_newline = ignore
|
|
25
|
-
|
|
26
|
-
# Makefiles always use tabs for indentation
|
|
27
|
-
[Makefile]
|
|
28
|
-
indent_style = tab
|
|
29
|
-
|
|
30
|
-
# Batch files use tabs for indentation
|
|
31
|
-
[*.bat]
|
|
32
|
-
indent_style = tab
|
|
33
|
-
|
|
34
|
-
[*.md]
|
|
35
|
-
trim_trailing_whitespace = false
|
|
36
|
-
|
|
37
|
-
[*.{cs,cshtml}]
|
|
38
|
-
indent_size = 4
|
|
39
|
-
charset = utf-8-bom
|