yeow-api 0.3.7 → 0.3.8

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/src/core.ts +1 -1
  3. package/src/fs.ts +15 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeow-api",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "description": "Yeow API",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/core.ts CHANGED
@@ -55,7 +55,7 @@ export { assets, read as assetsRead, readSync as assetsReadSync,
55
55
  extractDir as assetsExtractDir, extractDirSync as assetsExtractDirSync } from './assets.js';
56
56
  export { path } from './path.js';
57
57
  export { createReadStream, createWriteStream } from './fs.js';
58
- export type { ReadStream, WriteStream } from './fs.js';
58
+ export type { ReadStream, WriteStream, ReadStreamOptions, WriteStreamOptions } from './fs.js';
59
59
  export { listen, respond, close, request, requestSync } from './http.js';
60
60
  export type { RespondOptions } from './http.js';
61
61
  export { logError } from './log-error.js';
package/src/fs.ts CHANGED
@@ -116,13 +116,13 @@ function _makeFs(level: FsLevel) {
116
116
  return (_sendFs({ t: t('getServerPath') }) as { path: string }).path;
117
117
  }
118
118
 
119
- async function createReadStream(path: string): Promise<ReadStream> {
120
- const r = await _sendFsAsync({ t: t('openRead'), p: { path } }) as { id: string };
119
+ async function createReadStream(path: string, options?: ReadStreamOptions): Promise<ReadStream> {
120
+ const r = await _sendFsAsync({ t: t('openRead'), p: { path, ...options } }) as { id: string };
121
121
  return _makeReadStream((op, p2) => _sendFsAsync({ t: t(op), p: p2 }), r.id);
122
122
  }
123
123
 
124
- async function createWriteStream(path: string): Promise<WriteStream> {
125
- const r = await _sendFsAsync({ t: t('openWrite'), p: { path } }) as { id: string };
124
+ async function createWriteStream(path: string, options?: WriteStreamOptions): Promise<WriteStream> {
125
+ const r = await _sendFsAsync({ t: t('openWrite'), p: { path, ...options } }) as { id: string };
126
126
  return _makeWriteStream((op, p2) => _sendFsAsync({ t: t(op), p: p2 }), r.id);
127
127
  }
128
128
 
@@ -172,6 +172,17 @@ export const createWriteStream = fs.createWriteStream;
172
172
 
173
173
  // ── 流式读写(有状态句柄;背压 = 显式响应——每个操作 await 结果后才发起下一块)──
174
174
 
175
+ /** 读流选项:字节偏移区间(start 含、end 含;缺省 = 全文件)。 */
176
+ export interface ReadStreamOptions {
177
+ start?: number;
178
+ end?: number;
179
+ }
180
+
181
+ /** 写流选项:打开模式——w 覆盖(默认)/ a 追加 / wx 排他创建(已存在报错)。 */
182
+ export interface WriteStreamOptions {
183
+ flags?: 'w' | 'a' | 'wx';
184
+ }
185
+
175
186
  /** 文件读流:read() 一次返回一块(默认 1 MiB),null = EOF;可 for await。 */
176
187
  export interface ReadStream {
177
188
  read(maxBytes?: number): Promise<Uint8Array | null>;