node-liblzma
Version:
NodeJS wrapper for liblzma
123 lines • 4.11 kB
TypeScript
/**
* node-liblzma - Node.js bindings for liblzma
* Copyright (C) Olivier Orabona <olivier.orabona@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { EventEmitter } from 'node:events';
import { type LZMAOptions } from './lzma.js';
/**
* Metrics for pool monitoring
*/
export interface PoolMetrics {
/** Number of currently active compression/decompression operations */
active: number;
/** Number of operations waiting in the queue */
queued: number;
/** Total number of successfully completed operations */
completed: number;
/** Total number of failed operations */
failed: number;
}
/**
* LZMA Pool with concurrency control and event monitoring
*
* Provides rate limiting and backpressure for LZMA operations.
* Emits events for monitoring and metrics collection in production.
*
* @example
* ```typescript
* const pool = new LZMAPool(10); // Max 10 concurrent operations
*
* pool.on('metrics', (metrics) => {
* console.log(`Active: ${metrics.active}, Queued: ${metrics.queued}`);
* });
*
* const compressed = await pool.compress(buffer);
* ```
*
* Events:
* - 'queue': Emitted when task added to queue
* - 'start': Emitted when task starts processing
* - 'complete': Emitted when task completes successfully
* - 'error-task': Emitted when task fails
* - 'metrics': Emitted after each state change with current metrics
*/
export declare class LZMAPool extends EventEmitter {
private maxConcurrent;
private queue;
private metrics;
/**
* Create a new LZMA pool
* @param maxConcurrent Maximum number of concurrent operations (default: 10)
*/
constructor(maxConcurrent?: number);
/**
* Compress data with automatic queue management
* @param data Buffer to compress
* @param opts LZMA compression options
* @returns Promise that resolves to compressed buffer
*/
compress(data: Buffer, opts?: LZMAOptions): Promise<Buffer>;
/**
* Decompress data with automatic queue management
* @param data Compressed buffer to decompress
* @param opts LZMA decompression options
* @returns Promise that resolves to decompressed buffer
*/
decompress(data: Buffer, opts?: LZMAOptions): Promise<Buffer>;
/**
* Get current pool metrics
* @returns Copy of current metrics
*/
getMetrics(): Readonly<PoolMetrics>;
/**
* Get number of tasks waiting in queue
* @returns Queue length
*/
get queueLength(): number;
/**
* Get number of currently active tasks
* @returns Active task count
*/
get activeCount(): number;
/**
* Check if pool is at maximum capacity
* @returns True if at capacity
*/
get isAtCapacity(): boolean;
/**
* Enqueue a task for execution
* @param fn Task function returning Promise<Buffer>
* @returns Promise that resolves when task completes
*/
private enqueue;
/**
* Process tasks from queue respecting concurrency limit
*/
private processQueue;
/**
* Wait for all active tasks to complete
* Does not process new tasks added while waiting
* @returns Promise that resolves when all active tasks are done
*/
drain(): Promise<void>;
/**
* Clear all pending tasks from the queue
* Active tasks will continue to run
* @returns Number of tasks removed from queue
*/
clearQueue(): number;
}
//# sourceMappingURL=pool.d.ts.map