koa-files 3.1.6 → 3.1.7

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.6
4
+ * @version 3.1.7
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/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.6
4
+ * @version 3.1.7
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.6
4
+ * @version 3.1.7
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.6
4
+ * @version 3.1.7
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.6
4
+ * @version 3.1.7
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.6
4
+ * @version 3.1.7
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.6
4
+ * @version 3.1.7
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
@@ -126,7 +126,7 @@ class FileReadStream extends stream.Readable {
126
126
  const position = range.offset + bytesRead;
127
127
  const buffer$1 = buffer.Buffer.allocUnsafeSlow(Math.min(size, range.length - bytesRead));
128
128
  // Read file range.
129
- this.fs.read(fd, buffer$1, 0, buffer$1.length, position, (readError, bytesRead, buffer) => {
129
+ this.fs.read(fd, buffer$1, 0, buffer$1.length, position, (readError, bytesRead, buffer$1) => {
130
130
  this.reading = false;
131
131
  // Tell ._destroy() that it's safe to close the fd now.
132
132
  if (this.destroyed) {
@@ -136,7 +136,15 @@ class FileReadStream extends stream.Readable {
136
136
  this.destroy(readError);
137
137
  } else {
138
138
  if (bytesRead > 0) {
139
- this.push(buffer.subarray(0, bytesRead));
139
+ if (bytesRead !== buffer$1.length) {
140
+ // Slow path. Shrink to fit.
141
+ // Copy instead of slice so that we don't retain
142
+ // large backing buffer for small reads.
143
+ const chunk = buffer.Buffer.allocUnsafeSlow(bytesRead);
144
+ buffer$1.copy(chunk, 0, 0, bytesRead);
145
+ buffer$1 = chunk;
146
+ }
147
+ this.push(buffer$1);
140
148
  this.bytesRead += bytesRead;
141
149
  } else {
142
150
  this.bytesRead = 0;
package/esm/Service.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.6
4
+ * @version 3.1.7
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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 3.1.6
4
+ * @version 3.1.7
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.6
4
+ * @version 3.1.7
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.6
4
+ * @version 3.1.7
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.6
4
+ * @version 3.1.7
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.6
4
+ * @version 3.1.7
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.6
4
+ * @version 3.1.7
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
@@ -134,7 +134,15 @@ class FileReadStream extends Readable {
134
134
  this.destroy(readError);
135
135
  } else {
136
136
  if (bytesRead > 0) {
137
- this.push(buffer.subarray(0, bytesRead));
137
+ if (bytesRead !== buffer.length) {
138
+ // Slow path. Shrink to fit.
139
+ // Copy instead of slice so that we don't retain
140
+ // large backing buffer for small reads.
141
+ const chunk = Buffer.allocUnsafeSlow(bytesRead);
142
+ buffer.copy(chunk, 0, 0, bytesRead);
143
+ buffer = chunk;
144
+ }
145
+ this.push(buffer);
138
146
  this.bytesRead += bytesRead;
139
147
  } else {
140
148
  this.bytesRead = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koa-files",
3
- "version": "3.1.6",
3
+ "version": "3.1.7",
4
4
  "description": "A static files serving middleware for koa.",
5
5
  "type": "module",
6
6
  "main": "cjs/index.cjs",