fix gitignore again

This commit is contained in:
olcxja 2026-05-10 16:36:35 +02:00
commit 5da5c2afe2
3329 changed files with 364540 additions and 3 deletions

View file

@ -0,0 +1,3 @@
export declare const chownr: (p: string, uid: number, gid: number, cb: (er?: unknown) => any) => void;
export declare const chownrSync: (p: string, uid: number, gid: number) => void;
//# sourceMappingURL=index.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AA0CA,eAAO,MAAM,MAAM,MACd,MAAM,OACJ,MAAM,OACN,MAAM,YACD,OAAO,KAAK,GAAG,SA0B1B,CAAA;AAcD,eAAO,MAAM,UAAU,MAAO,MAAM,OAAO,MAAM,OAAO,MAAM,SAiB7D,CAAA"}

View file

@ -0,0 +1,93 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.chownrSync = exports.chownr = void 0;
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const lchownSync = (path, uid, gid) => {
try {
return node_fs_1.default.lchownSync(path, uid, gid);
}
catch (er) {
if (er?.code !== 'ENOENT')
throw er;
}
};
const chown = (cpath, uid, gid, cb) => {
node_fs_1.default.lchown(cpath, uid, gid, er => {
// Skip ENOENT error
cb(er && er?.code !== 'ENOENT' ? er : null);
});
};
const chownrKid = (p, child, uid, gid, cb) => {
if (child.isDirectory()) {
(0, exports.chownr)(node_path_1.default.resolve(p, child.name), uid, gid, (er) => {
if (er)
return cb(er);
const cpath = node_path_1.default.resolve(p, child.name);
chown(cpath, uid, gid, cb);
});
}
else {
const cpath = node_path_1.default.resolve(p, child.name);
chown(cpath, uid, gid, cb);
}
};
const chownr = (p, uid, gid, cb) => {
node_fs_1.default.readdir(p, { withFileTypes: true }, (er, children) => {
// any error other than ENOTDIR or ENOTSUP means it's not readable,
// or doesn't exist. give up.
if (er) {
if (er.code === 'ENOENT')
return cb();
else if (er.code !== 'ENOTDIR' && er.code !== 'ENOTSUP')
return cb(er);
}
if (er || !children.length)
return chown(p, uid, gid, cb);
let len = children.length;
let errState = null;
const then = (er) => {
/* c8 ignore start */
if (errState)
return;
/* c8 ignore stop */
if (er)
return cb((errState = er));
if (--len === 0)
return chown(p, uid, gid, cb);
};
for (const child of children) {
chownrKid(p, child, uid, gid, then);
}
});
};
exports.chownr = chownr;
const chownrKidSync = (p, child, uid, gid) => {
if (child.isDirectory())
(0, exports.chownrSync)(node_path_1.default.resolve(p, child.name), uid, gid);
lchownSync(node_path_1.default.resolve(p, child.name), uid, gid);
};
const chownrSync = (p, uid, gid) => {
let children;
try {
children = node_fs_1.default.readdirSync(p, { withFileTypes: true });
}
catch (er) {
const e = er;
if (e?.code === 'ENOENT')
return;
else if (e?.code === 'ENOTDIR' || e?.code === 'ENOTSUP')
return lchownSync(p, uid, gid);
else
throw e;
}
for (const child of children) {
chownrKidSync(p, child, uid, gid);
}
return lchownSync(p, uid, gid);
};
exports.chownrSync = chownrSync;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View file

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

View file

@ -0,0 +1,3 @@
export declare const chownr: (p: string, uid: number, gid: number, cb: (er?: unknown) => any) => void;
export declare const chownrSync: (p: string, uid: number, gid: number) => void;
//# sourceMappingURL=index.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AA0CA,eAAO,MAAM,MAAM,MACd,MAAM,OACJ,MAAM,OACN,MAAM,YACD,OAAO,KAAK,GAAG,SA0B1B,CAAA;AAcD,eAAO,MAAM,UAAU,MAAO,MAAM,OAAO,MAAM,OAAO,MAAM,SAiB7D,CAAA"}

View file

@ -0,0 +1,85 @@
import fs from 'node:fs';
import path from 'node:path';
const lchownSync = (path, uid, gid) => {
try {
return fs.lchownSync(path, uid, gid);
}
catch (er) {
if (er?.code !== 'ENOENT')
throw er;
}
};
const chown = (cpath, uid, gid, cb) => {
fs.lchown(cpath, uid, gid, er => {
// Skip ENOENT error
cb(er && er?.code !== 'ENOENT' ? er : null);
});
};
const chownrKid = (p, child, uid, gid, cb) => {
if (child.isDirectory()) {
chownr(path.resolve(p, child.name), uid, gid, (er) => {
if (er)
return cb(er);
const cpath = path.resolve(p, child.name);
chown(cpath, uid, gid, cb);
});
}
else {
const cpath = path.resolve(p, child.name);
chown(cpath, uid, gid, cb);
}
};
export const chownr = (p, uid, gid, cb) => {
fs.readdir(p, { withFileTypes: true }, (er, children) => {
// any error other than ENOTDIR or ENOTSUP means it's not readable,
// or doesn't exist. give up.
if (er) {
if (er.code === 'ENOENT')
return cb();
else if (er.code !== 'ENOTDIR' && er.code !== 'ENOTSUP')
return cb(er);
}
if (er || !children.length)
return chown(p, uid, gid, cb);
let len = children.length;
let errState = null;
const then = (er) => {
/* c8 ignore start */
if (errState)
return;
/* c8 ignore stop */
if (er)
return cb((errState = er));
if (--len === 0)
return chown(p, uid, gid, cb);
};
for (const child of children) {
chownrKid(p, child, uid, gid, then);
}
});
};
const chownrKidSync = (p, child, uid, gid) => {
if (child.isDirectory())
chownrSync(path.resolve(p, child.name), uid, gid);
lchownSync(path.resolve(p, child.name), uid, gid);
};
export const chownrSync = (p, uid, gid) => {
let children;
try {
children = fs.readdirSync(p, { withFileTypes: true });
}
catch (er) {
const e = er;
if (e?.code === 'ENOENT')
return;
else if (e?.code === 'ENOTDIR' || e?.code === 'ENOTSUP')
return lchownSync(p, uid, gid);
else
throw e;
}
for (const child of children) {
chownrKidSync(p, child, uid, gid);
}
return lchownSync(p, uid, gid);
};
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View file

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

View file

