yeow-api 0.3.9 → 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/core.ts +1 -1
- package/src/util.ts +36 -16
package/package.json
CHANGED
package/src/core.ts
CHANGED
|
@@ -112,4 +112,4 @@ export {
|
|
|
112
112
|
bytesToString, bytesToStringAsync,
|
|
113
113
|
Gzip,
|
|
114
114
|
} from './util.js';
|
|
115
|
-
export type { GzipCompressor, GzipDecompressor } from './util.js';
|
|
115
|
+
export type { GzipCompressor, GzipDecompressor, GzipCompressOptions, GzipDecompressOptions } from './util.js';
|
package/src/util.ts
CHANGED
|
@@ -73,28 +73,48 @@ export interface GzipDecompressor {
|
|
|
73
73
|
close(): Promise<void>;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/** 压缩选项:level 0-9(默认引擎默认级别);raw = 原始 deflate(无 GZIP 头/尾/CRC)。 */
|
|
77
|
+
export interface GzipCompressOptions {
|
|
78
|
+
level?: number;
|
|
79
|
+
raw?: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 解压选项:raw = 原始 deflate(无 GZIP 头/尾/CRC 校验)。 */
|
|
83
|
+
export interface GzipDecompressOptions {
|
|
84
|
+
raw?: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** 兼容旧式数字 level 参数:Gzip.compress(data, 6) 仍可用。 */
|
|
88
|
+
type LevelArg = number | GzipCompressOptions | undefined;
|
|
89
|
+
|
|
90
|
+
function normalizeOptions(o?: LevelArg): GzipCompressOptions {
|
|
91
|
+
return typeof o === 'number' ? { level: o } : (o ?? {});
|
|
92
|
+
}
|
|
93
|
+
|
|
76
94
|
export const Gzip = {
|
|
77
|
-
/**
|
|
78
|
-
compress(data: Uint8Array | string,
|
|
79
|
-
|
|
95
|
+
/** 一次性压缩(level 0-9;raw=true 输出原始 deflate 流)。输入 string 视为 UTF-8 文本。 */
|
|
96
|
+
compress(data: Uint8Array | string, options?: LevelArg): Promise<Uint8Array> {
|
|
97
|
+
const o = normalizeOptions(options);
|
|
98
|
+
return sendAsync<{ data: string }>('gzip.compress', { data: toB64(data), level: o.level, raw: o.raw })
|
|
80
99
|
.then((r) => Uint8Array.fromBase64(r.data));
|
|
81
100
|
},
|
|
82
|
-
/**
|
|
83
|
-
compressSync(data: Uint8Array | string,
|
|
84
|
-
|
|
101
|
+
/** 一次性压缩(同步版)。 */
|
|
102
|
+
compressSync(data: Uint8Array | string, options?: LevelArg): Uint8Array {
|
|
103
|
+
const o = normalizeOptions(options);
|
|
104
|
+
return Uint8Array.fromBase64(send<{ data: string }>('gzip.compress', { data: toB64(data), level: o.level, raw: o.raw }).data);
|
|
85
105
|
},
|
|
86
|
-
/**
|
|
87
|
-
decompress(data: Uint8Array | string): Promise<Uint8Array> {
|
|
88
|
-
return sendAsync<{ data: string }>('gzip.decompress', { data: toB64(data) })
|
|
106
|
+
/** 一次性解压(输出上限 256 MiB,超限报错——防压缩炸弹;上限可在 config.yml util 段调整)。 */
|
|
107
|
+
decompress(data: Uint8Array | string, options?: GzipDecompressOptions): Promise<Uint8Array> {
|
|
108
|
+
return sendAsync<{ data: string }>('gzip.decompress', { data: toB64(data), raw: options?.raw })
|
|
89
109
|
.then((r) => Uint8Array.fromBase64(r.data));
|
|
90
110
|
},
|
|
91
|
-
/**
|
|
92
|
-
decompressSync(data: Uint8Array | string): Uint8Array {
|
|
93
|
-
return Uint8Array.fromBase64(send<{ data: string }>('gzip.decompress', { data: toB64(data) }).data);
|
|
111
|
+
/** 一次性解压(同步版)。 */
|
|
112
|
+
decompressSync(data: Uint8Array | string, options?: GzipDecompressOptions): Uint8Array {
|
|
113
|
+
return Uint8Array.fromBase64(send<{ data: string }>('gzip.decompress', { data: toB64(data), raw: options?.raw }).data);
|
|
94
114
|
},
|
|
95
115
|
/** 创建分块压缩器(流式管道):create → write×n → finish → close。 */
|
|
96
|
-
async createCompressor(options?:
|
|
97
|
-
const r = await sendAsync<{ id: string }>('gzip.compressor.create', { level: options?.level });
|
|
116
|
+
async createCompressor(options?: GzipCompressOptions): Promise<GzipCompressor> {
|
|
117
|
+
const r = await sendAsync<{ id: string }>('gzip.compressor.create', { level: options?.level, raw: options?.raw });
|
|
98
118
|
let closed = false;
|
|
99
119
|
const check = () => { if (closed) throw new Error('compressor closed'); };
|
|
100
120
|
return {
|
|
@@ -116,8 +136,8 @@ export const Gzip = {
|
|
|
116
136
|
};
|
|
117
137
|
},
|
|
118
138
|
/** 创建分块解压器(流式管道):create → write×n → finish → close。 */
|
|
119
|
-
async createDecompressor(): Promise<GzipDecompressor> {
|
|
120
|
-
const r = await sendAsync<{ id: string }>('gzip.decompressor.create', {});
|
|
139
|
+
async createDecompressor(options?: GzipDecompressOptions): Promise<GzipDecompressor> {
|
|
140
|
+
const r = await sendAsync<{ id: string }>('gzip.decompressor.create', { raw: options?.raw });
|
|
121
141
|
let closed = false;
|
|
122
142
|
const check = () => { if (closed) throw new Error('decompressor closed'); };
|
|
123
143
|
return {
|