feat: slowly transition to fs-jetpack

controllers/handlers/ServeStatic.js
controllers/middlewares/ServeStaticQuick.js
This commit is contained in:
Bobby 2022-10-04 04:20:38 +07:00
parent 6d103c1e28
commit 65d9a76071
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09
2 changed files with 8 additions and 7 deletions

View File

@ -19,10 +19,10 @@
const contentDisposition = require('content-disposition')
const etag = require('etag')
const fs = require('fs')
const fsPromises = require('fs/promises')
const jetpack = require('fs-jetpack')
const SimpleDataStore = require('./../utils/SimpleDataStore')
const errors = require('./../errorsController')
const paths = require('./../pathsController')
const utils = require('./../utilsController')
const serveUtils = require('./../utils/serveUtils')
const logger = require('./../../logger')
@ -106,7 +106,7 @@ class ServeStatic {
}
async #get (fullPath) {
const stat = await paths.stat(fullPath)
const stat = await fsPromises.stat(fullPath)
if (stat.isDirectory()) return
@ -237,7 +237,7 @@ class ServeStatic {
}
async #stream (req, res, fullPath, result) {
const readStream = fs.createReadStream(fullPath, result.options)
const readStream = jetpack.createReadStream(fullPath, result.options)
readStream.on('error', error => {
readStream.destroy()

View File

@ -21,7 +21,7 @@
const chokidar = require('chokidar')
const etag = require('etag')
const fs = require('fs')
const jetpack = require('fs-jetpack')
const serveUtils = require('./../utils/serveUtils')
const logger = require('./../../logger')
@ -70,7 +70,8 @@ class ServeStaticQuick {
this.files = new Map()
this.watcher = chokidar.watch(this.directory, {
alwaysStat: true,
// fs.Stats object is already always available with add/addDir/change events
alwaysStat: false,
awaitWriteFinish: {
pollInterval: 100,
stabilityThreshold: 500
@ -220,7 +221,7 @@ class ServeStaticQuick {
#stream (req, res, path, stat, result) {
const fullPath = this.directory + path
const readStream = fs.createReadStream(fullPath, result.options)
const readStream = jetpack.createReadStream(fullPath, result.options)
readStream.on('error', error => {
readStream.destroy()