@ -0,0 +1,545 @@
import { EventEmitter } from 'node:events';
import { StringDecoder } from 'node:string_decoder';
/**
* Same as StringDecoder, but exposing the `lastNeed` flag on the type
*/
type SD = StringDecoder & {
lastNeed: boolean;
};
export type { SD, Pipe, PipeProxyErrors };
/**
* Return true if the argument is a Minipass stream, Node stream, or something
* else that Minipass can interact with.
*/
export declare const isStream: (s: any) => s is Minipass<any, any, any> | NodeJS.ReadStream | NodeJS.WriteStream | (EventEmitter<any> & {
end(): any;
write(chunk: any, ...args: any[]): any;
}) | (EventEmitter<any> & {
pause(): any;
resume(): any;
pipe(...destArgs: any[]): any;
}) | (NodeJS.ReadStream & {
fd: number;
}) | (NodeJS.WriteStream & {
fd: number;
});
/**
* Return true if the argument is a valid {@link Minipass.Readable}
*/
export declare const isReadable: (s: any) => s is Minipass.Readable;
/**
* Return true if the argument is a valid {@link Minipass.Writable}
*/
export declare const isWritable: (s: any) => s is Minipass.Readable;
declare const EOF: unique symbol;
declare const MAYBE_EMIT_END: unique symbol;
declare const EMITTED_END: unique symbol;
declare const EMITTING_END: unique symbol;
declare const EMITTED_ERROR: unique symbol;
declare const CLOSED: unique symbol;
declare const READ: unique symbol;
declare const FLUSH: unique symbol;
declare const FLUSHCHUNK: unique symbol;
declare const ENCODING: unique symbol;
declare const DECODER: unique symbol;
declare const FLOWING: unique symbol;
declare const PAUSED: unique symbol;
declare const RESUME: unique symbol;
declare const BUFFER: unique symbol;
declare const PIPES: unique symbol;
declare const BUFFERLENGTH: unique symbol;
declare const BUFFERPUSH: unique symbol;
declare const BUFFERSHIFT: unique symbol;
declare const OBJECTMODE: unique symbol;
declare const DESTROYED: unique symbol;
declare const ERROR: unique symbol;
declare const EMITDATA: unique symbol;
declare const EMITEND: unique symbol;
declare const EMITEND2: unique symbol;
declare const ASYNC: unique symbol;
declare const ABORT: unique symbol;
declare const ABORTED: unique symbol;
declare const SIGNAL: unique symbol;
declare const DATALISTENERS: unique symbol;
declare const DISCARDED: unique symbol;
/**
* Options that may be passed to stream.pipe()
*/
export interface PipeOptions {
/**
* end the destination stream when the source stream ends
*/
end?: boolean;
/**
* proxy errors from the source stream to the destination stream
*/
proxyErrors?: boolean;
}
/**
* Internal class representing a pipe to a destination stream.
*
* @internal
*/
declare class Pipe<T extends unknown> {
src: Minipass<T>;
dest: Minipass<any, T>;
opts: PipeOptions;
ondrain: () => any;
constructor(src: Minipass<T>, dest: Minipass.Writable, opts: PipeOptions);
unpipe(): void;
proxyErrors(_er: any): void;
end(): void;
}
/**
* Internal class representing a pipe to a destination stream where
* errors are proxied.
*
* @internal
*/
declare class PipeProxyErrors<T> extends Pipe<T> {
unpipe(): void;
constructor(src: Minipass<T>, dest: Minipass.Writable, opts: PipeOptions);
}
export declare namespace Minipass {
/**
* Encoding used to create a stream that outputs strings rather than
* Buffer objects.
*/
export type Encoding = BufferEncoding | 'buffer' | null;
/**
* Any stream that Minipass can pipe into
*/
export type Writable = Minipass<any, any, any> | NodeJS.WriteStream | (NodeJS.WriteStream & {
fd: number;
}) | (EventEmitter & {
end(): any;
write(chunk: any, ...args: any[]): any;
});
/**
* Any stream that can be read from
*/
export type Readable = Minipass<any, any, any> | NodeJS.ReadStream | (NodeJS.ReadStream & {
fd: number;
}) | (EventEmitter & {
pause(): any;
resume(): any;
pipe(...destArgs: any[]): any;
});
/**
* Utility type that can be iterated sync or async
*/
export type DualIterable<T> = Iterable<T> & AsyncIterable<T>;
type EventArguments = Record<string | symbol, unknown[]>;
/**
* The listing of events that a Minipass class can emit.
* Extend this when extending the Minipass class, and pass as
* the third template argument. The key is the name of the event,
* and the value is the argument list.
*
* Any undeclared events will still be allowed, but the handler will get
* arguments as `unknown[]`.
*/
export interface Events<RType extends any = Buffer> extends EventArguments {
readable: [];
data: [chunk: RType];
error: [er: unknown];
abort: [reason: unknown];
drain: [];
resume: [];
end: [];
finish: [];
prefinish: [];
close: [];
[DESTROYED]: [er?: unknown];
[ERROR]: [er: unknown];
}
/**
* String or buffer-like data that can be joined and sliced
*/
export type ContiguousData = Buffer | ArrayBufferLike | ArrayBufferView | string;
export type BufferOrString = Buffer | string;
/**
* Options passed to the Minipass constructor.
*/
export type SharedOptions = {
/**
* Defer all data emission and other events until the end of the
* current tick, similar to Node core streams
*/
async?: boolean;
/**
* A signal which will abort the stream
*/
signal?: AbortSignal;
/**
* Output string encoding. Set to `null` or `'buffer'` (or omit) to
* emit Buffer objects rather than strings.
*
* Conflicts with `objectMode`
*/
encoding?: BufferEncoding | null | 'buffer';
/**
* Output data exactly as it was written, supporting non-buffer/string
* data (such as arbitrary objects, falsey values, etc.)
*
* Conflicts with `encoding`
*/
objectMode?: boolean;
};
/**
* Options for a string encoded output
*/
export type EncodingOptions = SharedOptions & {
encoding: BufferEncoding;
objectMode?: false;
};
/**
* Options for contiguous data buffer output
*/
export type BufferOptions = SharedOptions & {
encoding?: null | 'buffer';
objectMode?: false;
};
/**
* Options for objectMode arbitrary output
*/
export type ObjectModeOptions = SharedOptions & {
objectMode: true;
encoding?: null;
};
/**
* Utility type to determine allowed options based on read type
*/
export type Options<T> = ObjectModeOptions | (T extends string ? EncodingOptions : T extends Buffer ? BufferOptions : SharedOptions);
export {};
}
/**
* Main export, the Minipass class
*
* `RType` is the type of data emitted, defaults to Buffer
*
* `WType` is the type of data to be written, if RType is buffer or string,
* then any {@link Minipass.ContiguousData} is allowed.
*
* `Events` is the set of event handler signatures that this object
* will emit, see {@link Minipass.Events}
*/
export declare class Minipass<RType extends unknown = Buffer, WType extends unknown = RType extends Minipass.BufferOrString ? Minipass.ContiguousData : RType, Events extends Minipass.Events<RType> = Minipass.Events<RType>> extends EventEmitter implements Minipass.DualIterable<RType> {
[FLOWING]: boolean;
[PAUSED]: boolean;
[PIPES]: Pipe<RType>[];
[BUFFER]: RType[];
[OBJECTMODE]: boolean;
[ENCODING]: BufferEncoding | null;
[ASYNC]: boolean;
[DECODER]: SD | null;
[EOF]: boolean;
[EMITTED_END]: boolean;
[EMITTING_END]: boolean;
[CLOSED]: boolean;
[EMITTED_ERROR]: unknown;
[BUFFERLENGTH]: number;
[DESTROYED]: boolean;
[SIGNAL]?: AbortSignal;
[ABORTED]: boolean;
[DATALISTENERS]: number;
[DISCARDED]: boolean;
/**
* true if the stream can be written
*/
writable: boolean;
/**
* true if the stream can be read
*/
readable: boolean;
/**
* If `RType` is Buffer, then options do not need to be provided.
* Otherwise, an options object must be provided to specify either
* {@link Minipass.SharedOptions.objectMode} or
* {@link Minipass.SharedOptions.encoding}, as appropriate.
*/
constructor(...args: [Minipass.ObjectModeOptions] | (RType extends Buffer ? [] | [Minipass.Options<RType>] : [Minipass.Options<RType>]));
/**
* The amount of data stored in the buffer waiting to be read.
*
* For Buffer strings, this will be the total byte length.
* For string encoding streams, this will be the string character length,
* according to JavaScript's `string.length` logic.
* For objectMode streams, this is a count of the items waiting to be
* emitted.
*/
get bufferLength(): number;
/**
* The `BufferEncoding` currently in use, or `null`
*/
get encoding(): BufferEncoding | null;
/**
* @deprecated - This is a read only property
*/
set encoding(_enc: BufferEncoding | null);
/**
* @deprecated - Encoding may only be set at instantiation time
*/
setEncoding(_enc: Minipass.Encoding): void;
/**
* True if this is an objectMode stream
*/
get objectMode(): boolean;
/**
* @deprecated - This is a read-only property
*/
set objectMode(_om: boolean);
/**
* true if this is an async stream
*/
get ['async'](): boolean;
/**
* Set to true to make this stream async.
*
* Once set, it cannot be unset, as this would potentially cause incorrect
* behavior. Ie, a sync stream can be made async, but an async stream
* cannot be safely made sync.
*/
set ['async'](a: boolean);
[ABORT](): void;
/**
* True if the stream has been aborted.
*/
get aborted(): boolean;
/**
* No-op setter. Stream aborted status is set via the AbortSignal provided
* in the constructor options.
*/
set aborted(_: boolean);
/**
* Write data into the stream
*
* If the chunk written is a string, and encoding is not specified, then
* `utf8` will be assumed. If the stream encoding matches the encoding of
* a written string, and the state of the string decoder allows it, then
* the string will be passed through to either the output or the internal
* buffer without any processing. Otherwise, it will be turned into a
* Buffer object for processing into the desired encoding.
*
* If provided, `cb` function is called immediately before return for
* sync streams, or on next tick for async streams, because for this
* base class, a chunk is considered "processed" once it is accepted
* and either emitted or buffered. That is, the callback does not indicate
* that the chunk has been eventually emitted, though of course child
* classes can override this function to do whatever processing is required
* and call `super.write(...)` only once processing is completed.
*/
write(chunk: WType, cb?: () => void): boolean;
write(chunk: WType, encoding?: Minipass.Encoding, cb?: () => void): boolean;
/**
* Low-level explicit read method.
*
* In objectMode, the argument is ignored, and one item is returned if
* available.
*
* `n` is the number of bytes (or in the case of encoding streams,
* characters) to consume. If `n` is not provided, then the entire buffer
* is returned, or `null` is returned if no data is available.
*
* If `n` is greater that the amount of data in the internal buffer,
* then `null` is returned.
*/
read(n?: number | null): RType | null;
[READ](n: number | null, chunk: RType): RType;
/**
* End the stream, optionally providing a final write.
*
* See {@link Minipass#write} for argument descriptions
*/
end(cb?: () => void): this;
end(chunk: WType, cb?: () => void): this;
end(chunk: WType, encoding?: Minipass.Encoding, cb?: () => void): this;
[RESUME](): void;
/**
* Resume the stream if it is currently in a paused state
*
* If called when there are no pipe destinations or `data` event listeners,
* this will place the stream in a "discarded" state, where all data will
* be thrown away. The discarded state is removed if a pipe destination or
* data handler is added, if pause() is called, or if any synchronous or
* asynchronous iteration is started.
*/
resume(): void;
/**
* Pause the stream
*/
pause(): void;
/**
* true if the stream has been forcibly destroyed
*/
get destroyed(): boolean;
/**
* true if the stream is currently in a flowing state, meaning that
* any writes will be immediately emitted.
*/
get flowing(): boolean;
/**
* true if the stream is currently in a paused state
*/
get paused(): boolean;
[BUFFERPUSH](chunk: RType): void;
[BUFFERSHIFT](): RType;
[FLUSH](noDrain?: boolean): void;
[FLUSHCHUNK](chunk: RType): boolean;
/**
* Pipe all data emitted by this stream into the destination provided.
*
* Triggers the flow of data.
*/
pipe<W extends Minipass.Writable>(dest: W, opts?: PipeOptions): W;
/**
* Fully unhook a piped destination stream.
*
* If the destination stream was the only consumer of this stream (ie,
* there are no other piped destinations or `'data'` event listeners)
* then the flow of data will stop until there is another consumer or
* {@link Minipass#resume} is explicitly called.
*/
unpipe<W extends Minipass.Writable>(dest: W): void;
/**
* Alias for {@link Minipass#on}
*/
addListener<Event extends keyof Events>(ev: Event, handler: (...args: Events[Event]) => any): this;
/**
* Mostly identical to `EventEmitter.on`, with the following
* behavior differences to prevent data loss and unnecessary hangs:
*
* - Adding a 'data' event handler will trigger the flow of data
*
* - Adding a 'readable' event handler when there is data waiting to be read
* will cause 'readable' to be emitted immediately.
*
* - Adding an 'endish' event handler ('end', 'finish', etc.) which has
* already passed will cause the event to be emitted immediately and all
* handlers removed.
*
* - Adding an 'error' event handler after an error has been emitted will
* cause the event to be re-emitted immediately with the error previously
* raised.
*/
on<Event extends keyof Events>(ev: Event, handler: (...args: Events[Event]) => any): this;
/**
* Alias for {@link Minipass#off}
*/
removeListener<Event extends keyof Events>(ev: Event, handler: (...args: Events[Event]) => any): this;
/**
* Mostly identical to `EventEmitter.off`
*
* If a 'data' event handler is removed, and it was the last consumer
* (ie, there are no pipe destinations or other 'data' event listeners),
* then the flow of data will stop until there is another consumer or
* {@link Minipass#resume} is explicitly called.
*/
off<Event extends keyof Events>(ev: Event, handler: (...args: Events[Event]) => any): this;
/**
* Mostly identical to `EventEmitter.removeAllListeners`
*
* If all 'data' event handlers are removed, and they were the last consumer
* (ie, there are no pipe destinations), then the flow of data will stop
* until there is another consumer or {@link Minipass#resume} is explicitly
* called.
*/
removeAllListeners<Event extends keyof Events>(ev?: Event): this;
/**
* true if the 'end' event has been emitted
*/
get emittedEnd(): boolean;
[MAYBE_EMIT_END](): void;
/**
* Mostly identical to `EventEmitter.emit`, with the following
* behavior differences to prevent data loss and unnecessary hangs:
*
* If the stream has been destroyed, and the event is something other
* than 'close' or 'error', then `false` is returned and no handlers
* are called.
*
* If the event is 'end', and has already been emitted, then the event
* is ignored. If the stream is in a paused or non-flowing state, then
* the event will be deferred until data flow resumes. If the stream is
* async, then handlers will be called on the next tick rather than
* immediately.
*
* If the event is 'close', and 'end' has not yet been emitted, then
* the event will be deferred until after 'end' is emitted.
*
* If the event is 'error', and an AbortSignal was provided for the stream,
* and there are no listeners, then the event is ignored, matching the
* behavior of node core streams in the presense of an AbortSignal.
*
* If the event is 'finish' or 'prefinish', then all listeners will be
* removed after emitting the event, to prevent double-firing.
*/
emit<Event extends keyof Events>(ev: Event, ...args: Events[Event]): boolean;
[EMITDATA](data: RType): boolean;
[EMITEND](): boolean;
[EMITEND2](): boolean;
/**
* Return a Promise that resolves to an array of all emitted data once
* the stream ends.
*/
collect(): Promise<RType[] & {
dataLength: number;
}>;
/**
* Return a Promise that resolves to the concatenation of all emitted data
* once the stream ends.
*
* Not allowed on objectMode streams.
*/
concat(): Promise<RType>;
/**
* Return a void Promise that resolves once the stream ends.
*/
promise(): Promise<void>;
/**
* Asynchronous `for await of` iteration.
*
* This will continue emitting all chunks until the stream terminates.
*/
[Symbol.asyncIterator](): AsyncGenerator<RType, void, void>;
/**
* Synchronous `for of` iteration.
*
* The iteration will terminate when the internal buffer runs out, even
* if the stream has not yet terminated.
*/
[Symbol.iterator](): Generator<RType, void, void>;
/**
* Destroy a stream, preventing it from being used for any further purpose.
*
* If the stream has a `close()` method, then it will be called on
* destruction.
*
* After destruction, any attempt to write data, read data, or emit most
* events will be ignored.
*
* If an error argument is provided, then it will be emitted in an
* 'error' event.
*/
destroy(er?: unknown): this;
/**
* Alias for {@link isStream}
*
* Former export location, maintained for backwards compatibility.
*
* @deprecated
*/
static get isStream(): (s: any) => s is Minipass<any, any, any> | NodeJS.ReadStream | NodeJS.WriteStream | (EventEmitter<any> & {
end(): any;
write(chunk: any, ...args: any[]): any;
}) | (EventEmitter<any> & {
pause(): any;
resume(): any;
pipe(...destArgs: any[]): any;
}) | (NodeJS.ReadStream & {
fd: number;
}) | (NodeJS.WriteStream & {
fd: number;
});
}
//# sourceMappingURL=index.d.ts.map

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

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

