feat(archive): introduce ts_shared browser-compatible layer, refactor Node-specific tools to wrap/shared implementations, and modernize archive handling
This commit is contained in:
42
ts_shared/classes.gziptools.ts
Normal file
42
ts_shared/classes.gziptools.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import type { TCompressionLevel } from './interfaces.js';
|
||||
|
||||
/**
|
||||
* GZIP compression and decompression utilities (browser-compatible)
|
||||
*/
|
||||
export class GzipTools {
|
||||
/**
|
||||
* Compress data synchronously
|
||||
*/
|
||||
public compressSync(data: Uint8Array, level?: TCompressionLevel): Uint8Array {
|
||||
const options = level !== undefined ? { level } : undefined;
|
||||
return plugins.fflate.gzipSync(data, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decompress data synchronously
|
||||
*/
|
||||
public decompressSync(data: Uint8Array): Uint8Array {
|
||||
return plugins.fflate.gunzipSync(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress data asynchronously
|
||||
* Note: Uses sync version for Deno compatibility (fflate async uses Web Workers
|
||||
* which have issues in Deno)
|
||||
*/
|
||||
public async compress(data: Uint8Array, level?: TCompressionLevel): Promise<Uint8Array> {
|
||||
// Use sync version wrapped in Promise for cross-runtime compatibility
|
||||
return this.compressSync(data, level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decompress data asynchronously
|
||||
* Note: Uses sync version for Deno compatibility (fflate async uses Web Workers
|
||||
* which have issues in Deno)
|
||||
*/
|
||||
public async decompress(data: Uint8Array): Promise<Uint8Array> {
|
||||
// Use sync version wrapped in Promise for cross-runtime compatibility
|
||||
return this.decompressSync(data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user