yeow-api 0.3.7 → 0.3.9
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 +35 -5
package/package.json
CHANGED
package/src/core.ts
CHANGED
|
@@ -46,16 +46,18 @@ 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,
|
|
55
57
|
extractDir as assetsExtractDir, extractDirSync as assetsExtractDirSync } from './assets.js';
|
|
56
58
|
export { path } from './path.js';
|
|
57
59
|
export { createReadStream, createWriteStream } from './fs.js';
|
|
58
|
-
export type { ReadStream, WriteStream } from './fs.js';
|
|
60
|
+
export type { ReadStream, WriteStream, ReadStreamOptions, WriteStreamOptions } from './fs.js';
|
|
59
61
|
export { listen, respond, close, request, requestSync } from './http.js';
|
|
60
62
|
export type { RespondOptions } from './http.js';
|
|
61
63
|
export { logError } from './log-error.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';
|
|
@@ -116,13 +123,13 @@ function _makeFs(level: FsLevel) {
|
|
|
116
123
|
return (_sendFs({ t: t('getServerPath') }) as { path: string }).path;
|
|
117
124
|
}
|
|
118
125
|
|
|
119
|
-
async function createReadStream(path: string): Promise<ReadStream> {
|
|
120
|
-
const r = await _sendFsAsync({ t: t('openRead'), p: { path } }) as { id: string };
|
|
126
|
+
async function createReadStream(path: string, options?: ReadStreamOptions): Promise<ReadStream> {
|
|
127
|
+
const r = await _sendFsAsync({ t: t('openRead'), p: { path, ...options } }) as { id: string };
|
|
121
128
|
return _makeReadStream((op, p2) => _sendFsAsync({ t: t(op), p: p2 }), r.id);
|
|
122
129
|
}
|
|
123
130
|
|
|
124
|
-
async function createWriteStream(path: string): Promise<WriteStream> {
|
|
125
|
-
const r = await _sendFsAsync({ t: t('openWrite'), p: { path } }) as { id: string };
|
|
131
|
+
async function createWriteStream(path: string, options?: WriteStreamOptions): Promise<WriteStream> {
|
|
132
|
+
const r = await _sendFsAsync({ t: t('openWrite'), p: { path, ...options } }) as { id: string };
|
|
126
133
|
return _makeWriteStream((op, p2) => _sendFsAsync({ t: t(op), p: p2 }), r.id);
|
|
127
134
|
}
|
|
128
135
|
|
|
@@ -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;
|
|
@@ -172,6 +182,26 @@ export const createWriteStream = fs.createWriteStream;
|
|
|
172
182
|
|
|
173
183
|
// ── 流式读写(有状态句柄;背压 = 显式响应——每个操作 await 结果后才发起下一块)──
|
|
174
184
|
|
|
185
|
+
/** 读流选项:字节偏移区间(start 含、end 含;缺省 = 全文件)。 */
|
|
186
|
+
export interface ReadStreamOptions {
|
|
187
|
+
start?: number;
|
|
188
|
+
end?: number;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** 写流选项:打开模式——w 覆盖(默认)/ a 追加 / wx 排他创建(已存在报错)。 */
|
|
192
|
+
export interface WriteStreamOptions {
|
|
193
|
+
flags?: 'w' | 'a' | 'wx';
|
|
194
|
+
}
|
|
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
|
+
|
|
175
205
|
/** 文件读流:read() 一次返回一块(默认 1 MiB),null = EOF;可 for await。 */
|
|
176
206
|
export interface ReadStream {
|
|
177
207
|
read(maxBytes?: number): Promise<Uint8Array | null>;
|