View file

@ -0,0 +1,545 @@
import { EventEmitter } from 'node:events';
import { StringDecoder } from 'node:string_decoder';
/**
* Same as StringDecoder, but exposing the `lastNeed` flag on the type
*/
type SD = StringDecoder & {
lastNeed: boolean;
};
export type { SD, Pipe, PipeProxyErrors };
/**
* Return true if the argument is a Minipass stream, Node stream, or something
* else that Minipass can interact with.
*/
export declare const isStream: (s: any) => s is Minipass<any, any, any> | NodeJS.ReadStream | NodeJS.WriteStream | (EventEmitter<any> & {
end(): any;
write(chunk: any, ...args: any[]): any;
}) | (EventEmitter<any> & {
pause(): any;
resume(): any;
pipe(...destArgs: any[]): any;
}) | (NodeJS.ReadStream & {
fd: number;
}) | (NodeJS.WriteStream & {
fd: number;
});
/**
* Return true if the argument is a valid {@link Minipass.Readable}
*/
export declare const isReadable: (s: any) => s is Minipass.Readable;
/**
* Return true if the argument is a valid {@link Minipass.Writable}
*/
export declare const isWritable: (s: any) => s is Minipass.Readable;
declare const EOF: unique symbol;
declare const MAYBE_EMIT_END: unique symbol;
declare const EMITTED_END: unique symbol;
declare const EMITTING_END: unique symbol;
declare const EMITTED_ERROR: unique symbol;
declare const CLOSED: unique symbol;
declare const READ: unique symbol;
declare const FLUSH: unique symbol;
declare const FLUSHCHUNK: unique symbol;
declare const ENCODING: unique symbol;
declare const DECODER: unique symbol;
declare const FLOWING: unique symbol;
declare const PAUSED: unique symbol;
declare const RESUME: unique symbol;
declare const BUFFER: unique symbol;
declare const PIPES: unique symbol;
declare const BUFFERLENGTH: unique symbol;
declare const BUFFERPUSH: unique symbol;
declare const BUFFERSHIFT: unique symbol;
declare const OBJECTMODE: unique symbol;
declare const DESTROYED: unique symbol;
declare const ERROR: unique symbol;
declare const EMITDATA: unique symbol;
declare const EMITEND: unique symbol;
declare const EMITEND2: unique symbol;
declare const ASYNC: unique symbol;
declare const ABORT: unique symbol;
declare const ABORTED: unique symbol;
declare const SIGNAL: unique symbol;
declare const DATALISTENERS: unique symbol;
declare const DISCARDED: unique symbol;
/**
* Options that may be passed to stream.pipe()
*/
export interface PipeOptions {
/**
* end the destination stream when the source stream ends
*/
end?: boolean;
/**
* proxy errors from the source stream to the destination stream
*/
proxyErrors?: boolean;
}
/**
* Internal class representing a pipe to a destination stream.
*
* @internal
*/
declare class Pipe<T extends unknown> {
src: Minipass<T>;
dest: Minipass<any, T>;
opts: PipeOptions;
ondrain: () => any;
constructor(src: Minipass<T>, dest: Minipass.Writable, opts: PipeOptions);
unpipe(): void;
proxyErrors(_er: any): void;
end(): void;
}
/**
* Internal class representing a pipe to a destination stream where
* errors are proxied.
*
* @internal
*/
declare class PipeProxyErrors<T> extends Pipe<T> {
unpipe(): void;
constructor(src: Minipass<T>, dest: Minipass.Writable, opts: PipeOptions);
}
export declare namespace Minipass {
/**
* Encoding used to create a stream that outputs strings rather than
* Buffer objects.
*/
export type Encoding = BufferEncoding | 'buffer' | null;
/**
* Any stream that Minipass can pipe into
*/
export type Writable = Minipass<any, any, any> | NodeJS.WriteStream | (NodeJS.WriteStream & {
fd: number;
}) | (EventEmitter & {
end(): any;
write(chunk: any, ...args: any[]): any;
});
/**
* Any stream that can be read from
*/
export type Readable = Minipass<any, any, any> | NodeJS.ReadStream | (NodeJS.ReadStream & {
fd: number;
}) | (EventEmitter & {
pause(): any;
resume(): any;
pipe(...destArgs: any[]): any;
});
/**
* Utility type that can be iterated sync or async
*/
export type DualIterable<T> = Iterable<T> & AsyncIterable<T>;
type EventArguments = Record<string | symbol, unknown[]>;
/**
* The listing of events that a Minipass class can emit.
* Extend this when extending the Minipass class, and pass as
* the third template argument. The key is the name of the event,
* and the value is the argument list.
*
* Any undeclared events will still be allowed, but the handler will get
* arguments as `unknown[]`.
*/
export interface Events<RType extends any = Buffer> extends EventArguments {
readable: [];
data: [chunk: RType];
error: [er: unknown];
abort: [reason: unknown];
drain: [];
resume: [];
end: [];
finish: [];
prefinish: [];
close: [];
[DESTROYED]: [er?: unknown];
[ERROR]: [er: unknown];
}
/**
* String or buffer-like data that can be joined and sliced
*/
export type ContiguousData = Buffer | ArrayBufferLike | ArrayBufferView | string;
export type BufferOrString = Buffer | string;
/**
* Options passed to the Minipass constructor.
*/
export type SharedOptions = {
/**
* Defer all data emission and other events until the end of the
* current tick, similar to Node core streams
*/
async?: boolean;
/**
* A signal which will abort the stream
*/
signal?: AbortSignal;
/**
* Output string encoding. Set to `null` or `'buffer'` (or omit) to
* emit Buffer objects rather than strings.
*
* Conflicts with `objectMode`
*/
encoding?: BufferEncoding | null | 'buffer';
/**
* Output data exactly as it was written, supporting non-buffer/string
* data (such as arbitrary objects, falsey values, etc.)
*
* Conflicts with `encoding`
*/
objectMode?: boolean;
};
/**
* Options for a string encoded output
*/
export type EncodingOptions = SharedOptions & {
encoding: BufferEncoding;
objectMode?: false;
};
/**
* Options for contiguous data buffer output
*/
export type BufferOptions = SharedOptions & {
encoding?: null | 'buffer';
objectMode?: false;
};
/**
* Options for objectMode arbitrary output
*/
export type ObjectModeOptions = SharedOptions & {
objectMode: true;
encoding?: null;
};
/**
* Utility type to determine allowed options based on read type
*/
export type Options<T> = ObjectModeOptions | (T extends string ? EncodingOptions : T extends Buffer ? BufferOptions : SharedOptions);
export {};
}
/**
* Main export, the Minipass class
*
* `RType` is the type of data emitted, defaults to Buffer
*
* `WType` is the type of data to be written, if RType is buffer or string,
* then any {@link Minipass.ContiguousData} is allowed.
*
* `Events` is the set of event handler signatures that this object
* will emit, see {@link Minipass.Events}
*/
export declare class Minipass<RType extends unknown = Buffer, WType extends unknown = RType extends Minipass.BufferOrString ? Minipass.ContiguousData : RType, Events extends Minipass.Events<RType> = Minipass.Events<RType>> extends EventEmitter implements Minipass.DualIterable<RType> {
[FLOWING]: boolean;
[PAUSED]: boolean;
[PIPES]: Pipe<RType>[];
[BUFFER]: RType[];
[OBJECTMODE]: boolean;
[ENCODING]: BufferEncoding | null;
[ASYNC]: boolean;
[DECODER]: SD | null;
[EOF]: boolean;
[EMITTED_END]: boolean;
[EMITTING_END]: boolean;
[CLOSED]: boolean;
[EMITTED_ERROR]: unknown;
[BUFFERLENGTH]: number;
[DESTROYED]: boolean;
[SIGNAL]?: AbortSignal;
[ABORTED]: boolean;
[DATALISTENERS]: number;
[DISCARDED]: boolean;
/**
* true if the stream can be written
*/
writable: boolean;
/**
* true if the stream can be read
*/
readable: boolean;
/**
* If `RType` is Buffer, then options do not need to be provided.
* Otherwise, an options object must be provided to specify either
* {@link Minipass.SharedOptions.objectMode} or
* {@link Minipass.SharedOptions.encoding}, as appropriate.
*/
constructor(...args: [Minipass.ObjectModeOptions] | (RType extends Buffer ? [] | [Minipass.Options<RType>] : [Minipass.Options<RType>]));
/**
* The amount of data stored in the buffer waiting to be read.
*
* For Buffer strings, this will be the total byte length.
* For string encoding streams, this will be the string character length,
* according to JavaScript's `string.length` logic.
* For objectMode streams, this is a count of the items waiting to be
* emitted.
*/
get bufferLength(): number;
/**
* The `BufferEncoding` currently in use, or `null`
*/
get encoding(): BufferEncoding | null;
/**
* @deprecated - This is a read only property
*/
set encoding(_enc: BufferEncoding | null);
/**
* @deprecated - Encoding may only be set at instantiation time
*/
setEncoding(_enc: Minipass.Encoding): void;
/**
* True if this is an objectMode stream
*/
get objectMode(): boolean;
/**
* @deprecated - This is a read-only property
*/
set objectMode(_om: boolean);
/**
* true if this is an async stream
*/
get ['async'](): boolean;
/**
* Set to true to make this stream async.
*
* Once set, it cannot be unset, as this would potentially cause incorrect
* behavior. Ie, a sync stream can be made async, but an async stream
* cannot be safely made sync.
*/
set ['async'](a: boolean);
[ABORT](): void;
/**
* True if the stream has been aborted.
*/
get aborted(): boolean;
/**
* No-op setter. Stream aborted status is set via the AbortSignal provided
* in the constructor options.
*/
set aborted(_: boolean);
/**
* Write data into the stream
*
* If the chunk written is a string, and encoding is not specified, then
* `utf8` will be assumed. If the stream encoding matches the encoding of
* a written string, and the state of the string decoder allows it, then
* the string will be passed through to either the output or the internal
* buffer without any processing. Otherwise, it will be turned into a
* Buffer object for processing into the desired encoding.
*
* If provided, `cb` function is called immediately before return for
* sync streams, or on next tick for async streams, because for this
* base class, a chunk is considered "processed" once it is accepted
* and either emitted or buffered. That is, the callback does not indicate
* that the chunk has been eventually emitted, though of course child
* classes can override this function to do whatever processing is required
* and call `super.write(...)` only once processing is completed.
*/
write(chunk: WType, cb?: () => void): boolean;
write(chunk: WType, encoding?: Minipass.Encoding, cb?: () => void): boolean;
/**
* Low-level explicit read method.
*
* In objectMode, the argument is ignored, and one item is returned if
* available.
*
* `n` is the number of bytes (or in the case of encoding streams,
* characters) to consume. If `n` is not provided, then the entire buffer
* is returned, or `null` is returned if no data is available.
*
* If `n` is greater that the amount of data in the internal buffer,
* then `null` is returned.
*/
read(n?: number | null): RType | null;
[READ](n: number | null, chunk: RType): RType;
/**
* End the stream, optionally providing a final write.
*
* See {@link Minipass#write} for argument descriptions
*/
end(cb?: () => void): this;
end(chunk: WType, cb?: () => void): this;
end(chunk: WType, encoding?: Minipass.Encoding, cb?: () => void): this;
[RESUME](): void;
/**
* Resume the stream if it is currently in a paused state
*
* If called when there are no pipe destinations or `data` event listeners,
* this will place the stream in a "discarded" state, where all data will
* be thrown away. The discarded state is removed if a pipe destination or
* data handler is added, if pause() is called, or if any synchronous or
* asynchronous iteration is started.
*/
resume(): void;
/**
* Pause the stream
*/
pause(): void;
/**
* true if the stream has been forcibly destroyed
*/
get destroyed(): boolean;
/**
* true if the stream is currently in a flowing state, meaning that
* any writes will be immediately emitted.
*/
get flowing(): boolean;
/**
* true if the stream is currently in a paused state
*/
get paused(): boolean;
[BUFFERPUSH](chunk: RType): void;
[BUFFERSHIFT](): RType;
[FLUSH](noDrain?: boolean): void;
[FLUSHCHUNK](chunk: RType): boolean;
/**
* Pipe all data emitted by this stream into the destination provided.
*
* Triggers the flow of data.
*/
pipe<W extends Minipass.Writable>(dest: W, opts?: PipeOptions): W;
/**
* Fully unhook a piped destination stream.
*
* If the destination stream was the only consumer of this stream (ie,
* there are no other piped destinations or `'data'` event listeners)
* then the flow of data will stop until there is another consumer or
* {@link Minipass#resume} is explicitly called.
*/
unpipe<W extends Minipass.Writable>(dest: W): void;
/**
* Alias for {@link Minipass#on}
*/
addListener<Event extends keyof Events>(ev: Event, handler: (...args: Events[Event]) => any): this;
/**
* Mostly identical to `EventEmitter.on`, with the following
* behavior differences to prevent data loss and unnecessary hangs:
*
* - Adding a 'data' event handler will trigger the flow of data
*
* - Adding a 'readable' event handler when there is data waiting to be read
* will cause 'readable' to be emitted immediately.
*
* - Adding an 'endish' event handler ('end', 'finish', etc.) which has
* already passed will cause the event to be emitted immediately and all
* handlers removed.
*
* - Adding an 'error' event handler after an error has been emitted will
* cause the event to be re-emitted immediately with the error previously
* raised.
*/
on<Event extends keyof Events>(ev: Event, handler: (...args: Events[Event]) => any): this;
/**
* Alias for {@link Minipass#off}
*/
removeListener<Event extends keyof Events>(ev: Event, handler: (...args: Events[Event]) => any): this;
/**
* Mostly identical to `EventEmitter.off`
*
* If a 'data' event handler is removed, and it was the last consumer
* (ie, there are no pipe destinations or other 'data' event listeners),
* then the flow of data will stop until there is another consumer or
* {@link Minipass#resume} is explicitly called.
*/
off<Event extends keyof Events>(ev: Event, handler: (...args: Events[Event]) => any): this;
/**
* Mostly identical to `EventEmitter.removeAllListeners`
*
* If all 'data' event handlers are removed, and they were the last consumer
* (ie, there are no pipe destinations), then the flow of data will stop
* until there is another consumer or {@link Minipass#resume} is explicitly
* called.
*/
removeAllListeners<Event extends keyof Events>(ev?: Event): this;
/**
* true if the 'end' event has been emitted
*/
get emittedEnd(): boolean;
[MAYBE_EMIT_END](): void;
/**
* Mostly identical to `EventEmitter.emit`, with the following
* behavior differences to prevent data loss and unnecessary hangs:
*
* If the stream has been destroyed, and the event is something other
* than 'close' or 'error', then `false` is returned and no handlers
* are called.
*
* If the event is 'end', and has already been emitted, then the event
* is ignored. If the stream is in a paused or non-flowing state, then
* the event will be deferred until data flow resumes. If the stream is
* async, then handlers will be called on the next tick rather than
* immediately.
*
* If the event is 'close', and 'end' has not yet been emitted, then
* the event will be deferred until after 'end' is emitted.
*
* If the event is 'error', and an AbortSignal was provided for the stream,
* and there are no listeners, then the event is ignored, matching the
* behavior of node core streams in the presense of an AbortSignal.
*
* If the event is 'finish' or 'prefinish', then all listeners will be
* removed after emitting the event, to prevent double-firing.
*/
emit<Event extends keyof Events>(ev: Event, ...args: Events[Event]): boolean;
[EMITDATA](data: RType): boolean;
[EMITEND](): boolean;
[EMITEND2](): boolean;
/**
* Return a Promise that resolves to an array of all emitted data once
* the stream ends.
*/
collect(): Promise<RType[] & {
dataLength: number;
}>;
/**
* Return a Promise that resolves to the concatenation of all emitted data
* once the stream ends.
*
* Not allowed on objectMode streams.
*/
concat(): Promise<RType>;
/**
* Return a void Promise that resolves once the stream ends.
*/
promise(): Promise<void>;
/**
* Asynchronous `for await of` iteration.
*
* This will continue emitting all chunks until the stream terminates.
*/
[Symbol.asyncIterator](): AsyncGenerator<RType, void, void>;
/**
* Synchronous `for of` iteration.
*
* The iteration will terminate when the internal buffer runs out, even
* if the stream has not yet terminated.
*/
[Symbol.iterator](): Generator<RType, void, void>;
/**
* Destroy a stream, preventing it from being used for any further purpose.
*
* If the stream has a `close()` method, then it will be called on
* destruction.
*
* After destruction, any attempt to write data, read data, or emit most
* events will be ignored.
*
* If an error argument is provided, then it will be emitted in an
* 'error' event.
*/
destroy(er?: unknown): this;
/**
* Alias for {@link isStream}
*
* Former export location, maintained for backwards compatibility.
*
* @deprecated
*/
static get isStream(): (s: any) => s is Minipass<any, any, any> | NodeJS.ReadStream | NodeJS.WriteStream | (EventEmitter<any> & {
end(): any;
write(chunk: any, ...args: any[]): any;
}) | (EventEmitter<any> & {
pause(): any;
resume(): any;
pipe(...destArgs: any[]): any;
}) | (NodeJS.ReadStream & {
fd: number;
}) | (NodeJS.WriteStream & {
fd: number;
});
}
//# sourceMappingURL=index.d.ts.map

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

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

