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 CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.9
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(this.options.fs, path$2);
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, { fs, highWaterMark });
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.9
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
package/cjs/utils/fs.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.9
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.9
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.9
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.9
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.9
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, encoding, highWaterMark } = options;
28
- super({ encoding, highWaterMark });
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.9
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(this.options.fs, path);
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, { fs, highWaterMark });
186
+ context.body = new FileReadStream(path, ranges, options);
187
187
  // File found.
188
188
  return true;
189
189
  }
package/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.9
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
package/esm/utils/fs.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.9
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
package/esm/utils/hash.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.9
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
package/esm/utils/http.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.9
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
package/esm/utils/path.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.9
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.9
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, encoding, highWaterMark } = options;
26
- super({ encoding, highWaterMark });
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koa-files",
3
- "version": "3.1.9",
3
+ "version": "3.1.11",
4
4
  "description": "A static files serving middleware for koa.",
5
5
  "type": "module",
6
6
  "main": "cjs/index.cjs",
@@ -26,8 +26,8 @@ export interface Options {
26
26
  * @class Service
27
27
  */
28
28
  export default class Service {
29
- private root;
30
- private options;
29
+ private readonly root;
30
+ private readonly options;
31
31
  /**
32
32
  * @constructor
33
33
  * @description Create file service.
@@ -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;