yeow-api 0.3.8 → 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 +4 -2
- package/src/fs.ts +20 -1
- package/src/util.ts +36 -16
package/package.json
CHANGED
package/src/core.ts
CHANGED
|
@@ -46,9 +46,11 @@ export {
|
|
|
46
46
|
readFile, readFileSync, readFileBase64, readFileBase64Sync,
|
|
47
47
|
writeFile, writeFileSync, writeFileBase64, writeFileBase64Sync,
|
|
48
48
|
appendFile, appendFileSync,
|
|
49
|
-
exists, existsSync,
|
|
49
|
+
exists, existsSync, stat, statSync,
|
|
50
|
+
isDirectory, isDirectorySync,
|
|
50
51
|
deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
|
|
51
52
|
} from './fs.js';
|
|
53
|
+
export type { FileStat } from './fs.js';
|
|
52
54
|
export { assets, read as assetsRead, readSync as assetsReadSync,
|
|
53
55
|
readBase64 as assetsReadBase64, readBase64Sync as assetsReadBase64Sync,
|
|
54
56
|
extract as assetsExtract, extractSync as assetsExtractSync,
|
|
@@ -110,4 +112,4 @@ export {
|
|
|
110
112
|
bytesToString, bytesToStringAsync,
|
|
111
113
|
Gzip,
|
|
112
114
|
} from './util.js';
|
|
113
|
-
export type { GzipCompressor, GzipDecompressor } from './util.js';
|
|
115
|
+
export type { GzipCompressor, GzipDecompressor, GzipCompressOptions, GzipDecompressOptions } from './util.js';
|
package/src/fs.ts
CHANGED
|
@@ -69,6 +69,13 @@ function _makeFs(level: FsLevel) {
|
|
|
69
69
|
return r === true || String(r) === 'true';
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
async function stat(path: string): Promise<FileStat> {
|
|
73
|
+
return await _sendFsAsync({ t: t('stat'), p: { path } }) as FileStat;
|
|
74
|
+
}
|
|
75
|
+
function statSync(path: string): FileStat {
|
|
76
|
+
return _sendFs({ t: t('stat'), p: { path } }) as FileStat;
|
|
77
|
+
}
|
|
78
|
+
|
|
72
79
|
async function isDirectory(path: string): Promise<boolean> {
|
|
73
80
|
const r = await _sendFsAsync({ t: t('isDirectory'), p: { path } });
|
|
74
81
|
return r === true || String(r) === 'true';
|
|
@@ -130,7 +137,8 @@ function _makeFs(level: FsLevel) {
|
|
|
130
137
|
readFile, readFileSync, readFileBase64, readFileBase64Sync,
|
|
131
138
|
writeFile, writeFileSync, writeFileBase64, writeFileBase64Sync,
|
|
132
139
|
appendFile, appendFileSync,
|
|
133
|
-
exists, existsSync,
|
|
140
|
+
exists, existsSync, stat, statSync,
|
|
141
|
+
isDirectory, isDirectorySync,
|
|
134
142
|
deleteFile, deleteFileSync, mkdir, mkdirSync, list, listSync,
|
|
135
143
|
createReadStream, createWriteStream,
|
|
136
144
|
// outer 专属能力(systemPaths / getServerPath)
|
|
@@ -159,6 +167,8 @@ export const appendFile = fs.appendFile;
|
|
|
159
167
|
export const appendFileSync = fs.appendFileSync;
|
|
160
168
|
export const exists = fs.exists;
|
|
161
169
|
export const existsSync = fs.existsSync;
|
|
170
|
+
export const stat = fs.stat;
|
|
171
|
+
export const statSync = fs.statSync;
|
|
162
172
|
export const isDirectory = fs.isDirectory;
|
|
163
173
|
export const isDirectorySync = fs.isDirectorySync;
|
|
164
174
|
export const deleteFile = fs.deleteFile;
|
|
@@ -183,6 +193,15 @@ export interface WriteStreamOptions {
|
|
|
183
193
|
flags?: 'w' | 'a' | 'wx';
|
|
184
194
|
}
|
|
185
195
|
|
|
196
|
+
/** 文件状态(stat)。mtimeMs / ctimeMs 为 epoch 毫秒。 */
|
|
197
|
+
export interface FileStat {
|
|
198
|
+
isFile: boolean;
|
|
199
|
+
isDirectory: boolean;
|
|
200
|
+
size: number;
|
|
201
|
+
mtimeMs: number;
|
|
202
|
+
ctimeMs: number;
|
|
203
|
+
}
|
|
204
|
+
|
|
186
205
|
/** 文件读流:read() 一次返回一块(默认 1 MiB),null = EOF;可 for await。 */
|
|
187
206
|
export interface ReadStream {
|
|
188
207
|
read(maxBytes?: number): Promise<Uint8Array | null>;
|
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 {
|