View file

@ -0,0 +1,2 @@
export declare const constants: any;
//# sourceMappingURL=constants.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,SAAS,KAiHrB,CAAA"}

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

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,99 @@
import { Buffer } from 'buffer';
import { Minipass } from 'minipass';
import * as realZlib from 'zlib';
export { constants } from './constants.js';
declare const _superWrite: unique symbol;
export declare class ZlibError extends Error {
code?: string;
errno?: number;
constructor(err: NodeJS.ErrnoException | Error, origin?: Function);
get name(): string;
}
declare const _flushFlag: unique symbol;
export type ChunkWithFlushFlag = Minipass.ContiguousData & {
[_flushFlag]?: number;
};
export type ZlibBaseOptions = Minipass.Options<Minipass.ContiguousData> & {
flush?: number;
finishFlush?: number;
fullFlushFlag?: number;
};
export type ZlibHandle = realZlib.Gzip | realZlib.Gunzip | realZlib.Deflate | realZlib.Inflate | realZlib.DeflateRaw | realZlib.InflateRaw | realZlib.BrotliCompress | realZlib.BrotliDecompress | realZlib.ZstdCompress | realZlib.ZstdDecompress;
export type ZlibMode = 'Gzip' | 'Gunzip' | 'Deflate' | 'Inflate' | 'DeflateRaw' | 'InflateRaw' | 'Unzip';
export type BrotliMode = 'BrotliCompress' | 'BrotliDecompress';
export type ZstdMode = 'ZstdCompress' | 'ZstdDecompress';
declare abstract class ZlibBase extends Minipass<Buffer, ChunkWithFlushFlag> {
#private;
get sawError(): boolean;
get handle(): ZlibHandle | undefined;
get flushFlag(): number;
constructor(opts: ZlibBaseOptions, mode: ZlibMode | BrotliMode | ZstdMode);
close(): void;
reset(): any;
flush(flushFlag?: number): void;
end(cb?: () => void): this;
end(chunk: ChunkWithFlushFlag, cb?: () => void): this;
end(chunk: ChunkWithFlushFlag, encoding?: Minipass.Encoding, cb?: () => void): this;
get ended(): boolean;
[_superWrite](data: Buffer & {
[_flushFlag]?: number;
}): boolean;
write(chunk: ChunkWithFlushFlag, cb?: () => void): boolean;
write(chunk: ChunkWithFlushFlag, encoding?: Minipass.Encoding, cb?: () => void): boolean;
}
export type ZlibOptions = ZlibBaseOptions & {
level?: number;
strategy?: number;
};
export declare class Zlib extends ZlibBase {
#private;
constructor(opts: ZlibOptions, mode: ZlibMode);
params(level: number, strategy: number): void;
}
export declare class Deflate extends Zlib {
constructor(opts: ZlibOptions);
}
export declare class Inflate extends Zlib {
constructor(opts: ZlibOptions);
}
export type GzipOptions = ZlibOptions & {
portable?: boolean;
};
export declare class Gzip extends Zlib {
#private;
constructor(opts: GzipOptions);
[_superWrite](data: Buffer & {
[_flushFlag]?: number;
}): boolean;
}
export declare class Gunzip extends Zlib {
constructor(opts: ZlibOptions);
}
export declare class DeflateRaw extends Zlib {
constructor(opts: ZlibOptions);
}
export declare class InflateRaw extends Zlib {
constructor(opts: ZlibOptions);
}
export declare class Unzip extends Zlib {
constructor(opts: ZlibOptions);
}
declare class Brotli extends ZlibBase {
constructor(opts: ZlibOptions, mode: BrotliMode);
}
export declare class BrotliCompress extends Brotli {
constructor(opts: ZlibOptions);
}
export declare class BrotliDecompress extends Brotli {
constructor(opts: ZlibOptions);
}
declare class Zstd extends ZlibBase {
constructor(opts: ZlibOptions, mode: ZstdMode);
}
export declare class ZstdCompress extends Zstd {
constructor(opts: ZlibOptions);
}
export declare class ZstdDecompress extends Zstd {
constructor(opts: ZlibOptions);
}
//# sourceMappingURL=index.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,KAAK,QAAQ,MAAM,MAAM,CAAA;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAY1C,QAAA,MAAM,WAAW,eAAwB,CAAA;AAEzC,qBAAa,SAAU,SAAQ,KAAK;IAClC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;gBACF,GAAG,EAAE,MAAM,CAAC,cAAc,GAAG,KAAK,EAAE,MAAM,CAAC,EAAE,QAAQ;IAWjE,IAAI,IAAI,WAEP;CACF;AAMD,QAAA,MAAM,UAAU,eAAsB,CAAA;AAEtC,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC,cAAc,GAAG;IACzD,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,CAAA;CACtB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AAa,UAAW,SAAQ,IAAI;gBACtB,IAAI,EAAE,WAAW;CAG9B;AAGD,qBAAa,KAAM,SAAQ,IAAI;gBACjB,IAAI,EAAE,WAAW;CAG9B;AAED,cAAM,MAAO,SAAQ,QAAQ;gBACf,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU;CAShD;AAED,qBAAa,cAAe,SAAQ,MAAM;gBAC5B,IAAI,EAAE,WAAW;CAG9B;AAED,qBAAa,gBAAiB,SAAQ,MAAM;gBAC9B,IAAI,EAAE,WAAW;CAG9B;AAED,cAAM,IAAK,SAAQ,QAAQ;gBACb,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ;CAQ9C;AAED,qBAAa,YAAa,SAAQ,IAAI;gBACxB,IAAI,EAAE,WAAW;CAG9B;AAED,qBAAa,cAAe,SAAQ,IAAI;gBAC1B,IAAI,EAAE,WAAW;CAG9B"}

