Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

20
deps/npm/node_modules/npm-registry-fetch/LICENSE.md generated vendored Normal file
View File

@ -0,0 +1,20 @@
<!-- This file is automatically added by @npmcli/template-oss. Do not edit. -->
ISC License
Copyright npm, Inc.
Permission to use, copy, modify, and/or distribute this
software for any purpose with or without fee is hereby
granted, provided that the above copyright notice and this
permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
USE OR PERFORMANCE OF THIS SOFTWARE.

181
deps/npm/node_modules/npm-registry-fetch/lib/auth.js generated vendored Normal file
View File

@ -0,0 +1,181 @@
'use strict'
const fs = require('fs')
const npa = require('npm-package-arg')
const { URL } = require('url')
// Find the longest registry key that is used for some kind of auth
// in the options. Returns the registry key and the auth config.
const regFromURI = (uri, opts) => {
const parsed = new URL(uri)
// try to find a config key indicating we have auth for this registry
// can be one of :_authToken, :_auth, :_password and :username, or
// :certfile and :keyfile
// We walk up the "path" until we're left with just //<host>[:<port>],
// stopping when we reach '//'.
let regKey = `//${parsed.host}${parsed.pathname}`
while (regKey.length > '//'.length) {
const authKey = hasAuth(regKey, opts)
// got some auth for this URI
if (authKey) {
return { regKey, authKey }
}
// can be either //host/some/path/:_auth or //host/some/path:_auth
// walk up by removing EITHER what's after the slash OR the slash itself
regKey = regKey.replace(/([^/]+|\/)$/, '')
}
return { regKey: false, authKey: null }
}
// Not only do we want to know if there is auth, but if we are calling `npm
// logout` we want to know what config value specifically provided it. This is
// so we can look up where the config came from to delete it (i.e. user vs
// project)
const hasAuth = (regKey, opts) => {
if (opts[`${regKey}:_authToken`]) {
return '_authToken'
}
if (opts[`${regKey}:_auth`]) {
return '_auth'
}
if (opts[`${regKey}:username`] && opts[`${regKey}:_password`]) {
// 'password' can be inferred to also be present
return 'username'
}
if (opts[`${regKey}:certfile`] && opts[`${regKey}:keyfile`]) {
// 'keyfile' can be inferred to also be present
return 'certfile'
}
return false
}
const sameHost = (a, b) => {
const parsedA = new URL(a)
const parsedB = new URL(b)
return parsedA.host === parsedB.host
}
const getRegistry = opts => {
const { spec } = opts
const { scope: specScope, subSpec } = spec ? npa(spec) : {}
const subSpecScope = subSpec && subSpec.scope
const scope = subSpec ? subSpecScope : specScope
const scopeReg = scope && opts[`${scope}:registry`]
return scopeReg || opts.registry
}
const maybeReadFile = file => {
try {
return fs.readFileSync(file, 'utf8')
} catch (er) {
if (er.code !== 'ENOENT') {
throw er
}
return null
}
}
const getAuth = (uri, opts = {}) => {
const { forceAuth } = opts
if (!uri) {
throw new Error('URI is required')
}
const { regKey, authKey } = regFromURI(uri, forceAuth || opts)
// we are only allowed to use what's in forceAuth if specified
if (forceAuth && !regKey) {
return new Auth({
// if we force auth we don't want to refer back to anything in config
regKey: false,
authKey: null,
scopeAuthKey: null,
token: forceAuth._authToken || forceAuth.token,
username: forceAuth.username,
password: forceAuth._password || forceAuth.password,
auth: forceAuth._auth || forceAuth.auth,
certfile: forceAuth.certfile,
keyfile: forceAuth.keyfile,
})
}
// no auth for this URI, but might have it for the registry
if (!regKey) {
const registry = getRegistry(opts)
if (registry && uri !== registry && sameHost(uri, registry)) {
return getAuth(registry, opts)
} else if (registry !== opts.registry) {
// If making a tarball request to a different base URI than the
// registry where we logged in, but the same auth SHOULD be sent
// to that artifact host, then we track where it was coming in from,
// and warn the user if we get a 4xx error on it.
const { regKey: scopeAuthKey, authKey: _authKey } = regFromURI(registry, opts)
return new Auth({ scopeAuthKey, regKey: scopeAuthKey, authKey: _authKey })
}
}
const {
[`${regKey}:_authToken`]: token,
[`${regKey}:username`]: username,
[`${regKey}:_password`]: password,
[`${regKey}:_auth`]: auth,
[`${regKey}:certfile`]: certfile,
[`${regKey}:keyfile`]: keyfile,
} = opts
return new Auth({
scopeAuthKey: null,
regKey,
authKey,
token,
auth,
username,
password,
certfile,
keyfile,
})
}
class Auth {
constructor ({
token,
auth,
username,
password,
scopeAuthKey,
certfile,
keyfile,
regKey,
authKey,
}) {
// same as regKey but only present for scoped auth. Should have been named scopeRegKey
this.scopeAuthKey = scopeAuthKey
// `${regKey}:${authKey}` will get you back to the auth config that gave us auth
this.regKey = regKey
this.authKey = authKey
this.token = null
this.auth = null
this.isBasicAuth = false
this.cert = null
this.key = null
if (token) {
this.token = token
} else if (auth) {
this.auth = auth
} else if (username && password) {
const p = Buffer.from(password, 'base64').toString('utf8')
this.auth = Buffer.from(`${username}:${p}`, 'utf8').toString('base64')
this.isBasicAuth = true
}
// mTLS may be used in conjunction with another auth method above
if (certfile && keyfile) {
const cert = maybeReadFile(certfile, 'utf-8')
const key = maybeReadFile(keyfile, 'utf-8')
if (cert && key) {
this.cert = cert
this.key = key
}
}
}
}
module.exports = getAuth

View File

