import { EventEmitter } from "node:events"; import * as nodestream from "node:stream"; //#region src/lib/fifo.d.ts declare class FastFIFO { private head; private tail; length: number; constructor(); push(val: Buffer): void; shift(): Buffer; peek(): Buffer; } //#endregion //#region src/lib/streamx.d.ts interface StreamOptions { open?(callback: (err?: Error) => void): void; predestroy?(): void; } declare class Stream extends EventEmitter implements nodestream.Stream { _duplexState: number; _readableState: ReadableState | null; _writableState: WritableState | null; constructor(opts?: StreamOptions); _open(callback: (err?: Error | null) => void): void; _destroy(callback: (err?: Error | null) => void): void; _predestroy(): void; get readable(): boolean; get writable(): boolean; get destroyed(): boolean; get destroying(): boolean; destroy(err?: Error): void; pipe(destination: T): T; } interface ReadableOptions extends StreamOptions, ReadableStateOptions { encoding?: BufferEncoding; read(callback: (err: Error | null) => void): void; } declare class Readable extends Stream implements nodestream.Readable { constructor(opts?: Partial); setEncoding(encoding?: BufferEncoding): this; _read(callback: (err?: Error | null) => void): void; pipe(dest: T, callback?: (err: Error | null) => void): T; read(): Buffer; push(data: Buffer | null): boolean; unshift(data: Buffer): void; resume(): this; pause(): this; [Symbol.asyncIterator](): { [Symbol.asyncIterator](): Readable; next(): Promise<{ value: undefined; done: true; }>; return(): Promise<{ value: undefined; done: true; }>; throw(err?: Error): Promise<{ value: undefined; done: true; }>; }; } interface WritableOptions extends StreamOptions, WritableStateOptions { write?(data: Buffer, callback: (err?: Error) => void): void; eagerOpen?: boolean; } declare class Writable extends Stream implements nodestream.Writable { constructor(opts?: WritableOptions); cork(): void; uncork(): void; _writev(batch: unknown, callback: (err?: Error | null) => void): void; _write(data: Buffer, callback: (err?: Error | null) => void): void; _final(callback: (err?: Error | null) => void): void; write(data: Buffer): boolean; end(data?: string | Buffer): this; } interface WritableStateOptions { highWaterMark?: number; map?: ((data: Buffer) => Buffer) | null; mapWritable?(data: Buffer): Buffer; } declare class WritableState { stream: Stream; queue: FastFIFO; highWaterMark: number; buffered: number; constructor(stream: Stream, options?: WritableStateOptions); get ended(): boolean; push(data: Buffer): boolean; shift(): Buffer; end(data?: string | Buffer): void; autoBatch(data: Buffer, callback: (err?: Error | null) => void): void; update(): void; updateNonPrimary(): void; continueUpdate(): boolean; updateCallback(): void; updateNextTick(): void; } interface ReadableStateOptions { highWaterMark: number; map: ((data: Buffer) => Buffer) | null; mapReadable(data: Buffer): Buffer; } declare class ReadableState { stream: Readable; queue: FastFIFO; highWaterMark: number; buffered: number; readAhead: boolean; error: Error | null; map: ((data: string | Buffer) => Buffer) | null; constructor(stream: Readable, options?: Partial); get ended(): boolean; pipe(pipeTo: T, callback?: ((err: Error | null) => void) | null): void; push(data: Buffer | null): boolean; shift(): Buffer; unshift(data: Buffer): void; read(): Buffer; drain(): void; update(): void; updateNonPrimary(): void; continueUpdate(): boolean; updateCallback(): void; updateNextTickIfOpen(): void; updateNextTick(): void; } //#endregion //#region src/extract.d.ts interface TarExtractSourceHeader { size: number; name: string; } declare class TarExtractSource extends Readable { private _parent; header: TarExtractSourceHeader; offset: number; constructor(self: TarExtract, header: TarExtractSourceHeader, offset: number); _read(callback: (err?: Error | null) => void): void; _predestroy(): void; _detach(): void; _destroy(callback: (err?: Error | null) => void): void; } interface TarExtractOptions extends WritableOptions { filenameEncoding?: string; allowUnknownFormat?: boolean; } declare class TarExtract extends Writable { private _buffer; private _offset; private _stream; private _missing; private _longHeader; private _callback?; private _locked; private _finished; private _header; constructor(opts?: TarExtractOptions); _unlock(err?: Error): void; _consumeHeader(): boolean; _applyLongHeaders(): void; _decodeLongHeader(buf: Buffer): void; _consumeLongHeader(): boolean; _consumeStream(): boolean; _createStream(): TarExtractSource; _update(): boolean; _continueWrite(err?: Error | null): void; _write(data: Buffer, callback?: (err?: Error | null) => void): void; _final(callback: (err?: Error | null) => void): void; _predestroy(): void; _destroy(callback: (err?: Error | null) => void): void; [Symbol.asyncIterator](): { [Symbol.asyncIterator](): TarExtract; next(): Promise<{ value: TarExtractSource; done: boolean; }>; return(): Promise<{ value: undefined; done: true; }>; throw(err?: Error): Promise<{ value: undefined; done: true; }>; }; } declare function extract(opts?: TarExtractOptions): TarExtract; //#endregion //#region src/lib/headers.d.ts type HeaderType = "symlink" | "file" | "block-device" | "character-device" | "directory" | "fifo" | "contiguous-file" | "pax-header" | "link" | "pax-global-header" | "gnu-long-link-path" | "gnu-long-path"; interface TarHeader { name: string; mode: number; uid: number; gid: number; pax: null | { path?: string; special: string; }; size: number; mtime: Date; type: HeaderType; linkname: string; uname: string; gname: string; devmajor: number; devminor: number; typeflag: number; } //#endregion //#region src/pack.d.ts interface TarPackSinkHeader { type: HeaderType; linkname: string; size: number; } declare class TarPackSink extends Writable { written: number; header: TarPackSinkHeader; private _isLinkname; private _isVoid; private _finished; private _pack; private _linkname; private _openCallback?; constructor(pack: TarPack, header: TarPackSinkHeader, callback?: (err: Error | null) => void); _open(callback?: (err: Error | null) => void): void; _continuePack(err: Error | null): void; _continueOpen(): void; _write(data: Buffer, callback: (arg?: Error | null) => void): void; _finish(): void; _final(callback: (err: Error | null) => void): void; private _getError; _predestroy(): void; _destroy(callback: () => void): void; } interface TarPackOptions extends ReadableOptions {} declare class TarPack extends Readable { private _drain; private _finalized; private _finalizing; private _pending; private _stream; constructor(opts?: Partial); entry(header: Partial, callback?: (err?: Error | null) => void): TarPackSink; entry(header: Partial, buffer: string | Buffer, callback?: (err?: Error | null) => void): TarPackSink; finalize(): void; _done(stream: TarPackSink): void; _encode(header: TarHeader): void; _encodePax(header: TarHeader): void; _doDrain(): void; _predestroy(): void; _read(callback: () => void): void; } declare function pack(opts?: Partial): TarPack; //#endregion export { type TarExtract, type TarExtractOptions, type TarPack, type TarPackOptions, extract, pack };