View file

@ -0,0 +1,416 @@
"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.ZstdDecompress = exports.ZstdCompress = exports.BrotliDecompress = exports.BrotliCompress = 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, origin) {
super('zlib: ' + err.message, { cause: err });
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, origin ?? 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 */
//@ts-ignore
if (typeof realZlib[mode] !== 'function') {
throw new TypeError('Compression method not supported: ' + mode);
}
// 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.constructor);
}
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, this.write));
}
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, this.write)));
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);
}
}
class BrotliCompress extends Brotli {
constructor(opts) {
super(opts, 'BrotliCompress');
}
}
exports.BrotliCompress = BrotliCompress;
class BrotliDecompress extends Brotli {
constructor(opts) {
super(opts, 'BrotliDecompress');
}
}
exports.BrotliDecompress = BrotliDecompress;
class Zstd extends ZlibBase {
constructor(opts, mode) {
opts = opts || {};
opts.flush = opts.flush || constants_js_1.constants.ZSTD_e_continue;
opts.finishFlush = opts.finishFlush || constants_js_1.constants.ZSTD_e_end;
opts.fullFlushFlag = constants_js_1.constants.ZSTD_e_flush;
super(opts, mode);
}
}
class ZstdCompress extends Zstd {
constructor(opts) {
super(opts, 'ZstdCompress');
}
}
exports.ZstdCompress = ZstdCompress;
class ZstdDecompress extends Zstd {
constructor(opts) {
super(opts, 'ZstdDecompress');
}
}
exports.ZstdDecompress = ZstdDecompress;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View file

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