@ -0,0 +1,108 @@
'use strict'
const errors = require('./errors.js')
const { Response } = require('minipass-fetch')
const defaultOpts = require('./default-opts.js')
const { log } = require('proc-log')
const { redact: cleanUrl } = require('@npmcli/redact')
/* eslint-disable-next-line max-len */
const moreInfoUrl = 'https://github.com/npm/cli/wiki/No-auth-for-URI,-but-auth-present-for-scoped-registry'
const checkResponse =
async ({ method, uri, res, startTime, auth, opts }) => {
opts = { ...defaultOpts, ...opts }
if (res.headers.has('npm-notice') && !res.headers.has('x-local-cache')) {
log.notice('', res.headers.get('npm-notice'))
}
if (res.status >= 400) {
logRequest(method, res, startTime)
if (auth && auth.scopeAuthKey && !auth.token && !auth.auth) {
// we didn't have auth for THIS request, but we do have auth for
// requests to the registry indicated by the spec's scope value.
// Warn the user.
log.warn('registry', `No auth for URI, but auth present for scoped registry.
URI: ${uri}
Scoped Registry Key: ${auth.scopeAuthKey}
More info here: ${moreInfoUrl}`)
}
return checkErrors(method, res, startTime, opts)
} else {
res.body.on('end', () => logRequest(method, res, startTime, opts))
if (opts.ignoreBody) {
res.body.resume()
return new Response(null, res)
}
return res
}
}
module.exports = checkResponse
function logRequest (method, res, startTime) {
const elapsedTime = Date.now() - startTime
const attempt = res.headers.get('x-fetch-attempts')
const attemptStr = attempt && attempt > 1 ? ` attempt #${attempt}` : ''
const cacheStatus = res.headers.get('x-local-cache-status')
const cacheStr = cacheStatus ? ` (cache ${cacheStatus})` : ''
const urlStr = cleanUrl(res.url)
// If make-fetch-happen reports a cache hit, then there was no fetch
if (cacheStatus === 'hit') {
log.http(
'cache',
`${urlStr} ${elapsedTime}ms${attemptStr}${cacheStr}`
)
} else {
log.http(
'fetch',
`${method.toUpperCase()} ${res.status} ${urlStr} ${elapsedTime}ms${attemptStr}${cacheStr}`
)
}
}
function checkErrors (method, res, startTime, opts) {
return res.buffer()
.catch(() => null)
.then(body => {
let parsed = body
try {
parsed = JSON.parse(body.toString('utf8'))
} catch {
// ignore errors
}
if (res.status === 401 && res.headers.get('www-authenticate')) {
const auth = res.headers.get('www-authenticate')
.split(/,\s*/)
.map(s => s.toLowerCase())
if (auth.indexOf('ipaddress') !== -1) {
throw new errors.HttpErrorAuthIPAddress(
method, res, parsed, opts.spec
)
} else if (auth.indexOf('otp') !== -1) {
throw new errors.HttpErrorAuthOTP(
method, res, parsed, opts.spec
)
} else {
throw new errors.HttpErrorAuthUnknown(
method, res, parsed, opts.spec
)
}
} else if (
res.status === 401 &&
body != null &&
/one-time pass/.test(body.toString('utf8'))
) {
// Heuristic for malformed OTP responses that don't include the
// www-authenticate header.
throw new errors.HttpErrorAuthOTP(
method, res, parsed, opts.spec
)
} else {
throw new errors.HttpErrorGeneral(
method, res, parsed, opts.spec
)
}
})
}

View File

@ -0,0 +1,19 @@
const pkg = require('../package.json')
module.exports = {
maxSockets: 12,
method: 'GET',
registry: 'https://registry.npmjs.org/',
timeout: 5 * 60 * 1000, // 5 minutes
strictSSL: true,
noProxy: process.env.NOPROXY,
userAgent: `${pkg.name
}@${
pkg.version
}/node@${
process.version
}+${
process.arch
} (${
process.platform
})`,
}

80
deps/npm/node_modules/npm-registry-fetch/lib/errors.js generated vendored Normal file
View File

@ -0,0 +1,80 @@
'use strict'
const { URL } = require('node:url')
function packageName (href) {
try {
let basePath = new URL(href).pathname.slice(1)
if (!basePath.match(/^-/)) {
basePath = basePath.split('/')
var index = basePath.indexOf('_rewrite')
if (index === -1) {
index = basePath.length - 1
} else {
index++
}
return decodeURIComponent(basePath[index])
}
} catch {
// this is ok
}
}
class HttpErrorBase extends Error {
constructor (method, res, body, spec) {
super()
this.name = this.constructor.name
this.headers = typeof res.headers?.raw === 'function' ? res.headers.raw() : res.headers
this.statusCode = res.status
this.code = `E${res.status}`
this.method = method
this.uri = res.url
this.body = body
this.pkgid = spec ? spec.toString() : packageName(res.url)
Error.captureStackTrace(this, this.constructor)
}
}
class HttpErrorGeneral extends HttpErrorBase {
constructor (method, res, body, spec) {
super(method, res, body, spec)
this.message = `${res.status} ${res.statusText} - ${
this.method.toUpperCase()
} ${
this.spec || this.uri
}${
(body && body.error) ? ' - ' + body.error : ''
}`
}
}
class HttpErrorAuthOTP extends HttpErrorBase {
constructor (method, res, body, spec) {
super(method, res, body, spec)
this.message = 'OTP required for authentication'
this.code = 'EOTP'
}
}
class HttpErrorAuthIPAddress extends HttpErrorBase {
constructor (method, res, body, spec) {
super(method, res, body, spec)
this.message = 'Login is not allowed from your IP address'
this.code = 'EAUTHIP'
}
}
class HttpErrorAuthUnknown extends HttpErrorBase {
constructor (method, res, body, spec) {
super(method, res, body, spec)
this.message = 'Unable to authenticate, need: ' + res.headers.get('www-authenticate')
}
}
module.exports = {
HttpErrorBase,
HttpErrorGeneral,
HttpErrorAuthOTP,
HttpErrorAuthIPAddress,
HttpErrorAuthUnknown,
}

247
deps/npm/node_modules/npm-registry-fetch/lib/index.js generated vendored Normal file
View File

