mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-28 23:04:59 +02:00
Remove archiver-utils dependency
This commit is contained in:
parent
bca2cfda13
commit
3c5bf376b5
86 changed files with 17236 additions and 210 deletions
149
server/libs/archiver/archiverUtils/readableStream/ours/util.js
Normal file
149
server/libs/archiver/archiverUtils/readableStream/ours/util.js
Normal file
|
@ -0,0 +1,149 @@
|
|||
'use strict'
|
||||
|
||||
const bufferModule = require('buffer')
|
||||
|
||||
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor
|
||||
const Blob = globalThis.Blob || bufferModule.Blob
|
||||
/* eslint-disable indent */
|
||||
|
||||
const isBlob =
|
||||
typeof Blob !== 'undefined'
|
||||
? function isBlob(b) {
|
||||
// eslint-disable-next-line indent
|
||||
return b instanceof Blob
|
||||
}
|
||||
: function isBlob(b) {
|
||||
return false
|
||||
}
|
||||
/* eslint-enable indent */
|
||||
// This is a simplified version of AggregateError
|
||||
|
||||
class AggregateError extends Error {
|
||||
constructor(errors) {
|
||||
if (!Array.isArray(errors)) {
|
||||
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`)
|
||||
}
|
||||
|
||||
let message = ''
|
||||
|
||||
for (let i = 0; i < errors.length; i++) {
|
||||
message += ` ${errors[i].stack}\n`
|
||||
}
|
||||
|
||||
super(message)
|
||||
this.name = 'AggregateError'
|
||||
this.errors = errors
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
AggregateError,
|
||||
|
||||
once(callback) {
|
||||
let called = false
|
||||
return function (...args) {
|
||||
if (called) {
|
||||
return
|
||||
}
|
||||
|
||||
called = true
|
||||
callback.apply(this, args)
|
||||
}
|
||||
},
|
||||
|
||||
createDeferredPromise: function () {
|
||||
let resolve
|
||||
let reject // eslint-disable-next-line promise/param-names
|
||||
|
||||
const promise = new Promise((res, rej) => {
|
||||
resolve = res
|
||||
reject = rej
|
||||
})
|
||||
return {
|
||||
promise,
|
||||
resolve,
|
||||
reject
|
||||
}
|
||||
},
|
||||
|
||||
promisify(fn) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fn((err, ...args) => {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
|
||||
return resolve(...args)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
debuglog() {
|
||||
return function () {}
|
||||
},
|
||||
|
||||
format(format, ...args) {
|
||||
// Simplified version of https://nodejs.org/api/util.html#utilformatformat-args
|
||||
return format.replace(/%([sdifj])/g, function (...[_unused, type]) {
|
||||
const replacement = args.shift()
|
||||
|
||||
if (type === 'f') {
|
||||
return replacement.toFixed(6)
|
||||
} else if (type === 'j') {
|
||||
return JSON.stringify(replacement)
|
||||
} else if (type === 's' && typeof replacement === 'object') {
|
||||
const ctor = replacement.constructor !== Object ? replacement.constructor.name : ''
|
||||
return `${ctor} {}`.trim()
|
||||
} else {
|
||||
return replacement.toString()
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
inspect(value) {
|
||||
// Vastly simplified version of https://nodejs.org/api/util.html#utilinspectobject-options
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
if (value.includes("'")) {
|
||||
if (!value.includes('"')) {
|
||||
return `"${value}"`
|
||||
} else if (!value.includes('`') && !value.includes('${')) {
|
||||
return `\`${value}\``
|
||||
}
|
||||
}
|
||||
|
||||
return `'${value}'`
|
||||
|
||||
case 'number':
|
||||
if (isNaN(value)) {
|
||||
return 'NaN'
|
||||
} else if (Object.is(value, -0)) {
|
||||
return String(value)
|
||||
}
|
||||
|
||||
return value
|
||||
|
||||
case 'bigint':
|
||||
return `${String(value)}n`
|
||||
|
||||
case 'boolean':
|
||||
case 'undefined':
|
||||
return String(value)
|
||||
|
||||
case 'object':
|
||||
return '{}'
|
||||
}
|
||||
},
|
||||
|
||||
types: {
|
||||
isAsyncFunction(fn) {
|
||||
return fn instanceof AsyncFunction
|
||||
},
|
||||
|
||||
isArrayBufferView(arr) {
|
||||
return ArrayBuffer.isView(arr)
|
||||
}
|
||||
},
|
||||
isBlob
|
||||
}
|
||||
module.exports.promisify.custom = Symbol.for('nodejs.util.promisify.custom')
|
Loading…
Add table
Add a link
Reference in a new issue