View file

@ -0,0 +1,2 @@
export declare const constants: any;
//# sourceMappingURL=constants.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,SAAS,KAiHrB,CAAA"}

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

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,99 @@
import { Buffer } from 'buffer';
import { Minipass } from 'minipass';
import * as realZlib from 'zlib';
export { constants } from './constants.js';
declare const _superWrite: unique symbol;
export declare class ZlibError extends Error {
code?: string;
errno?: number;
constructor(err: NodeJS.ErrnoException | Error, origin?: Function);
get name(): string;
}
declare const _flushFlag: unique symbol;
export type ChunkWithFlushFlag = Minipass.ContiguousData & {
[_flushFlag]?: number;
};
export type ZlibBaseOptions = Minipass.Options<Minipass.ContiguousData> & {
flush?: number;
finishFlush?: number;
fullFlushFlag?: number;
};
export type ZlibHandle = realZlib.Gzip | realZlib.Gunzip | realZlib.Deflate | realZlib.Inflate | realZlib.DeflateRaw | realZlib.InflateRaw | realZlib.BrotliCompress | realZlib.BrotliDecompress | realZlib.ZstdCompress | realZlib.ZstdDecompress;
export type ZlibMode = 'Gzip' | 'Gunzip' | 'Deflate' | 'Inflate' | 'DeflateRaw' | 'InflateRaw' | 'Unzip';
export type BrotliMode = 'BrotliCompress' | 'BrotliDecompress';
export type ZstdMode = 'ZstdCompress' | 'ZstdDecompress';
declare abstract class ZlibBase extends Minipass<Buffer, ChunkWithFlushFlag> {
#private;
get sawError(): boolean;
get handle(): ZlibHandle | undefined;
get flushFlag(): number;
constructor(opts: ZlibBaseOptions, mode: ZlibMode | BrotliMode | ZstdMode);
close(): void;
reset(): any;
flush(flushFlag?: number): void;
end(cb?: () => void): this;
end(chunk: ChunkWithFlushFlag, cb?: () => void): this;
end(chunk: ChunkWithFlushFlag, encoding?: Minipass.Encoding, cb?: () => void): this;
get ended(): boolean;
[_superWrite](data: Buffer & {
[_flushFlag]?: number;
}): boolean;
write(chunk: ChunkWithFlushFlag, cb?: () => void): boolean;
write(chunk: ChunkWithFlushFlag, encoding?: Minipass.Encoding, cb?: () => void): boolean;
}
export type ZlibOptions = ZlibBaseOptions & {
level?: number;
strategy?: number;
};
export declare class Zlib extends ZlibBase {
#private;
constructor(opts: ZlibOptions, mode: ZlibMode);
params(level: number, strategy: number): void;
}
export declare class Deflate extends Zlib {
constructor(opts: ZlibOptions);
}
export declare class Inflate extends Zlib {
constructor(opts: ZlibOptions);
}
export type GzipOptions = ZlibOptions & {
portable?: boolean;
};
export declare class Gzip extends Zlib {
#private;
constructor(opts: GzipOptions);
[_superWrite](data: Buffer & {
[_flushFlag]?: number;
}): boolean;
}
export declare class Gunzip extends Zlib {
constructor(opts: ZlibOptions);
}
export declare class DeflateRaw extends Zlib {
constructor(opts: ZlibOptions);
}
export declare class InflateRaw extends Zlib {
constructor(opts: ZlibOptions);
}
export declare class Unzip extends Zlib {
constructor(opts: ZlibOptions);
}
declare class Brotli extends ZlibBase {
constructor(opts: ZlibOptions, mode: BrotliMode);
}
export declare class BrotliCompress extends Brotli {
constructor(opts: ZlibOptions);
}
export declare class BrotliDecompress extends Brotli {
constructor(opts: ZlibOptions);
}
declare class Zstd extends ZlibBase {
constructor(opts: ZlibOptions, mode: ZstdMode);
}
export declare class ZstdCompress extends Zstd {
constructor(opts: ZlibOptions);
}
export declare class ZstdDecompress extends Zstd {
constructor(opts: ZlibOptions);
}
//# sourceMappingURL=index.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,KAAK,QAAQ,MAAM,MAAM,CAAA;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAY1C,QAAA,MAAM,WAAW,eAAwB,CAAA;AAEzC,qBAAa,SAAU,SAAQ,KAAK;IAClC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;gBACF,GAAG,EAAE,MAAM,CAAC,cAAc,GAAG,KAAK,EAAE,MAAM,CAAC,EAAE,QAAQ;IAWjE,IAAI,IAAI,WAEP;CACF;AAMD,QAAA,MAAM,UAAU,eAAsB,CAAA;AAEtC,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC,cAAc,GAAG;IACzD,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG;IACxE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,UAAU,GAClB,QAAQ,CAAC,IAAI,GACb,QAAQ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;AAED,qBAAa,gBAAiB,SAAQ,MAAM;gBAC9B,IAAI,EAAE,WAAW;CAG9B;AAED,cAAM,IAAK,SAAQ,QAAQ;gBACb,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ;CAQ9C;AAED,qBAAa,YAAa,SAAQ,IAAI;gBACxB,IAAI,EAAE,WAAW;CAG9B;AAED,qBAAa,cAAe,SAAQ,IAAI;gBAC1B,IAAI,EAAE,WAAW;CAG9B"}

View file

@ -0,0 +1,363 @@
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, origin) {
super('zlib: ' + err.message, { cause: err });
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, origin ?? 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 */
//@ts-ignore
if (typeof realZlib[mode] !== 'function') {
throw new TypeError('Compression method not supported: ' + mode);
}
// 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.constructor);
}
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, this.write));
}
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, this.write)));
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');
}
}
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');
}
}
class Zstd extends ZlibBase {
constructor(opts, mode) {
opts = opts || {};
opts.flush = opts.flush || constants.ZSTD_e_continue;
opts.finishFlush = opts.finishFlush || constants.ZSTD_e_end;
opts.fullFlushFlag = constants.ZSTD_e_flush;
super(opts, mode);
}
}
export class ZstdCompress extends Zstd {
constructor(opts) {
super(opts, 'ZstdCompress');
}
}
export class ZstdDecompress extends Zstd {
constructor(opts) {
super(opts, 'ZstdDecompress');
}
}
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View file

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

View file

@ -0,0 +1,39 @@
export declare class Yallist<T = unknown> {
tail?: Node<T>;
head?: Node<T>;
length: number;
static create<T = unknown>(list?: Iterable<T>): Yallist<T>;
constructor(list?: Iterable<T>);
[Symbol.iterator](): Generator<T, void, unknown>;
removeNode(node: Node<T>): Node<T> | undefined;
unshiftNode(node: Node<T>): void;
pushNode(node: Node<T>): void;
push(...args: T[]): number;
unshift(...args: T[]): number;
pop(): T | undefined;
shift(): T | undefined;
forEach(fn: (value: T, i: number, list: Yallist<T>) => any, thisp?: any): void;
forEachReverse(fn: (value: T, i: number, list: Yallist<T>) => any, thisp?: any): void;
get(n: number): T | undefined;
getReverse(n: number): T | undefined;
map<R = any>(fn: (value: T, list: Yallist<T>) => R, thisp?: any): Yallist<R>;
mapReverse<R = any>(fn: (value: T, list: Yallist<T>) => R, thisp?: any): Yallist<R>;
reduce(fn: (left: T, right: T, i: number) => T): T;
reduce<R = any>(fn: (acc: R, next: T, i: number) => R, initial: R): R;
reduceReverse(fn: (left: T, right: T, i: number) => T): T;
reduceReverse<R = any>(fn: (acc: R, next: T, i: number) => R, initial: R): R;
toArray(): any[];
toArrayReverse(): any[];
slice(from?: number, to?: number): Yallist<unknown>;
sliceReverse(from?: number, to?: number): Yallist<unknown>;
splice(start: number, deleteCount?: number, ...nodes: T[]): T[];
reverse(): this;
}
export declare class Node<T = unknown> {
list?: Yallist<T>;
next?: Node<T>;
prev?: Node<T>;
value: T;
constructor(value: T, prev?: Node<T> | undefined, next?: Node<T> | undefined, list?: Yallist<T> | undefined);
}
//# sourceMappingURL=index.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,qBAAa,OAAO,CAAC,CAAC,GAAG,OAAO;IAC9B,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IACd,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IACd,MAAM,EAAE,MAAM,CAAI;IAElB,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,GAAE,QAAQ,CAAC,CAAC,CAAM;gBAIrC,IAAI,GAAE,QAAQ,CAAC,CAAC,CAAM;IAMjC,CAAC,MAAM,CAAC,QAAQ,CAAC;IAMlB,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAiCxB,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAuBzB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAuBtB,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;IAOjB,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;IAOpB,GAAG;IAkBH,KAAK;IAkBL,OAAO,CACL,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,EAClD,KAAK,CAAC,EAAE,GAAG;IASb,cAAc,CACZ,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG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oB;IA4BvD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,GAAE,MAAU,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE;IAgC5D,OAAO;CAYR;AAwCD,qBAAa,IAAI,CAAC,CAAC,GAAG,OAAO;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IACjB,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IACd,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IACd,KAAK,EAAE,CAAC,CAAA;gBAGN,KAAK,EAAE,CAAC,EACR,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS,EAC1B,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS,EAC1B,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS;CAmBhC"}

