fs-stream-sync 2.0.19 → 2.0.22
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/CHANGELOG.md +33 -0
- package/README.md +34 -5
- package/index.d.ts +55 -1
- package/index.js +15 -1
- package/index.js.map +1 -1
- package/lib/errors.d.ts +46 -0
- package/lib/errors.js +43 -0
- package/lib/errors.js.map +1 -1
- package/lib/interface.d.ts +84 -0
- package/lib/interface.js +7 -0
- package/lib/interface.js.map +1 -1
- package/lib/internal.d.ts +90 -0
- package/lib/internal.js +109 -0
- package/lib/internal.js.map +1 -1
- package/package.json +7 -4
- package/read-sync.d.ts +73 -0
- package/read-sync.js +104 -8
- package/read-sync.js.map +1 -1
- package/read.d.ts +49 -0
- package/read.js +41 -0
- package/read.js.map +1 -1
- package/write-sync.d.ts +101 -1
- package/write-sync.js +93 -5
- package/write-sync.js.map +1 -1
- package/write.d.ts +83 -2
- package/write.js +52 -0
- package/write.js.map +1 -1
package/write.js
CHANGED
|
@@ -1,24 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 寫入流實作
|
|
4
|
+
* Write Stream Implementation
|
|
5
|
+
*
|
|
6
|
+
* 提供非同步檔案寫入流功能,擴展 Node.js fs.WriteStream
|
|
7
|
+
* Provides asynchronous file writing stream functionality, extends Node.js fs.WriteStream
|
|
8
|
+
*
|
|
9
|
+
* @module fs-stream-sync/write
|
|
10
|
+
*/
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.WriteStream = void 0;
|
|
4
13
|
exports.createWriteStream = createWriteStream;
|
|
5
14
|
const tslib_1 = require("tslib");
|
|
6
15
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
7
16
|
const internal_1 = require("./lib/internal");
|
|
17
|
+
/**
|
|
18
|
+
* 寫入流類別
|
|
19
|
+
* Write Stream Class
|
|
20
|
+
*
|
|
21
|
+
* 擴展 Node.js fs.WriteStream,提供額外功能
|
|
22
|
+
* Extends Node.js fs.WriteStream with additional functionality
|
|
23
|
+
*/
|
|
8
24
|
// @ts-ignore
|
|
9
25
|
class WriteStream extends fs_1.default.WriteStream {
|
|
26
|
+
/**
|
|
27
|
+
* 構造函數
|
|
28
|
+
* Constructor
|
|
29
|
+
*
|
|
30
|
+
* @param {PathLike} path - 檔案路徑 / File path
|
|
31
|
+
* @param {string | IFsWriteStreamOptions} [options] - 選項 / Options
|
|
32
|
+
*/
|
|
10
33
|
constructor(path, options) {
|
|
11
34
|
// @ts-ignore
|
|
12
35
|
super(path, options);
|
|
36
|
+
// 初始化流資料 / Initialize stream data
|
|
13
37
|
(0, internal_1.getFsStreamData)(this);
|
|
14
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* 建立函數別名
|
|
41
|
+
* Factory method alias
|
|
42
|
+
*/
|
|
15
43
|
static get create() {
|
|
16
44
|
return createWriteStream;
|
|
17
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* 開啟檔案流
|
|
48
|
+
* Open file stream
|
|
49
|
+
*
|
|
50
|
+
* 開啟檔案並發送 open 和 ready 事件
|
|
51
|
+
* Opens file and emits open and ready events
|
|
52
|
+
*/
|
|
18
53
|
open() {
|
|
19
54
|
if (!(0, internal_1.getFsStreamData)(this).opened) {
|
|
20
55
|
const self = this;
|
|
21
56
|
this[internal_1.SYM_FS_STREAM_DATA].opened = true;
|
|
57
|
+
// 監聽 open 事件並發送 ready 事件
|
|
58
|
+
// Listen for open event and emit ready event
|
|
22
59
|
this.once('open', function () {
|
|
23
60
|
process.nextTick(function () {
|
|
24
61
|
self.emit('ready');
|
|
@@ -30,8 +67,23 @@ class WriteStream extends fs_1.default.WriteStream {
|
|
|
30
67
|
}
|
|
31
68
|
}
|
|
32
69
|
exports.WriteStream = WriteStream;
|
|
70
|
+
/**
|
|
71
|
+
* 建立寫入流
|
|
72
|
+
* Create write stream
|
|
73
|
+
*
|
|
74
|
+
* 工廠函數,建立 WriteStream 實例
|
|
75
|
+
* Factory function that creates a WriteStream instance
|
|
76
|
+
*
|
|
77
|
+
* @param {PathLike} path - 檔案路徑 / File path
|
|
78
|
+
* @param {string | IFsWriteStreamOptions} [options] - 選項 / Options
|
|
79
|
+
* @returns {WriteStream} 寫入流實例 / Write stream instance
|
|
80
|
+
*/
|
|
33
81
|
function createWriteStream(path, options) {
|
|
34
82
|
return new WriteStream(path, options);
|
|
35
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* 預設導出 - WriteStream 類別
|
|
86
|
+
* Default export - WriteStream class
|
|
87
|
+
*/
|
|
36
88
|
exports.default = WriteStream;
|
|
37
89
|
//# sourceMappingURL=write.js.map
|
package/write.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.js","sourceRoot":"","sources":["write.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"write.js","sourceRoot":"","sources":["write.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AA2IH,8CAGC;;AA5ID,oDAAoB;AAGpB,6CAAqE;AAErE;;;;;;GAMG;AACH,aAAa;AACb,MAAa,WAAY,SAAQ,YAAE,CAAC,WAAW;IAyD9C;;;;;;OAMG;IACH,YAAY,IAAc,EAAE,OAAwC;QAEnE,aAAa;QACb,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAEpB,kCAAkC;QAClC,IAAA,0BAAe,EAAC,IAAI,CAAC,CAAA;IACtB,CAAC;IAED;;;OAGG;IACH,MAAM,KAAK,MAAM;QAEhB,OAAO,iBAAiB,CAAA;IACzB,CAAC;IAED;;;;;;OAMG;IACH,IAAI;QAEH,IAAI,CAAC,IAAA,0BAAe,EAAC,IAAI,CAAC,CAAC,MAAM,EACjC,CAAC;YACA,MAAM,IAAI,GAAG,IAAI,CAAA;YAEjB,IAAI,CAAC,6BAAkB,CAAC,CAAC,MAAM,GAAG,IAAI,CAAA;YAEtC,yBAAyB;YACzB,6CAA6C;YAC7C,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBAEjB,OAAO,CAAC,QAAQ,CAAC;oBAEhB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;gBACnB,CAAC,CAAC,CAAA;YACH,CAAC,CAAC,CAAA;YACF,aAAa;YACb,YAAE,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACzC,CAAC;IACF,CAAC;CAED;AA/GD,kCA+GC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,iBAAiB,CAAC,IAAc,EAAE,OAAwC;IAEzF,OAAO,IAAI,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AACtC,CAAC;AAED;;;GAGG;AACH,kBAAe,WAAW,CAAA","sourcesContent":["/**\n * 寫入流實作\n * Write Stream Implementation\n *\n * 提供非同步檔案寫入流功能,擴展 Node.js fs.WriteStream\n * Provides asynchronous file writing stream functionality, extends Node.js fs.WriteStream\n *\n * @module fs-stream-sync/write\n */\n\nimport fs from \"fs\";\nimport { PathLike } from 'fs';\nimport { IFsPath, IFsStreamData, IFsStreamState, IFsWriteStreamOptions } from './lib/interface';\nimport { getFsStreamData, SYM_FS_STREAM_DATA } from './lib/internal';\n\n/**\n * 寫入流類別\n * Write Stream Class\n *\n * 擴展 Node.js fs.WriteStream,提供額外功能\n * Extends Node.js fs.WriteStream with additional functionality\n */\n// @ts-ignore\nexport class WriteStream extends fs.WriteStream\n{\n\t/**\n\t * 自動關閉標誌 / Auto close flag\n\t */\n\tprotected autoClose: boolean\n\t/**\n\t * 檔案開啟標誌 / File open flags\n\t */\n\tprotected flags: string\n\t/**\n\t * 檔案描述符 / File descriptor\n\t */\n\tfd: number\n\t/**\n\t * 檔案權限模式 / File permission mode\n\t */\n\tprotected mode: number\n\t/**\n\t * 當前位置 / Current position\n\t */\n\tprotected pos: number\n\t/**\n\t * 是否已關閉 / Whether closed\n\t */\n\tprotected override closed: boolean\n\t/**\n\t * 是否已銷毀 / Whether destroyed\n\t */\n\tprotected override destroyed: boolean\n\n\t/**\n\t * 可寫狀態 / Writable state\n\t */\n\tprotected _writableState: IFsStreamState\n\t/**\n\t * 可讀狀態 / Readable state\n\t */\n\tprotected _readableState: IFsStreamState\n\n\t/**\n\t * 流資料符號屬性 / Stream data symbol property\n\t */\n\tprotected [SYM_FS_STREAM_DATA]: IFsStreamData\n\n\t/**\n\t * 已寫入的位元組數(不包含佇列中的資料)\n\t * Number of bytes written so far (excludes queued data)\n\t */\n\tpublic override bytesWritten: number\n\n\t/**\n\t * 檔案路徑(字串或 Buffer)\n\t * File path (string or Buffer)\n\t */\n\tpublic override readonly path: IFsPath\n\n\t/**\n\t * 構造函數\n\t * Constructor\n\t *\n\t * @param {PathLike} path - 檔案路徑 / File path\n\t * @param {string | IFsWriteStreamOptions} [options] - 選項 / Options\n\t */\n\tconstructor(path: PathLike, options?: string | IFsWriteStreamOptions)\n\t{\n\t\t// @ts-ignore\n\t\tsuper(path, options)\n\n\t\t// 初始化流資料 / Initialize stream data\n\t\tgetFsStreamData(this)\n\t}\n\n\t/**\n\t * 建立函數別名\n\t * Factory method alias\n\t */\n\tstatic get create()\n\t{\n\t\treturn createWriteStream\n\t}\n\n\t/**\n\t * 開啟檔案流\n\t * Open file stream\n\t *\n\t * 開啟檔案並發送 open 和 ready 事件\n\t * Opens file and emits open and ready events\n\t */\n\topen()\n\t{\n\t\tif (!getFsStreamData(this).opened)\n\t\t{\n\t\t\tconst self = this\n\n\t\t\tthis[SYM_FS_STREAM_DATA].opened = true\n\n\t\t\t// 監聽 open 事件並發送 ready 事件\n\t\t\t// Listen for open event and emit ready event\n\t\t\tthis.once('open', function ()\n\t\t\t{\n\t\t\t\tprocess.nextTick(function ()\n\t\t\t\t{\n\t\t\t\t\tself.emit('ready')\n\t\t\t\t})\n\t\t\t})\n\t\t\t// @ts-ignore\n\t\t\tfs.WriteStream.prototype.open.call(this)\n\t\t}\n\t}\n\n}\n\n/**\n * 建立寫入流\n * Create write stream\n *\n * 工廠函數,建立 WriteStream 實例\n * Factory function that creates a WriteStream instance\n *\n * @param {PathLike} path - 檔案路徑 / File path\n * @param {string | IFsWriteStreamOptions} [options] - 選項 / Options\n * @returns {WriteStream} 寫入流實例 / Write stream instance\n */\nexport function createWriteStream(path: PathLike, options?: string | IFsWriteStreamOptions)\n{\n\treturn new WriteStream(path, options)\n}\n\n/**\n * 預設導出 - WriteStream 類別\n * Default export - WriteStream class\n */\nexport default WriteStream\n"]}
|