better code
Massimo Melina committed
Aug 3, 2023 at 17:48 UTC
dac34e7ec932c210d45e79e32f325b2ac3d76c99
3 files changed
+9
-4
src/QuickZipStream.ts
+2
-1
@@ -119,7 +119,8 @@ export class QuickZipStream extends Readable {
119
if (this.finished || this.destroyed) return
120
if (this.workingFile)
121
return this.workingFile.resume()
122
- const file = this.consumedCalculating.shift() || (await this.walker.next()).value as ZipSource
122
+ const file = this.consumedCalculating.shift()
123
+ || (await this.walker.next()).value as ZipSource
124
if (!file)
125
return this.closeArchive()
126
let { path, sourcePath, getData, size=0, ts=this.now, mode=0o40775 } = file
src/misc.ts
+5
-1
@@ -241,4 +241,8 @@ export function try_(cb: () => any, onException?: (e:any) => any) {
241
catch(e) {
242
return onException?.(e)
243
}
244
-}
\ No newline at end of file
244
+}
245
+
246
+export function throw_(err: any) {
247
+ throw err
248
+}
src/vfs.ts
+2
-2
@@ -12,7 +12,7 @@ import {
12
makeMatcher,
13
setHidden,
14
onlyTruthy,
15
- typedEntries
15
+ typedEntries, throw_
16
} from './misc'
17
import Koa from 'koa'
18
import _ from 'lodash'
@@ -250,7 +250,7 @@ export function statusCodeForMissingPerm(node: VfsNode, perm: keyof VfsPerm, ctx
250
}
251
return typeof who === 'boolean' ? (who ? 0 : HTTP_FORBIDDEN)
252
: who === WHO_ANY_ACCOUNT ? (ctx.state.account ? 0 : HTTP_UNAUTHORIZED)
253
- : (() => { throw Error('invalid permission: ' + who) })()
253
+ : throw_(Error('invalid permission: ' + JSON.stringify(who)))
254
}
255
}
256