koa-files 3.1.9 → 3.1.11
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/cjs/Service.cjs +5 -5
- package/cjs/index.cjs +1 -1
- package/cjs/utils/fs.cjs +1 -1
- package/cjs/utils/hash.cjs +1 -1
- package/cjs/utils/http.cjs +1 -1
- package/cjs/utils/path.cjs +1 -1
- package/cjs/utils/stream.cjs +3 -3
- package/esm/Service.js +5 -5
- package/esm/index.js +1 -1
- package/esm/utils/fs.js +1 -1
- package/esm/utils/hash.js +1 -1
- package/esm/utils/http.js +1 -1
- package/esm/utils/path.js +1 -1
- package/esm/utils/stream.js +3 -3
- package/package.json +1 -1
- package/types/Service.d.ts +2 -2
- package/types/utils/stream.d.ts +6 -6
package/cjs/Service.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package koa-files
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 3.1.
|
|
4
|
+
* @version 3.1.11
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A static files serving middleware for koa.
|
|
7
7
|
* @see https://github.com/nuintun/koa-files#readme
|
|
@@ -136,8 +136,10 @@ class Service {
|
|
|
136
136
|
if (this.isIgnore(path$2)) {
|
|
137
137
|
return false;
|
|
138
138
|
}
|
|
139
|
+
// Get options.
|
|
140
|
+
const { options } = this;
|
|
139
141
|
// File stats.
|
|
140
|
-
const stats = await fs$1.stat(
|
|
142
|
+
const stats = await fs$1.stat(options.fs, path$2);
|
|
141
143
|
// Check file stats.
|
|
142
144
|
if (
|
|
143
145
|
// File not exist (404 | 500).
|
|
@@ -189,10 +191,8 @@ class Service {
|
|
|
189
191
|
if (ranges === -2) {
|
|
190
192
|
return context.throw(400);
|
|
191
193
|
}
|
|
192
|
-
// Get stream options.
|
|
193
|
-
const { fs, highWaterMark } = this.options;
|
|
194
194
|
// Set response body.
|
|
195
|
-
context.body = new stream.FileReadStream(path$2, ranges,
|
|
195
|
+
context.body = new stream.FileReadStream(path$2, ranges, options);
|
|
196
196
|
// File found.
|
|
197
197
|
return true;
|
|
198
198
|
}
|
package/cjs/index.cjs
CHANGED
package/cjs/utils/fs.cjs
CHANGED
package/cjs/utils/hash.cjs
CHANGED
package/cjs/utils/http.cjs
CHANGED
package/cjs/utils/path.cjs
CHANGED
package/cjs/utils/stream.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package koa-files
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 3.1.
|
|
4
|
+
* @version 3.1.11
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A static files serving middleware for koa.
|
|
7
7
|
* @see https://github.com/nuintun/koa-files#readme
|
|
@@ -24,8 +24,8 @@ class FileReadStream extends stream.Readable {
|
|
|
24
24
|
* @param options The stream options.
|
|
25
25
|
*/
|
|
26
26
|
constructor(path, ranges, options) {
|
|
27
|
-
const { fs,
|
|
28
|
-
super({
|
|
27
|
+
const { fs, highWaterMark } = options;
|
|
28
|
+
super({ highWaterMark });
|
|
29
29
|
this.bytesRead = 0;
|
|
30
30
|
this.fd = null;
|
|
31
31
|
this.reading = false;
|
package/esm/Service.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package koa-files
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 3.1.
|
|
4
|
+
* @version 3.1.11
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A static files serving middleware for koa.
|
|
7
7
|
* @see https://github.com/nuintun/koa-files#readme
|
|
@@ -127,8 +127,10 @@ class Service {
|
|
|
127
127
|
if (this.isIgnore(path)) {
|
|
128
128
|
return false;
|
|
129
129
|
}
|
|
130
|
+
// Get options.
|
|
131
|
+
const { options } = this;
|
|
130
132
|
// File stats.
|
|
131
|
-
const stats = await stat(
|
|
133
|
+
const stats = await stat(options.fs, path);
|
|
132
134
|
// Check file stats.
|
|
133
135
|
if (
|
|
134
136
|
// File not exist (404 | 500).
|
|
@@ -180,10 +182,8 @@ class Service {
|
|
|
180
182
|
if (ranges === -2) {
|
|
181
183
|
return context.throw(400);
|
|
182
184
|
}
|
|
183
|
-
// Get stream options.
|
|
184
|
-
const { fs, highWaterMark } = this.options;
|
|
185
185
|
// Set response body.
|
|
186
|
-
context.body = new FileReadStream(path, ranges,
|
|
186
|
+
context.body = new FileReadStream(path, ranges, options);
|
|
187
187
|
// File found.
|
|
188
188
|
return true;
|
|
189
189
|
}
|
package/esm/index.js
CHANGED
package/esm/utils/fs.js
CHANGED
package/esm/utils/hash.js
CHANGED
package/esm/utils/http.js
CHANGED
package/esm/utils/path.js
CHANGED
package/esm/utils/stream.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package koa-files
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 3.1.
|
|
4
|
+
* @version 3.1.11
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A static files serving middleware for koa.
|
|
7
7
|
* @see https://github.com/nuintun/koa-files#readme
|
|
@@ -22,8 +22,8 @@ class FileReadStream extends Readable {
|
|
|
22
22
|
* @param options The stream options.
|
|
23
23
|
*/
|
|
24
24
|
constructor(path, ranges, options) {
|
|
25
|
-
const { fs,
|
|
26
|
-
super({
|
|
25
|
+
const { fs, highWaterMark } = options;
|
|
26
|
+
super({ highWaterMark });
|
|
27
27
|
this.bytesRead = 0;
|
|
28
28
|
this.fd = null;
|
|
29
29
|
this.reading = false;
|
package/package.json
CHANGED
package/types/Service.d.ts
CHANGED
package/types/utils/stream.d.ts
CHANGED
|
@@ -5,22 +5,22 @@ import { PathLike } from 'fs';
|
|
|
5
5
|
import { Buffer } from 'buffer';
|
|
6
6
|
import { FileSystem } from './fs';
|
|
7
7
|
import { Readable, ReadableOptions } from 'stream';
|
|
8
|
-
export interface Options extends Pick<ReadableOptions, 'encoding' | 'highWaterMark'> {
|
|
9
|
-
fs: FileSystem;
|
|
10
|
-
}
|
|
11
8
|
export interface Range {
|
|
12
9
|
offset: number;
|
|
13
10
|
length: number;
|
|
14
11
|
prefix?: Buffer;
|
|
15
12
|
suffix?: Buffer;
|
|
16
13
|
}
|
|
14
|
+
export interface Options extends Pick<ReadableOptions, 'highWaterMark'> {
|
|
15
|
+
fs: FileSystem;
|
|
16
|
+
}
|
|
17
17
|
interface Callback {
|
|
18
18
|
(error?: Error | null): void;
|
|
19
19
|
}
|
|
20
20
|
export declare class FileReadStream extends Readable {
|
|
21
|
-
private fs;
|
|
22
|
-
private path;
|
|
23
|
-
private ranges;
|
|
21
|
+
private readonly fs;
|
|
22
|
+
private readonly path;
|
|
23
|
+
private readonly ranges;
|
|
24
24
|
private bytesRead;
|
|
25
25
|
private fd;
|
|
26
26
|
private reading;
|