View file

@ -0,0 +1,384 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Node = exports.Yallist = void 0;
class Yallist {
tail;
head;
length = 0;
static create(list = []) {
return new Yallist(list);
}
constructor(list = []) {
for (const item of list) {
this.push(item);
}
}
*[Symbol.iterator]() {
for (let walker = this.head; walker; walker = walker.next) {
yield walker.value;
}
}
removeNode(node) {
if (node.list !== this) {
throw new Error('removing node which does not belong to this list');
}
const next = node.next;
const prev = node.prev;
if (next) {
next.prev = prev;
}
if (prev) {
prev.next = next;
}
if (node === this.head) {
this.head = next;
}
if (node === this.tail) {
this.tail = prev;
}
this.length--;
node.next = undefined;
node.prev = undefined;
node.list = undefined;
return next;
}
unshiftNode(node) {
if (node === this.head) {
return;
}
if (node.list) {
node.list.removeNode(node);
}
const head = this.head;
node.list = this;
node.next = head;
if (head) {
head.prev = node;
}
this.head = node;
if (!this.tail) {
this.tail = node;
}
this.length++;
}
pushNode(node) {
if (node === this.tail) {
return;
}
if (node.list) {
node.list.removeNode(node);
}
const tail = this.tail;
node.list = this;
node.prev = tail;
if (tail) {
tail.next = node;
}
this.tail = node;
if (!this.head) {
this.head = node;
}
this.length++;
}
push(...args) {
for (let i = 0, l = args.length; i < l; i++) {
push(this, args[i]);
}
return this.length;
}
unshift(...args) {
for (var i = 0, l = args.length; i < l; i++) {
unshift(this, args[i]);
}
return this.length;
}
pop() {
if (!this.tail) {
return undefined;
}
const res = this.tail.value;
const t = this.tail;
this.tail = this.tail.prev;
if (this.tail) {
this.tail.next = undefined;
}
else {
this.head = undefined;
}
t.list = undefined;
this.length--;
return res;
}
shift() {
if (!this.head) {
return undefined;
}
const res = this.head.value;
const h = this.head;
this.head = this.head.next;
if (this.head) {
this.head.prev = undefined;
}
else {
this.tail = undefined;
}
h.list = undefined;
this.length--;
return res;
}
forEach(fn, thisp) {
thisp = thisp || this;
for (let walker = this.head, i = 0; !!walker; i++) {
fn.call(thisp, walker.value, i, this);
walker = walker.next;
}
}
forEachReverse(fn, thisp) {
thisp = thisp || this;
for (let walker = this.tail, i = this.length - 1; !!walker; i--) {
fn.call(thisp, walker.value, i, this);
walker = walker.prev;
}
}
get(n) {
let i = 0;
let walker = this.head;
for (; !!walker && i < n; i++) {
walker = walker.next;
}
if (i === n && !!walker) {
return walker.value;
}
}
getReverse(n) {
let i = 0;
let walker = this.tail;
for (; !!walker && i < n; i++) {
// abort out of the list early if we hit a cycle
walker = walker.prev;
}
if (i === n && !!walker) {
return walker.value;
}
}
map(fn, thisp) {
thisp = thisp || this;
const res = new Yallist();
for (let walker = this.head; !!walker;) {
res.push(fn.call(thisp, walker.value, this));
walker = walker.next;
}
return res;
}
mapReverse(fn, thisp) {
thisp = thisp || this;
var res = new Yallist();
for (let walker = this.tail; !!walker;) {
res.push(fn.call(thisp, walker.value, this));
walker = walker.prev;
}
return res;
}
reduce(fn, initial) {
let acc;
let walker = this.head;
if (arguments.length > 1) {
acc = initial;
}
else if (this.head) {
walker = this.head.next;
acc = this.head.value;
}
else {
throw new TypeError('Reduce of empty list with no initial value');
}
for (var i = 0; !!walker; i++) {
acc = fn(acc, walker.value, i);
walker = walker.next;
}
return acc;
}
reduceReverse(fn, initial) {
let acc;
let walker = this.tail;
if (arguments.length > 1) {
acc = initial;
}
else if (this.tail) {
walker = this.tail.prev;
acc = this.tail.value;
}
else {
throw new TypeError('Reduce of empty list with no initial value');
}
for (let i = this.length - 1; !!walker; i--) {
acc = fn(acc, walker.value, i);
walker = walker.prev;
}
return acc;
}
toArray() {
const arr = new Array(this.length);
for (let i = 0, walker = this.head; !!walker; i++) {
arr[i] = walker.value;
walker = walker.next;
}
return arr;
}
toArrayReverse() {
const arr = new Array(this.length);
for (let i = 0, walker = this.tail; !!walker; i++) {
arr[i] = walker.value;
walker = walker.prev;
}
return arr;
}
slice(from = 0, to = this.length) {
if (to < 0) {
to += this.length;
}
if (from < 0) {
from += this.length;
}
const ret = new Yallist();
if (to < from || to < 0) {
return ret;
}
if (from < 0) {
from = 0;
}
if (to > this.length) {
to = this.length;
}
let walker = this.head;
let i = 0;
for (i = 0; !!walker && i < from; i++) {
walker = walker.next;
}
for (; !!walker && i < to; i++, walker = walker.next) {
ret.push(walker.value);
}
return ret;
}
sliceReverse(from = 0, to = this.length) {
if (to < 0) {
to += this.length;
}
if (from < 0) {
from += this.length;
}
const ret = new Yallist();
if (to < from || to < 0) {
return ret;
}
if (from < 0) {
from = 0;
}
if (to > this.length) {
to = this.length;
}
let i = this.length;
let walker = this.tail;
for (; !!walker && i > to; i--) {
walker = walker.prev;
}
for (; !!walker && i > from; i--, walker = walker.prev) {
ret.push(walker.value);
}
return ret;
}
splice(start, deleteCount = 0, ...nodes) {
if (start > this.length) {
start = this.length - 1;
}
if (start < 0) {
start = this.length + start;
}
let walker = this.head;
for (let i = 0; !!walker && i < start; i++) {
walker = walker.next;
}
const ret = [];
for (let i = 0; !!walker && i < deleteCount; i++) {
ret.push(walker.value);
walker = this.removeNode(walker);
}
if (!walker) {
walker = this.tail;
}
else if (walker !== this.tail) {
walker = walker.prev;
}
for (const v of nodes) {
walker = insertAfter(this, walker, v);
}
return ret;
}
reverse() {
const head = this.head;
const tail = this.tail;
for (let walker = head; !!walker; walker = walker.prev) {
const p = walker.prev;
walker.prev = walker.next;
walker.next = p;
}
this.head = tail;
this.tail = head;
return this;
}
}
exports.Yallist = Yallist;
// insertAfter undefined means "make the node the new head of list"
function insertAfter(self, node, value) {
const prev = node;
const next = node ? node.next : self.head;
const inserted = new Node(value, prev, next, self);
if (inserted.next === undefined) {
self.tail = inserted;
}
if (inserted.prev === undefined) {
self.head = inserted;
}
self.length++;
return inserted;
}
function push(self, item) {
self.tail = new Node(item, self.tail, undefined, self);
if (!self.head) {
self.head = self.tail;
}
self.length++;
}
function unshift(self, item) {
self.head = new Node(item, undefined, self.head, self);
if (!self.tail) {
self.tail = self.head;
}
self.length++;
}
class Node {
list;
next;
prev;
value;
constructor(value, prev, next, list) {
this.list = list;
this.value = value;
if (prev) {
prev.next = this;
this.prev = prev;
}
else {
this.prev = undefined;
}
if (next) {
next.prev = this;
this.next = next;
}
else {
this.next = undefined;
}
}
}
exports.Node = Node;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View file

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

View file