@ -0,0 +1,247 @@
'use strict'
const { HttpErrorAuthOTP } = require('./errors.js')
const checkResponse = require('./check-response.js')
const getAuth = require('./auth.js')
const fetch = require('make-fetch-happen')
const JSONStream = require('./json-stream')
const npa = require('npm-package-arg')
const qs = require('querystring')
const url = require('url')
const zlib = require('minizlib')
const { Minipass } = require('minipass')
const defaultOpts = require('./default-opts.js')
// WhatWG URL throws if it's not fully resolved
const urlIsValid = u => {
try {
return !!new url.URL(u)
} catch (_) {
return false
}
}
module.exports = regFetch
function regFetch (uri, /* istanbul ignore next */ opts_ = {}) {
const opts = {
...defaultOpts,
...opts_,
}
// if we did not get a fully qualified URI, then we look at the registry
// config or relevant scope to resolve it.
const uriValid = urlIsValid(uri)
let registry = opts.registry || defaultOpts.registry
if (!uriValid) {
registry = opts.registry = (
(opts.spec && pickRegistry(opts.spec, opts)) ||
opts.registry ||
registry
)
uri = `${
registry.trim().replace(/\/?$/g, '')
}/${
uri.trim().replace(/^\//, '')
}`
// asserts that this is now valid
new url.URL(uri)
}
const method = opts.method || 'GET'
// through that takes into account the scope, the prefix of `uri`, etc
const startTime = Date.now()
const auth = getAuth(uri, opts)
const headers = getHeaders(uri, auth, opts)
let body = opts.body
const bodyIsStream = Minipass.isStream(body)
const bodyIsPromise = body &&
typeof body === 'object' &&
typeof body.then === 'function'
if (
body && !bodyIsStream && !bodyIsPromise && typeof body !== 'string' && !Buffer.isBuffer(body)
) {
headers['content-type'] = headers['content-type'] || 'application/json'
body = JSON.stringify(body)
} else if (body && !headers['content-type']) {
headers['content-type'] = 'application/octet-stream'
}
if (opts.gzip) {
headers['content-encoding'] = 'gzip'
if (bodyIsStream) {
const gz = new zlib.Gzip()
body.on('error', /* istanbul ignore next: unlikely and hard to test */
err => gz.emit('error', err))
body = body.pipe(gz)
} else if (!bodyIsPromise) {
body = new zlib.Gzip().end(body).concat()
}
}
const parsed = new url.URL(uri)
if (opts.query) {
const q = typeof opts.query === 'string' ? qs.parse(opts.query)
: opts.query
Object.keys(q).forEach(key => {
if (q[key] !== undefined) {
parsed.searchParams.set(key, q[key])
}
})
uri = url.format(parsed)
}
if (parsed.searchParams.get('write') === 'true' && method === 'GET') {
// do not cache, because this GET is fetching a rev that will be
// used for a subsequent PUT or DELETE, so we need to conditionally
// update cache.
opts.offline = false
opts.preferOffline = false
opts.preferOnline = true
}
const doFetch = async fetchBody => {
const p = fetch(uri, {
agent: opts.agent,
algorithms: opts.algorithms,
body: fetchBody,
cache: getCacheMode(opts),
cachePath: opts.cache,
ca: opts.ca,
cert: auth.cert || opts.cert,
headers,
integrity: opts.integrity,
key: auth.key || opts.key,
localAddress: opts.localAddress,
maxSockets: opts.maxSockets,
memoize: opts.memoize,
method: method,
noProxy: opts.noProxy,
proxy: opts.httpsProxy || opts.proxy,
retry: opts.retry ? opts.retry : {
retries: opts.fetchRetries,
factor: opts.fetchRetryFactor,
minTimeout: opts.fetchRetryMintimeout,
maxTimeout: opts.fetchRetryMaxtimeout,
},
strictSSL: opts.strictSSL,
timeout: opts.timeout || 30 * 1000,
}).then(res => checkResponse({
method,
uri,
res,
registry,
startTime,
auth,
opts,
}))
if (typeof opts.otpPrompt === 'function') {
return p.catch(async er => {
if (er instanceof HttpErrorAuthOTP) {
let otp
// if otp fails to complete, we fail with that failure
try {
otp = await opts.otpPrompt()
} catch (_) {
// ignore this error
}
// if no otp provided, or otpPrompt errored, throw the original HTTP error
if (!otp) {
throw er
}
return regFetch(uri, { ...opts, otp })
}
throw er
})
} else {
return p
}
}
return Promise.resolve(body).then(doFetch)
}
module.exports.getAuth = getAuth
module.exports.json = fetchJSON
function fetchJSON (uri, opts) {
return regFetch(uri, opts).then(res => res.json())
}
module.exports.json.stream = fetchJSONStream
function fetchJSONStream (uri, jsonPath,
/* istanbul ignore next */ opts_ = {}) {
const opts = { ...defaultOpts, ...opts_ }
const parser = JSONStream.parse(jsonPath, opts.mapJSON)
regFetch(uri, opts).then(res =>
res.body.on('error',
/* istanbul ignore next: unlikely and difficult to test */
er => parser.emit('error', er)).pipe(parser)
).catch(er => parser.emit('error', er))
return parser
}
module.exports.pickRegistry = pickRegistry
function pickRegistry (spec, opts = {}) {
spec = npa(spec)
let registry = spec.scope &&
opts[spec.scope.replace(/^@?/, '@') + ':registry']
if (!registry && opts.scope) {
registry = opts[opts.scope.replace(/^@?/, '@') + ':registry']
}
if (!registry) {
registry = opts.registry || defaultOpts.registry
}
return registry
}
function getCacheMode (opts) {
return opts.offline ? 'only-if-cached'
: opts.preferOffline ? 'force-cache'
: opts.preferOnline ? 'no-cache'
: 'default'
}
function getHeaders (uri, auth, opts) {
const headers = Object.assign({
'user-agent': opts.userAgent,
}, opts.headers || {})
if (opts.authType) {
headers['npm-auth-type'] = opts.authType
}
if (opts.scope) {
headers['npm-scope'] = opts.scope
}
if (opts.npmSession) {
headers['npm-session'] = opts.npmSession
}
if (opts.npmCommand) {
headers['npm-command'] = opts.npmCommand
}
// If a tarball is hosted on a different place than the manifest, only send
// credentials on `alwaysAuth`
if (auth.token) {
headers.authorization = `Bearer ${auth.token}`
} else if (auth.auth) {
headers.authorization = `Basic ${auth.auth}`
}
if (opts.otp) {
headers['npm-otp'] = opts.otp
}
return headers
}

View File

@ -0,0 +1,223 @@
const Parser = require('jsonparse')
const { Minipass } = require('minipass')
class JSONStreamError extends Error {
constructor (err, caller) {
super(err.message)
Error.captureStackTrace(this, caller || this.constructor)
}
get name () {
return 'JSONStreamError'
}
}
const check = (x, y) =>
typeof x === 'string' ? String(y) === x
: x && typeof x.test === 'function' ? x.test(y)
: typeof x === 'boolean' || typeof x === 'object' ? x
: typeof x === 'function' ? x(y)
: false
class JSONStream extends Minipass {
#count = 0
#ending = false
#footer = null
#header = null
#map = null
#onTokenOriginal
#parser
#path = null
#root = null
constructor (opts) {
super({
...opts,
objectMode: true,
})
const parser = this.#parser = new Parser()
parser.onValue = value => this.#onValue(value)
this.#onTokenOriginal = parser.onToken
parser.onToken = (token, value) => this.#onToken(token, value)
parser.onError = er => this.#onError(er)
this.#path = typeof opts.path === 'string'
? opts.path.split('.').map(e =>
e === '$*' ? { emitKey: true }
: e === '*' ? true
: e === '' ? { recurse: true }
: e)
: Array.isArray(opts.path) && opts.path.length ? opts.path
: null
if (typeof opts.map === 'function') {
this.#map = opts.map
}
}
#setHeaderFooter (key, value) {
// header has not been emitted yet
if (this.#header !== false) {
this.#header = this.#header || {}
this.#header[key] = value
}
// footer has not been emitted yet but header has
if (this.#footer !== false && this.#header === false) {
this.#footer = this.#footer || {}
this.#footer[key] = value
}
}
#onError (er) {
// error will always happen during a write() call.
const caller = this.#ending ? this.end : this.write
this.#ending = false
return this.emit('error', new JSONStreamError(er, caller))
}
#onToken (token, value) {
const parser = this.#parser
this.#onTokenOriginal.call(this.#parser, token, value)
if (parser.stack.length === 0) {
if (this.#root) {
const root = this.#root
if (!this.#path) {
super.write(root)
}
this.#root = null
this.#count = 0
}
}
}
#onValue (value) {
const parser = this.#parser
// the LAST onValue encountered is the root object.
// just overwrite it each time.
this.#root = value
if (!this.#path) {
return
}
let i = 0 // iterates on path
let j = 0 // iterates on stack
let emitKey = false
while (i < this.#path.length) {
const key = this.#path[i]
j++
if (key && !key.recurse) {
const c = (j === parser.stack.length) ? parser : parser.stack[j]
if (!c) {
return
}
if (!check(key, c.key)) {
this.#setHeaderFooter(c.key, value)
return
}
emitKey = !!key.emitKey
i++
} else {
i++
if (i >= this.#path.length) {
return
}
const nextKey = this.#path[i]
if (!nextKey) {
return
}
while (true) {
const c = (j === parser.stack.length) ? parser : parser.stack[j]
if (!c) {
return
}
if (check(nextKey, c.key)) {
i++
if (!Object.isFrozen(parser.stack[j])) {
parser.stack[j].value = null
}
break
} else {
this.#setHeaderFooter(c.key, value)
}
j++
}
}
}
// emit header
if (this.#header) {
const header = this.#header
this.#header = false
this.emit('header', header)
}
if (j !== parser.stack.length) {
return
}
this.#count++
const actualPath = parser.stack.slice(1)
.map(e => e.key).concat([parser.key])
if (value !== null && value !== undefined) {
const data = this.#map ? this.#map(value, actualPath) : value
if (data !== null && data !== undefined) {
const emit = emitKey ? { value: data } : data
if (emitKey) {
emit.key = parser.key
}
super.write(emit)
}
}
if (parser.value) {
delete parser.value[parser.key]
}
for (const k of parser.stack) {
k.value = null
}
}
write (chunk, encoding) {
if (typeof chunk === 'string') {
chunk = Buffer.from(chunk, encoding)
} else if (!Buffer.isBuffer(chunk)) {
return this.emit('error', new TypeError(
'Can only parse JSON from string or buffer input'))
}
this.#parser.write(chunk)
return this.flowing
}
end (chunk, encoding) {
this.#ending = true
if (chunk) {
this.write(chunk, encoding)
}
const h = this.#header
this.#header = null
const f = this.#footer
this.#footer = null
if (h) {
this.emit('header', h)
}
if (f) {
this.emit('footer', f)
}
return super.end()
}
static get JSONStreamError () {
return JSONStreamError
}
static parse (path, map) {
return new JSONStream({ path, map })
}
}
module.exports = JSONStream

