koa-files 3.1.10 → 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.10
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
@@ -138,10 +138,8 @@ class Service {
138
138
  }
139
139
  // Get options.
140
140
  const { options } = this;
141
- // Get file system.
142
- const { fs } = options;
143
141
  // File stats.
144
- const stats = await fs$1.stat(fs, path$2);
142
+ const stats = await fs$1.stat(options.fs, path$2);
145
143
  // Check file stats.
146
144
  if (
147
145
  // File not exist (404 | 500).
@@ -193,10 +191,8 @@ class Service {
193
191
  if (ranges === -2) {
194
192
  return context.throw(400);
195
193
  }
196
- // Get stream options.
197
- const { highWaterMark } = options;
198
194
  // Set response body.
199
- context.body = new stream.FileReadStream(path$2, ranges, { fs, highWaterMark });
195
+ context.body = new stream.FileReadStream(path$2, ranges, options);
200
196
  // File found.
201
197
  return true;
202
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.10
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.10
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.10
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.10
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.10
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.10
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.10
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
@@ -129,10 +129,8 @@ class Service {
129
129
  }
130
130
  // Get options.
131
131
  const { options } = this;
132
- // Get file system.
133
- const { fs } = options;
134
132
  // File stats.
135
- const stats = await stat(fs, path);
133
+ const stats = await stat(options.fs, path);
136
134
  // Check file stats.
137
135
  if (
138
136
  // File not exist (404 | 500).
@@ -184,10 +182,8 @@ class Service {
184
182
  if (ranges === -2) {
185
183
  return context.throw(400);
186
184
  }
187
- // Get stream options.
188
- const { highWaterMark } = options;
189
185
  // Set response body.
190
- context.body = new FileReadStream(path, ranges, { fs, highWaterMark });
186
+ context.body = new FileReadStream(path, ranges, options);
191
187
  // File found.
192
188
  return true;
193
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.10
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.10
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.10
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.10
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.10
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.10
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.10",
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",
@@ -5,15 +5,15 @@ 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
  }