@ -0,0 +1,39 @@
export declare class Yallist<T = unknown> {
tail?: Node<T>;
head?: Node<T>;
length: number;
static create<T = unknown>(list?: Iterable<T>): Yallist<T>;
constructor(list?: Iterable<T>);
[Symbol.iterator](): Generator<T, void, unknown>;
removeNode(node: Node<T>): Node<T> | undefined;
unshiftNode(node: Node<T>): void;
pushNode(node: Node<T>): void;
push(...args: T[]): number;
unshift(...args: T[]): number;
pop(): T | undefined;
shift(): T | undefined;
forEach(fn: (value: T, i: number, list: Yallist<T>) => any, thisp?: any): void;
forEachReverse(fn: (value: T, i: number, list: Yallist<T>) => any, thisp?: any): void;
get(n: number): T | undefined;
getReverse(n: number): T | undefined;
map<R = any>(fn: (value: T, list: Yallist<T>) => R, thisp?: any): Yallist<R>;
mapReverse<R = any>(fn: (value: T, list: Yallist<T>) => R, thisp?: any): Yallist<R>;
reduce(fn: (left: T, right: T, i: number) => T): T;
reduce<R = any>(fn: (acc: R, next: T, i: number) => R, initial: R): R;
reduceReverse(fn: (left: T, right: T, i: number) => T): T;
reduceReverse<R = any>(fn: (acc: R, next: T, i: number) => R, initial: R): R;
toArray(): any[];
toArrayReverse(): any[];
slice(from?: number, to?: number): Yallist<unknown>;
sliceReverse(from?: number, to?: number): Yallist<unknown>;
splice(start: number, deleteCount?: number, ...nodes: T[]): T[];
reverse(): this;
}
export declare class Node<T = unknown> {
list?: Yallist<T>;
next?: Node<T>;
prev?: Node<T>;
value: T;
constructor(value: T, prev?: Node<T> | undefined, next?: Node<T> | undefined, list?: Yallist<T> | undefined);
}
//# sourceMappingURL=index.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,qBAAa,OAAO,CAAC,CAAC,GAAG,OAAO;IAC9B,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IACd,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IACd,MAAM,EAAE,MAAM,CAAI;IAElB,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,GAAE,QAAQ,CAAC,CAAC,CAAM;gBAIrC,IAAI,GAAE,QAAQ,CAAC,CAAC,CAAM;IAMjC,CAAC,MAAM,CAAC,QAAQ,CAAC;IAMlB,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAiCxB,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAuBzB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAuBtB,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;IAOjB,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;IAOpB,GAAG;IAkBH,KAAK;IAkBL,OAAO,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B,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC,EACrC,OAAO,EAAE,CAAC,GACT,CAAC;IA0BJ,OAAO;IASP,cAAc;IASd,KAAK,CAAC,IAAI,GAAE,MAAU,EAAE,EAAE,GAAE,MAAoB;IA4BhD,YAAY,CAAC,IAAI,GAAE,MAAU,EAAE,EAAE,GAAE,MAAoB;IA4BvD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,GAAE,MAAU,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE;IAgC5D,OAAO;CAYR;AAwCD,qBAAa,IAAI,CAAC,CAAC,GAAG,OAAO;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IACjB,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IACd,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IACd,KAAK,EAAE,CAAC,CAAA;gBAGN,KAAK,EAAE,CAAC,EACR,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS,EAC1B,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS,EAC1B,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS;CAmBhC"}

View file

@ -0,0 +1,379 @@
export class Yallist {
tail;
head;
length = 0;
static create(list = []) {
return new Yallist(list);
}
constructor(list = []) {
for (const item of list) {
this.push(item);
}
}
*[Symbol.iterator]() {
for (let walker = this.head; walker; walker = walker.next) {
yield walker.value;
}
}
removeNode(node) {
if (node.list !== this) {
throw new Error('removing node which does not belong to this list');
}
const next = node.next;
const prev = node.prev;
if (next) {
next.prev = prev;
}
if (prev) {
prev.next = next;
}
if (node === this.head) {
this.head = next;
}
if (node === this.tail) {
this.tail = prev;
}
this.length--;
node.next = undefined;
node.prev = undefined;
node.list = undefined;
return next;
}
unshiftNode(node) {
if (node === this.head) {
return;
}
if (node.list) {
node.list.removeNode(node);
}
const head = this.head;
node.list = this;
node.next = head;
if (head) {
head.prev = node;
}
this.head = node;
if (!this.tail) {
this.tail = node;
}
this.length++;
}
pushNode(node) {
if (node === this.tail) {
return;
}
if (node.list) {
node.list.removeNode(node);
}
const tail = this.tail;
node.list = this;
node.prev = tail;
if (tail) {
tail.next = node;
}
this.tail = node;
if (!this.head) {
this.head = node;
}
this.length++;
}
push(...args) {
for (let i = 0, l = args.length; i < l; i++) {
push(this, args[i]);
}
return this.length;
}
unshift(...args) {
for (var i = 0, l = args.length; i < l; i++) {
unshift(this, args[i]);
}
return this.length;
}
pop() {
if (!this.tail) {
return undefined;
}
const res = this.tail.value;
const t = this.tail;
this.tail = this.tail.prev;
if (this.tail) {
this.tail.next = undefined;
}
else {
this.head = undefined;
}
t.list = undefined;
this.length--;
return res;
}
shift() {
if (!this.head) {
return undefined;
}
const res = this.head.value;
const h = this.head;
this.head = this.head.next;
if (this.head) {
this.head.prev = undefined;
}
else {
this.tail = undefined;
}
h.list = undefined;
this.length--;
return res;
}
forEach(fn, thisp) {
thisp = thisp || this;
for (let walker = this.head, i = 0; !!walker; i++) {
fn.call(thisp, walker.value, i, this);
walker = walker.next;
}
}
forEachReverse(fn, thisp) {
thisp = thisp || this;
for (let walker = this.tail, i = this.length - 1; !!walker; i--) {
fn.call(thisp, walker.value, i, this);
walker = walker.prev;
}
}
get(n) {
let i = 0;
let walker = this.head;
for (; !!walker && i < n; i++) {
walker = walker.next;
}
if (i === n && !!walker) {
return walker.value;
}
}
getReverse(n) {
let i = 0;
let walker = this.tail;
for (; !!walker && i < n; i++) {
// abort out of the list early if we hit a cycle
walker = walker.prev;
}
if (i === n && !!walker) {
return walker.value;
}
}
map(fn, thisp) {
thisp = thisp || this;
const res = new Yallist();
for (let walker = this.head; !!walker;) {
res.push(fn.call(thisp, walker.value, this));
walker = walker.next;
}
return res;
}
mapReverse(fn, thisp) {
thisp = thisp || this;
var res = new Yallist();
for (let walker = this.tail; !!walker;) {
res.push(fn.call(thisp, walker.value, this));
walker = walker.prev;
}
return res;
}
reduce(fn, initial) {
let acc;
let walker = this.head;
if (arguments.length > 1) {
acc = initial;
}
else if (this.head) {
walker = this.head.next;
acc = this.head.value;
}
else {
throw new TypeError('Reduce of empty list with no initial value');
}
for (var i = 0; !!walker; i++) {
acc = fn(acc, walker.value, i);
walker = walker.next;
}
return acc;
}
reduceReverse(fn, initial) {
let acc;
let walker = this.tail;
if (arguments.length > 1) {
acc = initial;
}
else if (this.tail) {
walker = this.tail.prev;
acc = this.tail.value;
}
else {
throw new TypeError('Reduce of empty list with no initial value');
}
for (let i = this.length - 1; !!walker; i--) {
acc = fn(acc, walker.value, i);
walker = walker.prev;
}
return acc;
}
toArray() {
const arr = new Array(this.length);
for (let i = 0, walker = this.head; !!walker; i++) {
arr[i] = walker.value;
walker = walker.next;
}
return arr;
}
toArrayReverse() {
const arr = new Array(this.length);
for (let i = 0, walker = this.tail; !!walker; i++) {
arr[i] = walker.value;
walker = walker.prev;
}
return arr;
}
slice(from = 0, to = this.length) {
if (to < 0) {
to += this.length;
}
if (from < 0) {
from += this.length;
}
const ret = new Yallist();
if (to < from || to < 0) {
return ret;
}
if (from < 0) {
from = 0;
}
if (to > this.length) {
to = this.length;
}
let walker = this.head;
let i = 0;
for (i = 0; !!walker && i < from; i++) {
walker = walker.next;
}
for (; !!walker && i < to; i++, walker = walker.next) {
ret.push(walker.value);
}
return ret;
}
sliceReverse(from = 0, to = this.length) {
if (to < 0) {
to += this.length;
}
if (from < 0) {
from += this.length;
}
const ret = new Yallist();
if (to < from || to < 0) {
return ret;
}
if (from < 0) {
from = 0;
}
if (to > this.length) {
to = this.length;
}
let i = this.length;
let walker = this.tail;
for (; !!walker && i > to; i--) {
walker = walker.prev;
}
for (; !!walker && i > from; i--, walker = walker.prev) {
ret.push(walker.value);
}
return ret;
}
splice(start, deleteCount = 0, ...nodes) {
if (start > this.length) {
start = this.length - 1;
}
if (start < 0) {
start = this.length + start;
}
let walker = this.head;
for (let i = 0; !!walker && i < start; i++) {
walker = walker.next;
}
const ret = [];
for (let i = 0; !!walker && i < deleteCount; i++) {
ret.push(walker.value);
walker = this.removeNode(walker);
}
if (!walker) {
walker = this.tail;
}
else if (walker !== this.tail) {
walker = walker.prev;
}
for (const v of nodes) {
walker = insertAfter(this, walker, v);
}
return ret;
}
reverse() {
const head = this.head;
const tail = this.tail;
for (let walker = head; !!walker; walker = walker.prev) {
const p = walker.prev;
walker.prev = walker.next;
walker.next = p;
}
this.head = tail;
this.tail = head;
return this;
}
}
// insertAfter undefined means "make the node the new head of list"
function insertAfter(self, node, value) {
const prev = node;
const next = node ? node.next : self.head;
const inserted = new Node(value, prev, next, self);
if (inserted.next === undefined) {
self.tail = inserted;
}
if (inserted.prev === undefined) {
self.head = inserted;
}
self.length++;
return inserted;
}
function push(self, item) {
self.tail = new Node(item, self.tail, undefined, self);
if (!self.head) {
self.head = self.tail;
}
self.length++;
}
function unshift(self, item) {
self.head = new Node(item, undefined, self.head, self);
if (!self.tail) {
self.tail = self.head;
}
self.length++;
}
export class Node {
list;
next;
prev;
value;
constructor(value, prev, next, list) {
this.list = list;
this.value = value;
if (prev) {
prev.next = this;
this.prev = prev;
}
else {
this.prev = undefined;
}
if (next) {
next.prev = this;
this.next = next;
}
else {
this.next = undefined;
}
}
}
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View file

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