View File

@ -0,0 +1,26 @@
Minizlib was created by Isaac Z. Schlueter.
It is a derivative work of the Node.js project.
"""
Copyright (c) 2017-2023 Isaac Z. Schlueter and Contributors
Copyright (c) 2017-2023 Node.js contributors. All rights reserved.
Copyright (c) 2017-2023 Joyent, Inc. and other Node contributors. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""

View File

@ -0,0 +1,123 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.constants = void 0;
// Update with any zlib constants that are added or changed in the future.
// Node v6 didn't export this, so we just hard code the version and rely
// on all the other hard-coded values from zlib v4736. When node v6
// support drops, we can just export the realZlibConstants object.
const zlib_1 = __importDefault(require("zlib"));
/* c8 ignore start */
const realZlibConstants = zlib_1.default.constants || { ZLIB_VERNUM: 4736 };
/* c8 ignore stop */
exports.constants = Object.freeze(Object.assign(Object.create(null), {
Z_NO_FLUSH: 0,
Z_PARTIAL_FLUSH: 1,
Z_SYNC_FLUSH: 2,
Z_FULL_FLUSH: 3,
Z_FINISH: 4,
Z_BLOCK: 5,
Z_OK: 0,
Z_STREAM_END: 1,
Z_NEED_DICT: 2,
Z_ERRNO: -1,
Z_STREAM_ERROR: -2,
Z_DATA_ERROR: -3,
Z_MEM_ERROR: -4,
Z_BUF_ERROR: -5,
Z_VERSION_ERROR: -6,
Z_NO_COMPRESSION: 0,
Z_BEST_SPEED: 1,
Z_BEST_COMPRESSION: 9,
Z_DEFAULT_COMPRESSION: -1,
Z_FILTERED: 1,
Z_HUFFMAN_ONLY: 2,
Z_RLE: 3,
Z_FIXED: 4,
Z_DEFAULT_STRATEGY: 0,
DEFLATE: 1,
INFLATE: 2,
GZIP: 3,
GUNZIP: 4,
DEFLATERAW: 5,
INFLATERAW: 6,
UNZIP: 7,
BROTLI_DECODE: 8,
BROTLI_ENCODE: 9,
Z_MIN_WINDOWBITS: 8,
Z_MAX_WINDOWBITS: 15,
Z_DEFAULT_WINDOWBITS: 15,
Z_MIN_CHUNK: 64,
Z_MAX_CHUNK: Infinity,
Z_DEFAULT_CHUNK: 16384,
Z_MIN_MEMLEVEL: 1,
Z_MAX_MEMLEVEL: 9,
Z_DEFAULT_MEMLEVEL: 8,
Z_MIN_LEVEL: -1,
Z_MAX_LEVEL: 9,
Z_DEFAULT_LEVEL: -1,
BROTLI_OPERATION_PROCESS: 0,
BROTLI_OPERATION_FLUSH: 1,
BROTLI_OPERATION_FINISH: 2,
BROTLI_OPERATION_EMIT_METADATA: 3,
BROTLI_MODE_GENERIC: 0,
BROTLI_MODE_TEXT: 1,
BROTLI_MODE_FONT: 2,
BROTLI_DEFAULT_MODE: 0,
BROTLI_MIN_QUALITY: 0,
BROTLI_MAX_QUALITY: 11,
BROTLI_DEFAULT_QUALITY: 11,
BROTLI_MIN_WINDOW_BITS: 10,
BROTLI_MAX_WINDOW_BITS: 24,
BROTLI_LARGE_MAX_WINDOW_BITS: 30,
BROTLI_DEFAULT_WINDOW: 22,
BROTLI_MIN_INPUT_BLOCK_BITS: 16,
BROTLI_MAX_INPUT_BLOCK_BITS: 24,
BROTLI_PARAM_MODE: 0,
BROTLI_PARAM_QUALITY: 1,
BROTLI_PARAM_LGWIN: 2,
BROTLI_PARAM_LGBLOCK: 3,
BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: 4,
BROTLI_PARAM_SIZE_HINT: 5,
BROTLI_PARAM_LARGE_WINDOW: 6,
BROTLI_PARAM_NPOSTFIX: 7,
BROTLI_PARAM_NDIRECT: 8,
BROTLI_DECODER_RESULT_ERROR: 0,
BROTLI_DECODER_RESULT_SUCCESS: 1,
BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: 2,
BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: 3,
BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: 0,
BROTLI_DECODER_PARAM_LARGE_WINDOW: 1,
BROTLI_DECODER_NO_ERROR: 0,
BROTLI_DECODER_SUCCESS: 1,
BROTLI_DECODER_NEEDS_MORE_INPUT: 2,
BROTLI_DECODER_NEEDS_MORE_OUTPUT: 3,
BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: -1,
BROTLI_DECODER_ERROR_FORMAT_RESERVED: -2,
BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: -3,
BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: -4,
BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: -5,
BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: -6,
BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: -7,
BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: -8,
BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: -9,
BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: -10,
BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: -11,
BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: -12,
BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: -13,
BROTLI_DECODER_ERROR_FORMAT_PADDING_1: -14,
BROTLI_DECODER_ERROR_FORMAT_PADDING_2: -15,
BROTLI_DECODER_ERROR_FORMAT_DISTANCE: -16,
BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: -19,
BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: -20,
BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: -21,
BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: -22,
BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: -25,
BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: -26,
BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: -27,
BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: -30,
BROTLI_DECODER_ERROR_UNREACHABLE: -31,
}, realZlibConstants));
//# sourceMappingURL=constants.js.map

View File

@ -0,0 +1,392 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BrotliDecompress = exports.BrotliCompress = exports.Brotli = exports.Unzip = exports.InflateRaw = exports.DeflateRaw = exports.Gunzip = exports.Gzip = exports.Inflate = exports.Deflate = exports.Zlib = exports.ZlibError = exports.constants = void 0;
const assert_1 = __importDefault(require("assert"));
const buffer_1 = require("buffer");
const minipass_1 = require("minipass");
const realZlib = __importStar(require("zlib"));
const constants_js_1 = require("./constants.js");
var constants_js_2 = require("./constants.js");
Object.defineProperty(exports, "constants", { enumerable: true, get: function () { return constants_js_2.constants; } });
const OriginalBufferConcat = buffer_1.Buffer.concat;
const desc = Object.getOwnPropertyDescriptor(buffer_1.Buffer, 'concat');
const noop = (args) => args;
const passthroughBufferConcat = desc?.writable === true || desc?.set !== undefined
? (makeNoOp) => {
buffer_1.Buffer.concat = makeNoOp ? noop : OriginalBufferConcat;
}
: (_) => { };
const _superWrite = Symbol('_superWrite');
class ZlibError extends Error {
code;
errno;
constructor(err) {
super('zlib: ' + err.message);
this.code = err.code;
this.errno = err.errno;
/* c8 ignore next */
if (!this.code)
this.code = 'ZLIB_ERROR';
this.message = 'zlib: ' + err.message;
Error.captureStackTrace(this, this.constructor);
}
get name() {
return 'ZlibError';
}
}
exports.ZlibError = ZlibError;
// the Zlib class they all inherit from
// This thing manages the queue of requests, and returns
// true or false if there is anything in the queue when
// you call the .write() method.
const _flushFlag = Symbol('flushFlag');
class ZlibBase extends minipass_1.Minipass {
#sawError = false;
#ended = false;
#flushFlag;
#finishFlushFlag;
#fullFlushFlag;
#handle;
#onError;
get sawError() {
return this.#sawError;
}
get handle() {
return this.#handle;
}
/* c8 ignore start */
get flushFlag() {
return this.#flushFlag;
}
/* c8 ignore stop */
constructor(opts, mode) {
if (!opts || typeof opts !== 'object')
throw new TypeError('invalid options for ZlibBase constructor');
//@ts-ignore
super(opts);
/* c8 ignore start */
this.#flushFlag = opts.flush ?? 0;
this.#finishFlushFlag = opts.finishFlush ?? 0;
this.#fullFlushFlag = opts.fullFlushFlag ?? 0;
/* c8 ignore stop */
// this will throw if any options are invalid for the class selected
try {
// @types/node doesn't know that it exports the classes, but they're there
//@ts-ignore
this.#handle = new realZlib[mode](opts);
}
catch (er) {
// make sure that all errors get decorated properly
throw new ZlibError(er);
}
this.#onError = err => {
// no sense raising multiple errors, since we abort on the first one.
if (this.#sawError)
return;
this.#sawError = true;
// there is no way to cleanly recover.
// continuing only obscures problems.
this.close();
this.emit('error', err);
};
this.#handle?.on('error', er => this.#onError(new ZlibError(er)));
this.once('end', () => this.close);
}
close() {
if (this.#handle) {
this.#handle.close();
this.#handle = undefined;
this.emit('close');
}
}
reset() {
if (!this.#sawError) {
(0, assert_1.default)(this.#handle, 'zlib binding closed');
//@ts-ignore
return this.#handle.reset?.();
}
}
flush(flushFlag) {
if (this.ended)
return;
if (typeof flushFlag !== 'number')
flushFlag = this.#fullFlushFlag;
this.write(Object.assign(buffer_1.Buffer.alloc(0), { [_flushFlag]: flushFlag }));
}
end(chunk, encoding, cb) {
/* c8 ignore start */
if (typeof chunk === 'function') {
cb = chunk;
encoding = undefined;
chunk = undefined;
}
if (typeof encoding === 'function') {
cb = encoding;
encoding = undefined;
}
/* c8 ignore stop */
if (chunk) {
if (encoding)
this.write(chunk, encoding);
else
this.write(chunk);
}
this.flush(this.#finishFlushFlag);
this.#ended = true;
return super.end(cb);
}
get ended() {
return this.#ended;
}
// overridden in the gzip classes to do portable writes
[_superWrite](data) {
return super.write(data);
}
write(chunk, encoding, cb) {
// process the chunk using the sync process
// then super.write() all the outputted chunks
if (typeof encoding === 'function')
(cb = encoding), (encoding = 'utf8');
if (typeof chunk === 'string')
chunk = buffer_1.Buffer.from(chunk, encoding);
if (this.#sawError)
return;
(0, assert_1.default)(this.#handle, 'zlib binding closed');
// _processChunk tries to .close() the native handle after it's done, so we
// intercept that by temporarily making it a no-op.
// diving into the node:zlib internals a bit here
const nativeHandle = this.#handle
._handle;
const originalNativeClose = nativeHandle.close;
nativeHandle.close = () => { };
const originalClose = this.#handle.close;
this.#handle.close = () => { };
// It also calls `Buffer.concat()` at the end, which may be convenient
// for some, but which we are not interested in as it slows us down.
passthroughBufferConcat(true);
let result = undefined;
try {
const flushFlag = typeof chunk[_flushFlag] === 'number'
? chunk[_flushFlag]
: this.#flushFlag;
result = this.#handle._processChunk(chunk, flushFlag);
// if we don't throw, reset it back how it was
passthroughBufferConcat(false);
}
catch (err) {
// or if we do, put Buffer.concat() back before we emit error
// Error events call into user code, which may call Buffer.concat()
passthroughBufferConcat(false);
this.#onError(new ZlibError(err));
}
finally {
if (this.#handle) {
// Core zlib resets `_handle` to null after attempting to close the
// native handle. Our no-op handler prevented actual closure, but we
// need to restore the `._handle` property.
;
this.#handle._handle =
nativeHandle;
nativeHandle.close = originalNativeClose;
this.#handle.close = originalClose;
// `_processChunk()` adds an 'error' listener. If we don't remove it
// after each call, these handlers start piling up.
this.#handle.removeAllListeners('error');
// make sure OUR error listener is still attached tho
}
}
if (this.#handle)
this.#handle.on('error', er => this.#onError(new ZlibError(er)));
let writeReturn;
if (result) {
if (Array.isArray(result) && result.length > 0) {
const r = result[0];
// The first buffer is always `handle._outBuffer`, which would be
// re-used for later invocations; so, we always have to copy that one.
writeReturn = this[_superWrite](buffer_1.Buffer.from(r));
for (let i = 1; i < result.length; i++) {
writeReturn = this[_superWrite](result[i]);
}
}
else {
// either a single Buffer or an empty array
writeReturn = this[_superWrite](buffer_1.Buffer.from(result));
}
}
if (cb)
cb();
return writeReturn;
}
}
class Zlib extends ZlibBase {
#level;
#strategy;
constructor(opts, mode) {
opts = opts || {};
opts.flush = opts.flush || constants_js_1.constants.Z_NO_FLUSH;
opts.finishFlush = opts.finishFlush || constants_js_1.constants.Z_FINISH;
opts.fullFlushFlag = constants_js_1.constants.Z_FULL_FLUSH;
super(opts, mode);
this.#level = opts.level;
this.#strategy = opts.strategy;
}
params(level, strategy) {
if (this.sawError)
return;
if (!this.handle)
throw new Error('cannot switch params when binding is closed');
// no way to test this without also not supporting params at all
/* c8 ignore start */
if (!this.handle.params)
throw new Error('not supported in this implementation');
/* c8 ignore stop */
if (this.#level !== level || this.#strategy !== strategy) {
this.flush(constants_js_1.constants.Z_SYNC_FLUSH);
(0, assert_1.default)(this.handle, 'zlib binding closed');
// .params() calls .flush(), but the latter is always async in the
// core zlib. We override .flush() temporarily to intercept that and
// flush synchronously.
const origFlush = this.handle.flush;
this.handle.flush = (flushFlag, cb) => {
/* c8 ignore start */
if (typeof flushFlag === 'function') {
cb = flushFlag;
flushFlag = this.flushFlag;
}
/* c8 ignore stop */
this.flush(flushFlag);
cb?.();
};
try {
;
this.handle.params(level, strategy);
}
finally {
this.handle.flush = origFlush;
}
/* c8 ignore start */
if (this.handle) {
this.#level = level;
this.#strategy = strategy;
}
/* c8 ignore stop */
}
}
}
exports.Zlib = Zlib;
// minimal 2-byte header
class Deflate extends Zlib {
constructor(opts) {
super(opts, 'Deflate');
}
}
exports.Deflate = Deflate;
class Inflate extends Zlib {
constructor(opts) {
super(opts, 'Inflate');
}
}
exports.Inflate = Inflate;
class Gzip extends Zlib {
#portable;
constructor(opts) {
super(opts, 'Gzip');
this.#portable = opts && !!opts.portable;
}
[_superWrite](data) {
if (!this.#portable)
return super[_superWrite](data);
// we'll always get the header emitted in one first chunk
// overwrite the OS indicator byte with 0xFF
this.#portable = false;
data[9] = 255;
return super[_superWrite](data);
}
}
exports.Gzip = Gzip;
class Gunzip extends Zlib {
constructor(opts) {
super(opts, 'Gunzip');
}
}
exports.Gunzip = Gunzip;
// raw - no header
class DeflateRaw extends Zlib {
constructor(opts) {
super(opts, 'DeflateRaw');
}
}
exports.DeflateRaw = DeflateRaw;
class InflateRaw extends Zlib {
constructor(opts) {
super(opts, 'InflateRaw');
}
}
exports.InflateRaw = InflateRaw;
// auto-detect header.
class Unzip extends Zlib {
constructor(opts) {
super(opts, 'Unzip');
}
}
exports.Unzip = Unzip;
class Brotli extends ZlibBase {
constructor(opts, mode) {
opts = opts || {};
opts.flush = opts.flush || constants_js_1.constants.BROTLI_OPERATION_PROCESS;
opts.finishFlush =
opts.finishFlush || constants_js_1.constants.BROTLI_OPERATION_FINISH;
opts.fullFlushFlag = constants_js_1.constants.BROTLI_OPERATION_FLUSH;
super(opts, mode);
}
}
exports.Brotli = Brotli;
class BrotliCompress extends Brotli {
constructor(opts) {
super(opts, 'BrotliCompress');
}
}
exports.BrotliCompress = BrotliCompress;
class BrotliDecompress extends Brotli {
constructor(opts) {
super(opts, 'BrotliDecompress');
}
}
exports.BrotliDecompress = BrotliDecompress;
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1,3 @@
{
"type": "commonjs"
}

View File

@ -0,0 +1,117 @@
// Update with any zlib constants that are added or changed in the future.
// Node v6 didn't export this, so we just hard code the version and rely
// on all the other hard-coded values from zlib v4736. When node v6
// support drops, we can just export the realZlibConstants object.
import realZlib from 'zlib';
/* c8 ignore start */
const realZlibConstants = realZlib.constants || { ZLIB_VERNUM: 4736 };
/* c8 ignore stop */
export const constants = Object.freeze(Object.assign(Object.create(null), {
Z_NO_FLUSH: 0,
Z_PARTIAL_FLUSH: 1,
Z_SYNC_FLUSH: 2,
Z_FULL_FLUSH: 3,
Z_FINISH: 4,
Z_BLOCK: 5,
Z_OK: 0,
Z_STREAM_END: 1,
Z_NEED_DICT: 2,
Z_ERRNO: -1,
Z_STREAM_ERROR: -2,
Z_DATA_ERROR: -3,
Z_MEM_ERROR: -4,
Z_BUF_ERROR: -5,
Z_VERSION_ERROR: -6,
Z_NO_COMPRESSION: 0,
Z_BEST_SPEED: 1,
Z_BEST_COMPRESSION: 9,
Z_DEFAULT_COMPRESSION: -1,
Z_FILTERED: 1,
Z_HUFFMAN_ONLY: 2,
Z_RLE: 3,
Z_FIXED: 4,
Z_DEFAULT_STRATEGY: 0,
DEFLATE: 1,
INFLATE: 2,
GZIP: 3,
GUNZIP: 4,
DEFLATERAW: 5,
INFLATERAW: 6,
UNZIP: 7,
BROTLI_DECODE: 8,
BROTLI_ENCODE: 9,
Z_MIN_WINDOWBITS: 8,
Z_MAX_WINDOWBITS: 15,
Z_DEFAULT_WINDOWBITS: 15,
Z_MIN_CHUNK: 64,
Z_MAX_CHUNK: Infinity,
Z_DEFAULT_CHUNK: 16384,
Z_MIN_MEMLEVEL: 1,
Z_MAX_MEMLEVEL: 9,
Z_DEFAULT_MEMLEVEL: 8,
Z_MIN_LEVEL: -1,
Z_MAX_LEVEL: 9,
Z_DEFAULT_LEVEL: -1,
BROTLI_OPERATION_PROCESS: 0,
BROTLI_OPERATION_FLUSH: 1,
BROTLI_OPERATION_FINISH: 2,
BROTLI_OPERATION_EMIT_METADATA: 3,
BROTLI_MODE_GENERIC: 0,
BROTLI_MODE_TEXT: 1,
BROTLI_MODE_FONT: 2,
BROTLI_DEFAULT_MODE: 0,
BROTLI_MIN_QUALITY: 0,
BROTLI_MAX_QUALITY: 11,
BROTLI_DEFAULT_QUALITY: 11,
BROTLI_MIN_WINDOW_BITS: 10,
BROTLI_MAX_WINDOW_BITS: 24,
BROTLI_LARGE_MAX_WINDOW_BITS: 30,
BROTLI_DEFAULT_WINDOW: 22,
BROTLI_MIN_INPUT_BLOCK_BITS: 16,
BROTLI_MAX_INPUT_BLOCK_BITS: 24,
BROTLI_PARAM_MODE: 0,
BROTLI_PARAM_QUALITY: 1,
BROTLI_PARAM_LGWIN: 2,
BROTLI_PARAM_LGBLOCK: 3,
BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: 4,
BROTLI_PARAM_SIZE_HINT: 5,
BROTLI_PARAM_LARGE_WINDOW: 6,
BROTLI_PARAM_NPOSTFIX: 7,
BROTLI_PARAM_NDIRECT: 8,
BROTLI_DECODER_RESULT_ERROR: 0,
BROTLI_DECODER_RESULT_SUCCESS: 1,
BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: 2,
BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: 3,
BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: 0,
BROTLI_DECODER_PARAM_LARGE_WINDOW: 1,
BROTLI_DECODER_NO_ERROR: 0,
BROTLI_DECODER_SUCCESS: 1,
BROTLI_DECODER_NEEDS_MORE_INPUT: 2,
BROTLI_DECODER_NEEDS_MORE_OUTPUT: 3,
BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: -1,
BROTLI_DECODER_ERROR_FORMAT_RESERVED: -2,
BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: -3,
BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: -4,
BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: -5,
BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: -6,
BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: -7,
BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: -8,
BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: -9,
BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: -10,
BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: -11,
BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: -12,
BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: -13,
BROTLI_DECODER_ERROR_FORMAT_PADDING_1: -14,
BROTLI_DECODER_ERROR_FORMAT_PADDING_2: -15,
BROTLI_DECODER_ERROR_FORMAT_DISTANCE: -16,
BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: -19,
BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: -20,
BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: -21,
BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: -22,
BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: -25,
BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: -26,
BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: -27,
BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: -30,
BROTLI_DECODER_ERROR_UNREACHABLE: -31,
}, realZlibConstants));
//# sourceMappingURL=constants.js.map

View File

@ -0,0 +1,340 @@
import assert from 'assert';
import { Buffer } from 'buffer';
import { Minipass } from 'minipass';
import * as realZlib from 'zlib';
import { constants } from './constants.js';
export { constants } from './constants.js';
const OriginalBufferConcat = Buffer.concat;
const desc = Object.getOwnPropertyDescriptor(Buffer, 'concat');
const noop = (args) => args;
const passthroughBufferConcat = desc?.writable === true || desc?.set !== undefined
? (makeNoOp) => {
Buffer.concat = makeNoOp ? noop : OriginalBufferConcat;
}
: (_) => { };
const _superWrite = Symbol('_superWrite');
export class ZlibError extends Error {
code;
errno;
constructor(err) {
super('zlib: ' + err.message);
this.code = err.code;
this.errno = err.errno;
/* c8 ignore next */
if (!this.code)
this.code = 'ZLIB_ERROR';
this.message = 'zlib: ' + err.message;
Error.captureStackTrace(this, this.constructor);
}
get name() {
return 'ZlibError';
}
}
// the Zlib class they all inherit from
// This thing manages the queue of requests, and returns
// true or false if there is anything in the queue when
// you call the .write() method.
const _flushFlag = Symbol('flushFlag');
class ZlibBase extends Minipass {
#sawError = false;
#ended = false;
#flushFlag;
#finishFlushFlag;
#fullFlushFlag;
#handle;
#onError;
get sawError() {
return this.#sawError;
}
get handle() {
return this.#handle;
}
/* c8 ignore start */
get flushFlag() {
return this.#flushFlag;
}
/* c8 ignore stop */
constructor(opts, mode) {
if (!opts || typeof opts !== 'object')
throw new TypeError('invalid options for ZlibBase constructor');
//@ts-ignore
super(opts);
/* c8 ignore start */
this.#flushFlag = opts.flush ?? 0;
this.#finishFlushFlag = opts.finishFlush ?? 0;
this.#fullFlushFlag = opts.fullFlushFlag ?? 0;
/* c8 ignore stop */
// this will throw if any options are invalid for the class selected
try {
// @types/node doesn't know that it exports the classes, but they're there
//@ts-ignore
this.#handle = new realZlib[mode](opts);
}
catch (er) {
// make sure that all errors get decorated properly
throw new ZlibError(er);
}
this.#onError = err => {
// no sense raising multiple errors, since we abort on the first one.
if (this.#sawError)
return;
this.#sawError = true;
// there is no way to cleanly recover.
// continuing only obscures problems.
this.close();
this.emit('error', err);
};
this.#handle?.on('error', er => this.#onError(new ZlibError(er)));
this.once('end', () => this.close);
}
close() {
if (this.#handle) {
this.#handle.close();
this.#handle = undefined;
this.emit('close');
}
}
reset() {
if (!this.#sawError) {
assert(this.#handle, 'zlib binding closed');
//@ts-ignore
return this.#handle.reset?.();
}
}
flush(flushFlag) {
if (this.ended)
return;
if (typeof flushFlag !== 'number')
flushFlag = this.#fullFlushFlag;
this.write(Object.assign(Buffer.alloc(0), { [_flushFlag]: flushFlag }));
}
end(chunk, encoding, cb) {
/* c8 ignore start */
if (typeof chunk === 'function') {
cb = chunk;
encoding = undefined;
chunk = undefined;
}
if (typeof encoding === 'function') {
cb = encoding;
encoding = undefined;
}
/* c8 ignore stop */
if (chunk) {
if (encoding)
this.write(chunk, encoding);
else
this.write(chunk);
}
this.flush(this.#finishFlushFlag);
this.#ended = true;
return super.end(cb);
}
get ended() {
return this.#ended;
}
// overridden in the gzip classes to do portable writes
[_superWrite](data) {
return super.write(data);
}
write(chunk, encoding, cb) {
// process the chunk using the sync process
// then super.write() all the outputted chunks
if (typeof encoding === 'function')
(cb = encoding), (encoding = 'utf8');
if (typeof chunk === 'string')
chunk = Buffer.from(chunk, encoding);
if (this.#sawError)
return;
assert(this.#handle, 'zlib binding closed');
// _processChunk tries to .close() the native handle after it's done, so we
// intercept that by temporarily making it a no-op.
// diving into the node:zlib internals a bit here
const nativeHandle = this.#handle
._handle;
const originalNativeClose = nativeHandle.close;
nativeHandle.close = () => { };
const originalClose = this.#handle.close;
this.#handle.close = () => { };
// It also calls `Buffer.concat()` at the end, which may be convenient
// for some, but which we are not interested in as it slows us down.
passthroughBufferConcat(true);
let result = undefined;
try {
const flushFlag = typeof chunk[_flushFlag] === 'number'
? chunk[_flushFlag]
: this.#flushFlag;
result = this.#handle._processChunk(chunk, flushFlag);
// if we don't throw, reset it back how it was
passthroughBufferConcat(false);
}
catch (err) {
// or if we do, put Buffer.concat() back before we emit error
// Error events call into user code, which may call Buffer.concat()
passthroughBufferConcat(false);
this.#onError(new ZlibError(err));
}
finally {
if (this.#handle) {
// Core zlib resets `_handle` to null after attempting to close the
// native handle. Our no-op handler prevented actual closure, but we
// need to restore the `._handle` property.
;
this.#handle._handle =
nativeHandle;
nativeHandle.close = originalNativeClose;
this.#handle.close = originalClose;
// `_processChunk()` adds an 'error' listener. If we don't remove it
// after each call, these handlers start piling up.
this.#handle.removeAllListeners('error');
// make sure OUR error listener is still attached tho
}
}
if (this.#handle)
this.#handle.on('error', er => this.#onError(new ZlibError(er)));
let writeReturn;
if (result) {
if (Array.isArray(result) && result.length > 0) {
const r = result[0];
// The first buffer is always `handle._outBuffer`, which would be
// re-used for later invocations; so, we always have to copy that one.
writeReturn = this[_superWrite](Buffer.from(r));
for (let i = 1; i < result.length; i++) {
writeReturn = this[_superWrite](result[i]);
}
}
else {
// either a single Buffer or an empty array
writeReturn = this[_superWrite](Buffer.from(result));
}
}
if (cb)
cb();
return writeReturn;
}
}
export class Zlib extends ZlibBase {
#level;
#strategy;
constructor(opts, mode) {
opts = opts || {};
opts.flush = opts.flush || constants.Z_NO_FLUSH;
opts.finishFlush = opts.finishFlush || constants.Z_FINISH;
opts.fullFlushFlag = constants.Z_FULL_FLUSH;
super(opts, mode);
this.#level = opts.level;
this.#strategy = opts.strategy;
}
params(level, strategy) {
if (this.sawError)
return;
if (!this.handle)
throw new Error('cannot switch params when binding is closed');
// no way to test this without also not supporting params at all
/* c8 ignore start */
if (!this.handle.params)
throw new Error('not supported in this implementation');
/* c8 ignore stop */
if (this.#level !== level || this.#strategy !== strategy) {
this.flush(constants.Z_SYNC_FLUSH);
assert(this.handle, 'zlib binding closed');
// .params() calls .flush(), but the latter is always async in the
// core zlib. We override .flush() temporarily to intercept that and
// flush synchronously.
const origFlush = this.handle.flush;
this.handle.flush = (flushFlag, cb) => {
/* c8 ignore start */
if (typeof flushFlag === 'function') {
cb = flushFlag;
flushFlag = this.flushFlag;
}
/* c8 ignore stop */
this.flush(flushFlag);
cb?.();
};
try {
;
this.handle.params(level, strategy);
}
finally {
this.handle.flush = origFlush;
}
/* c8 ignore start */
if (this.handle) {
this.#level = level;
this.#strategy = strategy;
}
/* c8 ignore stop */
}
}
}
// minimal 2-byte header
export class Deflate extends Zlib {
constructor(opts) {
super(opts, 'Deflate');
}
}
export class Inflate extends Zlib {
constructor(opts) {
super(opts, 'Inflate');
}
}
export class Gzip extends Zlib {
#portable;
constructor(opts) {
super(opts, 'Gzip');
this.#portable = opts && !!opts.portable;
}
[_superWrite](data) {
if (!this.#portable)
return super[_superWrite](data);
// we'll always get the header emitted in one first chunk
// overwrite the OS indicator byte with 0xFF
this.#portable = false;
data[9] = 255;
return super[_superWrite](data);
}
}
export class Gunzip extends Zlib {
constructor(opts) {
super(opts, 'Gunzip');
}
}
// raw - no header
export class DeflateRaw extends Zlib {
constructor(opts) {
super(opts, 'DeflateRaw');
}
}
export class InflateRaw extends Zlib {
constructor(opts) {
super(opts, 'InflateRaw');
}
}
// auto-detect header.
export class Unzip extends Zlib {
constructor(opts) {
super(opts, 'Unzip');
}
}
export class Brotli extends ZlibBase {
constructor(opts, mode) {
opts = opts || {};
opts.flush = opts.flush || constants.BROTLI_OPERATION_PROCESS;
opts.finishFlush =
opts.finishFlush || constants.BROTLI_OPERATION_FINISH;
opts.fullFlushFlag = constants.BROTLI_OPERATION_FLUSH;
super(opts, mode);
}
}
export class BrotliCompress extends Brotli {
constructor(opts) {
super(opts, 'BrotliCompress');
}
}
export class BrotliDecompress extends Brotli {
constructor(opts) {
super(opts, 'BrotliDecompress');
}
}
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1,3 @@
{
"type": "module"
}

View File

@ -0,0 +1,80 @@
{
"name": "minizlib",
"version": "3.0.2",
"description": "A small fast zlib stream built on [minipass](http://npm.im/minipass) and Node.js's zlib binding.",
"main": "./dist/commonjs/index.js",
"dependencies": {
"minipass": "^7.1.2"
},
"scripts": {
"prepare": "tshy",
"pretest": "npm run prepare",
"test": "tap",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"format": "prettier --write . --loglevel warn",
"typedoc": "typedoc --tsconfig .tshy/esm.json ./src/*.ts"
},
"repository": {
"type": "git",
"url": "git+https://github.com/isaacs/minizlib.git"
},
"keywords": [
"zlib",
"gzip",
"gunzip",
"deflate",
"inflate",
"compression",
"zip",
"unzip"
],
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
"license": "MIT",
"devDependencies": {
"@types/node": "^22.13.14",
"tap": "^21.1.0",
"tshy": "^3.0.2",
"typedoc": "^0.28.1"
},
"files": [
"dist"
],
"engines": {
"node": ">= 18"
},
"tshy": {
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
}
},
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"types": "./dist/commonjs/index.d.ts",
"type": "module",
"prettier": {
"semi": false,
"printWidth": 75,
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"jsxSingleQuote": false,
"bracketSameLine": true,
"arrowParens": "avoid",
"endOfLine": "lf"
},
"module": "./dist/esm/index.js"
}

68
deps/npm/node_modules/npm-registry-fetch/package.json generated vendored Normal file
View File

@ -0,0 +1,68 @@
{
"name": "npm-registry-fetch",
"version": "18.0.2",
"description": "Fetch-based http client for use with npm registry APIs",
"main": "lib",
"files": [
"bin/",
"lib/"
],
"scripts": {
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
"lint": "npm run eslint",
"lintfix": "npm run eslint -- --fix",
"test": "tap",
"posttest": "npm run lint",
"npmclilint": "npmcli-lint",
"postsnap": "npm run lintfix --",
"postlint": "template-oss-check",
"snap": "tap",
"template-oss-apply": "template-oss-apply --force"
},
"repository": {
"type": "git",
"url": "git+https://github.com/npm/npm-registry-fetch.git"
},
"keywords": [
"npm",
"registry",
"fetch"
],
"author": "GitHub Inc.",
"license": "ISC",
"dependencies": {
"@npmcli/redact": "^3.0.0",
"jsonparse": "^1.3.1",
"make-fetch-happen": "^14.0.0",
"minipass": "^7.0.2",
"minipass-fetch": "^4.0.0",
"minizlib": "^3.0.1",
"npm-package-arg": "^12.0.0",
"proc-log": "^5.0.0"
},
"devDependencies": {
"@npmcli/eslint-config": "^5.0.0",
"@npmcli/template-oss": "4.23.4",
"cacache": "^19.0.1",
"nock": "^13.2.4",
"require-inject": "^1.4.4",
"ssri": "^12.0.0",
"tap": "^16.0.1"
},
"tap": {
"check-coverage": true,
"test-ignore": "test[\\\\/](util|cache)[\\\\/]",
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
]
},
"engines": {
"node": "^18.17.0 || >=20.5.0"
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.23.4",
"publish": "true"
}
}