@logtape/file 1.0.0-dev.246 → 1.0.0-dev.248

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 (43) hide show
  1. package/deno.json +1 -1
  2. package/dist/filesink.base.cjs +347 -52
  3. package/dist/filesink.base.d.cts +65 -3
  4. package/dist/filesink.base.d.cts.map +1 -1
  5. package/dist/filesink.base.d.ts +65 -3
  6. package/dist/filesink.base.d.ts.map +1 -1
  7. package/dist/filesink.base.js +347 -52
  8. package/dist/filesink.base.js.map +1 -1
  9. package/dist/filesink.deno.cjs +26 -23
  10. package/dist/filesink.deno.d.cts +17 -4
  11. package/dist/filesink.deno.d.cts.map +1 -1
  12. package/dist/filesink.deno.d.ts +17 -4
  13. package/dist/filesink.deno.d.ts.map +1 -1
  14. package/dist/filesink.deno.js +26 -24
  15. package/dist/filesink.deno.js.map +1 -1
  16. package/dist/filesink.node.cjs +33 -23
  17. package/dist/filesink.node.d.cts +17 -4
  18. package/dist/filesink.node.d.cts.map +1 -1
  19. package/dist/filesink.node.d.ts +17 -4
  20. package/dist/filesink.node.d.ts.map +1 -1
  21. package/dist/filesink.node.js +33 -24
  22. package/dist/filesink.node.js.map +1 -1
  23. package/dist/mod.cjs +3 -1
  24. package/dist/mod.d.cts +2 -1
  25. package/dist/mod.d.ts +2 -1
  26. package/dist/mod.js +2 -1
  27. package/dist/streamfilesink.cjs +84 -0
  28. package/dist/streamfilesink.d.cts +95 -0
  29. package/dist/streamfilesink.d.cts.map +1 -0
  30. package/dist/streamfilesink.d.ts +95 -0
  31. package/dist/streamfilesink.d.ts.map +1 -0
  32. package/dist/streamfilesink.js +84 -0
  33. package/dist/streamfilesink.js.map +1 -0
  34. package/filesink.base.ts +618 -37
  35. package/filesink.deno.ts +57 -4
  36. package/filesink.jsr.ts +32 -7
  37. package/filesink.node.ts +58 -4
  38. package/filesink.test.ts +120 -0
  39. package/mod.ts +2 -0
  40. package/package.json +4 -2
  41. package/streamfilesink.test.ts +336 -0
  42. package/streamfilesink.ts +136 -0
  43. package/tsdown.config.ts +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"filesink.deno.d.cts","names":[],"sources":["../filesink.deno.ts"],"sourcesContent":[],"mappings":";;;;;;;AAYA;AAeC,cAfY,UAeZ,EAfwB,sBAexB,CAf+C,IAAA,CAAK,MAepD,CAAA;;;AAf8C;AA2B/C;;;;;AAGoB;AAmBpB;AAAmC,iBAtBnB,WAAA,CAsBmB,IAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EApBxB,eAoBwB,CAAA,EAnBhC,IAmBgC,GAnBzB,UAmByB;;;;AAGf;;;;;;;;;;;;iBAHJ,mBAAA,yBAEL,0BACR,OAAO"}
1
+ {"version":3,"file":"filesink.deno.d.cts","names":[],"sources":["../filesink.deno.ts"],"sourcesContent":[],"mappings":";;;;;;;AAaA;AAsBC,cAtBY,UAsBZ,EAtBwB,sBAsBxB,CAtB+C,IAAA,CAAK,MAsBpD,CAAA;;;AAtB8C;AA4B/C;AAeC,cAfY,eAeZ,EAf6B,2BAe7B,CAfyD,IAAA,CAAK,MAe9D,CAAA;;;AAfwD;AA4BzD;;;;;AAGoB;AACpB;;AAEW,iBANK,WAAA,CAML,IAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAJC,eAID,CAAA,EAHR,IAGQ,GAHD,UAGC;AACR,iBAHa,WAAA,CAGb,IAAA,EAAA,MAAA,EAAA,OAAA,EADQ,eACR,GAAA;EAAI,WAAG,EAAA,IAAA;AAAe,CAAA,CAAA,EAAtB,IAAsB,GAAf,eAAe;AA2BzB;;;;;AAGoB;AACpB;;;;;AAGyB;;;;;iBAPT,mBAAA,yBAEJ,0BACT,OAAO;iBACM,mBAAA,wBAEL;;IACR,OAAO"}
@@ -1,4 +1,4 @@
1
- import { FileSinkOptions, RotatingFileSinkDriver, RotatingFileSinkOptions } from "./filesink.base.js";
1
+ import { AsyncRotatingFileSinkDriver, FileSinkOptions, RotatingFileSinkDriver, RotatingFileSinkOptions } from "./filesink.base.js";
2
2
  import { Sink } from "@logtape/logtape";
3
3
 
4
4
  //#region filesink.deno.d.ts
@@ -7,6 +7,11 @@ import { Sink } from "@logtape/logtape";
7
7
  * A Deno-specific file sink driver.
8
8
  */
9
9
  declare const denoDriver: RotatingFileSinkDriver<Deno.FsFile>;
10
+ /**
11
+ * A Deno-specific async file sink driver.
12
+ * @since 1.0.0
13
+ */
14
+ declare const denoAsyncDriver: AsyncRotatingFileSinkDriver<Deno.FsFile>;
10
15
  /**
11
16
  * Get a file sink.
12
17
  *
@@ -15,9 +20,13 @@ declare const denoDriver: RotatingFileSinkDriver<Deno.FsFile>;
15
20
  * @param path A path to the file to write to.
16
21
  * @param options The options for the sink.
17
22
  * @returns A sink that writes to the file. The sink is also a disposable
18
- * object that closes the file when disposed.
23
+ * object that closes the file when disposed. If `nonBlocking` is enabled,
24
+ * returns a sink that also implements {@link AsyncDisposable}.
19
25
  */
20
26
  declare function getFileSink(path: string, options?: FileSinkOptions): Sink & Disposable;
27
+ declare function getFileSink(path: string, options: FileSinkOptions & {
28
+ nonBlocking: true;
29
+ }): Sink & AsyncDisposable;
21
30
  /**
22
31
  * Get a rotating file sink.
23
32
  *
@@ -31,10 +40,14 @@ declare function getFileSink(path: string, options?: FileSinkOptions): Sink & Di
31
40
  * @param path A path to the file to write to.
32
41
  * @param options The options for the sink and the file driver.
33
42
  * @returns A sink that writes to the file. The sink is also a disposable
34
- * object that closes the file when disposed.
43
+ * object that closes the file when disposed. If `nonBlocking` is enabled,
44
+ * returns a sink that also implements {@link AsyncDisposable}.
35
45
  */
36
46
  declare function getRotatingFileSink(path: string, options?: RotatingFileSinkOptions): Sink & Disposable;
47
+ declare function getRotatingFileSink(path: string, options: RotatingFileSinkOptions & {
48
+ nonBlocking: true;
49
+ }): Sink & AsyncDisposable;
37
50
  //# sourceMappingURL=filesink.deno.d.ts.map
38
51
  //#endregion
39
- export { denoDriver, getFileSink, getRotatingFileSink };
52
+ export { denoAsyncDriver, denoDriver, getFileSink, getRotatingFileSink };
40
53
  //# sourceMappingURL=filesink.deno.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filesink.deno.d.ts","names":[],"sources":["../filesink.deno.ts"],"sourcesContent":[],"mappings":";;;;;;;AAYA;AAeC,cAfY,UAeZ,EAfwB,sBAexB,CAf+C,IAAA,CAAK,MAepD,CAAA;;;AAf8C;AA2B/C;;;;;AAGoB;AAmBpB;AAAmC,iBAtBnB,WAAA,CAsBmB,IAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EApBxB,eAoBwB,CAAA,EAnBhC,IAmBgC,GAnBzB,UAmByB;;;;AAGf;;;;;;;;;;;;iBAHJ,mBAAA,yBAEL,0BACR,OAAO"}
1
+ {"version":3,"file":"filesink.deno.d.ts","names":[],"sources":["../filesink.deno.ts"],"sourcesContent":[],"mappings":";;;;;;;AAaA;AAsBC,cAtBY,UAsBZ,EAtBwB,sBAsBxB,CAtB+C,IAAA,CAAK,MAsBpD,CAAA;;;AAtB8C;AA4B/C;AAeC,cAfY,eAeZ,EAf6B,2BAe7B,CAfyD,IAAA,CAAK,MAe9D,CAAA;;;AAfwD;AA4BzD;;;;;AAGoB;AACpB;;AAEW,iBANK,WAAA,CAML,IAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAJC,eAID,CAAA,EAHR,IAGQ,GAHD,UAGC;AACR,iBAHa,WAAA,CAGb,IAAA,EAAA,MAAA,EAAA,OAAA,EADQ,eACR,GAAA;EAAI,WAAG,EAAA,IAAA;AAAe,CAAA,CAAA,EAAtB,IAAsB,GAAf,eAAe;AA2BzB;;;;;AAGoB;AACpB;;;;;AAGyB;;;;;iBAPT,mBAAA,yBAEJ,0BACT,OAAO;iBACM,mBAAA,wBAEL;;IACR,OAAO"}
@@ -14,6 +14,9 @@ const denoDriver = {
14
14
  writeSync(fd, chunk) {
15
15
  fd.writeSync(chunk);
16
16
  },
17
+ writeManySync(fd, chunks) {
18
+ for (const chunk of chunks) fd.writeSync(chunk);
19
+ },
17
20
  flushSync(fd) {
18
21
  fd.syncSync();
19
22
  },
@@ -24,37 +27,36 @@ const denoDriver = {
24
27
  renameSync: globalThis?.Deno.renameSync
25
28
  };
26
29
  /**
27
- * Get a file sink.
28
- *
29
- * Note that this function is unavailable in the browser.
30
- *
31
- * @param path A path to the file to write to.
32
- * @param options The options for the sink.
33
- * @returns A sink that writes to the file. The sink is also a disposable
34
- * object that closes the file when disposed.
30
+ * A Deno-specific async file sink driver.
31
+ * @since 1.0.0
35
32
  */
33
+ const denoAsyncDriver = {
34
+ ...denoDriver,
35
+ async writeMany(fd, chunks) {
36
+ for (const chunk of chunks) await fd.write(chunk);
37
+ },
38
+ async flush(fd) {
39
+ await fd.sync();
40
+ },
41
+ close(fd) {
42
+ return Promise.resolve(fd.close());
43
+ }
44
+ };
36
45
  function getFileSink(path, options = {}) {
46
+ if (options.nonBlocking) return getBaseFileSink(path, {
47
+ ...options,
48
+ ...denoAsyncDriver
49
+ });
37
50
  return getBaseFileSink(path, {
38
51
  ...options,
39
52
  ...denoDriver
40
53
  });
41
54
  }
42
- /**
43
- * Get a rotating file sink.
44
- *
45
- * This sink writes log records to a file, and rotates the file when it reaches
46
- * the `maxSize`. The rotated files are named with the original file name
47
- * followed by a dot and a number, starting from 1. The number is incremented
48
- * for each rotation, and the maximum number of files to keep is `maxFiles`.
49
- *
50
- * Note that this function is unavailable in the browser.
51
- *
52
- * @param path A path to the file to write to.
53
- * @param options The options for the sink and the file driver.
54
- * @returns A sink that writes to the file. The sink is also a disposable
55
- * object that closes the file when disposed.
56
- */
57
55
  function getRotatingFileSink(path, options = {}) {
56
+ if (options.nonBlocking) return getBaseRotatingFileSink(path, {
57
+ ...options,
58
+ ...denoAsyncDriver
59
+ });
58
60
  return getBaseRotatingFileSink(path, {
59
61
  ...options,
60
62
  ...denoDriver
@@ -62,5 +64,5 @@ function getRotatingFileSink(path, options = {}) {
62
64
  }
63
65
 
64
66
  //#endregion
65
- export { denoDriver, getFileSink, getRotatingFileSink };
67
+ export { denoAsyncDriver, denoDriver, getFileSink, getRotatingFileSink };
66
68
  //# sourceMappingURL=filesink.deno.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"filesink.deno.js","names":["denoDriver: RotatingFileSinkDriver<Deno.FsFile>","path: string","options: FileSinkOptions","options: RotatingFileSinkOptions"],"sources":["../filesink.deno.ts"],"sourcesContent":["import type { Sink } from \"@logtape/logtape\";\nimport {\n type FileSinkOptions,\n getBaseFileSink,\n getBaseRotatingFileSink,\n type RotatingFileSinkDriver,\n type RotatingFileSinkOptions,\n} from \"./filesink.base.ts\";\n\n/**\n * A Deno-specific file sink driver.\n */\nexport const denoDriver: RotatingFileSinkDriver<Deno.FsFile> = {\n openSync(path: string) {\n return Deno.openSync(path, { create: true, append: true });\n },\n writeSync(fd, chunk) {\n fd.writeSync(chunk);\n },\n flushSync(fd) {\n fd.syncSync();\n },\n closeSync(fd) {\n fd.close();\n },\n statSync: globalThis?.Deno.statSync,\n renameSync: globalThis?.Deno.renameSync,\n};\n\n/**\n * Get a file sink.\n *\n * Note that this function is unavailable in the browser.\n *\n * @param path A path to the file to write to.\n * @param options The options for the sink.\n * @returns A sink that writes to the file. The sink is also a disposable\n * object that closes the file when disposed.\n */\nexport function getFileSink(\n path: string,\n options: FileSinkOptions = {},\n): Sink & Disposable {\n return getBaseFileSink(path, { ...options, ...denoDriver });\n}\n\n/**\n * Get a rotating file sink.\n *\n * This sink writes log records to a file, and rotates the file when it reaches\n * the `maxSize`. The rotated files are named with the original file name\n * followed by a dot and a number, starting from 1. The number is incremented\n * for each rotation, and the maximum number of files to keep is `maxFiles`.\n *\n * Note that this function is unavailable in the browser.\n *\n * @param path A path to the file to write to.\n * @param options The options for the sink and the file driver.\n * @returns A sink that writes to the file. The sink is also a disposable\n * object that closes the file when disposed.\n */\nexport function getRotatingFileSink(\n path: string,\n options: RotatingFileSinkOptions = {},\n): Sink & Disposable {\n return getBaseRotatingFileSink(path, { ...options, ...denoDriver });\n}\n\n// cSpell: ignore filesink\n"],"mappings":";;;;;;AAYA,MAAaA,aAAkD;CAC7D,SAASC,MAAc;AACrB,SAAO,KAAK,SAAS,MAAM;GAAE,QAAQ;GAAM,QAAQ;EAAM,EAAC;CAC3D;CACD,UAAU,IAAI,OAAO;AACnB,KAAG,UAAU,MAAM;CACpB;CACD,UAAU,IAAI;AACZ,KAAG,UAAU;CACd;CACD,UAAU,IAAI;AACZ,KAAG,OAAO;CACX;CACD,UAAU,YAAY,KAAK;CAC3B,YAAY,YAAY,KAAK;AAC9B;;;;;;;;;;;AAYD,SAAgB,YACdA,MACAC,UAA2B,CAAE,GACV;AACnB,QAAO,gBAAgB,MAAM;EAAE,GAAG;EAAS,GAAG;CAAY,EAAC;AAC5D;;;;;;;;;;;;;;;;AAiBD,SAAgB,oBACdD,MACAE,UAAmC,CAAE,GAClB;AACnB,QAAO,wBAAwB,MAAM;EAAE,GAAG;EAAS,GAAG;CAAY,EAAC;AACpE"}
1
+ {"version":3,"file":"filesink.deno.js","names":["denoDriver: RotatingFileSinkDriver<Deno.FsFile>","path: string","fd: Deno.FsFile","chunks: Uint8Array[]","denoAsyncDriver: AsyncRotatingFileSinkDriver<Deno.FsFile>","options: FileSinkOptions","options: RotatingFileSinkOptions"],"sources":["../filesink.deno.ts"],"sourcesContent":["import type { Sink } from \"@logtape/logtape\";\nimport {\n type AsyncRotatingFileSinkDriver,\n type FileSinkOptions,\n getBaseFileSink,\n getBaseRotatingFileSink,\n type RotatingFileSinkDriver,\n type RotatingFileSinkOptions,\n} from \"./filesink.base.ts\";\n\n/**\n * A Deno-specific file sink driver.\n */\nexport const denoDriver: RotatingFileSinkDriver<Deno.FsFile> = {\n openSync(path: string) {\n return Deno.openSync(path, { create: true, append: true });\n },\n writeSync(fd, chunk) {\n fd.writeSync(chunk);\n },\n writeManySync(fd: Deno.FsFile, chunks: Uint8Array[]): void {\n // Deno doesn't have writev, but we can optimize by writing all chunks\n // then doing a single sync operation\n for (const chunk of chunks) {\n fd.writeSync(chunk);\n }\n },\n flushSync(fd) {\n fd.syncSync();\n },\n closeSync(fd) {\n fd.close();\n },\n statSync: globalThis?.Deno.statSync,\n renameSync: globalThis?.Deno.renameSync,\n};\n\n/**\n * A Deno-specific async file sink driver.\n * @since 1.0.0\n */\nexport const denoAsyncDriver: AsyncRotatingFileSinkDriver<Deno.FsFile> = {\n ...denoDriver,\n async writeMany(fd: Deno.FsFile, chunks: Uint8Array[]): Promise<void> {\n // Deno doesn't have async writev, but we can write all chunks\n // then do a single async sync\n for (const chunk of chunks) {\n await fd.write(chunk);\n }\n },\n async flush(fd) {\n await fd.sync();\n },\n close(fd) {\n return Promise.resolve(fd.close());\n },\n};\n\n/**\n * Get a file sink.\n *\n * Note that this function is unavailable in the browser.\n *\n * @param path A path to the file to write to.\n * @param options The options for the sink.\n * @returns A sink that writes to the file. The sink is also a disposable\n * object that closes the file when disposed. If `nonBlocking` is enabled,\n * returns a sink that also implements {@link AsyncDisposable}.\n */\nexport function getFileSink(\n path: string,\n options?: FileSinkOptions,\n): Sink & Disposable;\nexport function getFileSink(\n path: string,\n options: FileSinkOptions & { nonBlocking: true },\n): Sink & AsyncDisposable;\nexport function getFileSink(\n path: string,\n options: FileSinkOptions = {},\n): Sink & (Disposable | AsyncDisposable) {\n if (options.nonBlocking) {\n return getBaseFileSink(path, { ...options, ...denoAsyncDriver });\n }\n return getBaseFileSink(path, { ...options, ...denoDriver });\n}\n\n/**\n * Get a rotating file sink.\n *\n * This sink writes log records to a file, and rotates the file when it reaches\n * the `maxSize`. The rotated files are named with the original file name\n * followed by a dot and a number, starting from 1. The number is incremented\n * for each rotation, and the maximum number of files to keep is `maxFiles`.\n *\n * Note that this function is unavailable in the browser.\n *\n * @param path A path to the file to write to.\n * @param options The options for the sink and the file driver.\n * @returns A sink that writes to the file. The sink is also a disposable\n * object that closes the file when disposed. If `nonBlocking` is enabled,\n * returns a sink that also implements {@link AsyncDisposable}.\n */\nexport function getRotatingFileSink(\n path: string,\n options?: RotatingFileSinkOptions,\n): Sink & Disposable;\nexport function getRotatingFileSink(\n path: string,\n options: RotatingFileSinkOptions & { nonBlocking: true },\n): Sink & AsyncDisposable;\nexport function getRotatingFileSink(\n path: string,\n options: RotatingFileSinkOptions = {},\n): Sink & (Disposable | AsyncDisposable) {\n if (options.nonBlocking) {\n return getBaseRotatingFileSink(path, { ...options, ...denoAsyncDriver });\n }\n return getBaseRotatingFileSink(path, { ...options, ...denoDriver });\n}\n\n// cSpell: ignore filesink\n"],"mappings":";;;;;;AAaA,MAAaA,aAAkD;CAC7D,SAASC,MAAc;AACrB,SAAO,KAAK,SAAS,MAAM;GAAE,QAAQ;GAAM,QAAQ;EAAM,EAAC;CAC3D;CACD,UAAU,IAAI,OAAO;AACnB,KAAG,UAAU,MAAM;CACpB;CACD,cAAcC,IAAiBC,QAA4B;AAGzD,OAAK,MAAM,SAAS,OAClB,IAAG,UAAU,MAAM;CAEtB;CACD,UAAU,IAAI;AACZ,KAAG,UAAU;CACd;CACD,UAAU,IAAI;AACZ,KAAG,OAAO;CACX;CACD,UAAU,YAAY,KAAK;CAC3B,YAAY,YAAY,KAAK;AAC9B;;;;;AAMD,MAAaC,kBAA4D;CACvE,GAAG;CACH,MAAM,UAAUF,IAAiBC,QAAqC;AAGpE,OAAK,MAAM,SAAS,OAClB,OAAM,GAAG,MAAM,MAAM;CAExB;CACD,MAAM,MAAM,IAAI;AACd,QAAM,GAAG,MAAM;CAChB;CACD,MAAM,IAAI;AACR,SAAO,QAAQ,QAAQ,GAAG,OAAO,CAAC;CACnC;AACF;AAqBD,SAAgB,YACdF,MACAI,UAA2B,CAAE,GACU;AACvC,KAAI,QAAQ,YACV,QAAO,gBAAgB,MAAM;EAAE,GAAG;EAAS,GAAG;CAAiB,EAAC;AAElE,QAAO,gBAAgB,MAAM;EAAE,GAAG;EAAS,GAAG;CAAY,EAAC;AAC5D;AA0BD,SAAgB,oBACdJ,MACAK,UAAmC,CAAE,GACE;AACvC,KAAI,QAAQ,YACV,QAAO,wBAAwB,MAAM;EAAE,GAAG;EAAS,GAAG;CAAiB,EAAC;AAE1E,QAAO,wBAAwB,MAAM;EAAE,GAAG;EAAS,GAAG;CAAY,EAAC;AACpE"}
@@ -1,6 +1,7 @@
1
1
  const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
2
  const require_filesink_base = require('./filesink.base.cjs');
3
3
  const node_fs = require_rolldown_runtime.__toESM(require("node:fs"));
4
+ const node_util = require_rolldown_runtime.__toESM(require("node:util"));
4
5
 
5
6
  //#region filesink.node.ts
6
7
  /**
@@ -11,43 +12,51 @@ const nodeDriver = {
11
12
  return node_fs.default.openSync(path, "a");
12
13
  },
13
14
  writeSync: node_fs.default.writeSync,
15
+ writeManySync(fd, chunks) {
16
+ if (chunks.length === 0) return;
17
+ if (chunks.length === 1) {
18
+ node_fs.default.writeSync(fd, chunks[0]);
19
+ return;
20
+ }
21
+ node_fs.default.writevSync(fd, chunks);
22
+ },
14
23
  flushSync: node_fs.default.fsyncSync,
15
24
  closeSync: node_fs.default.closeSync,
16
25
  statSync: node_fs.default.statSync,
17
26
  renameSync: node_fs.default.renameSync
18
27
  };
19
28
  /**
20
- * Get a file sink.
21
- *
22
- * Note that this function is unavailable in the browser.
23
- *
24
- * @param path A path to the file to write to.
25
- * @param options The options for the sink.
26
- * @returns A sink that writes to the file. The sink is also a disposable
27
- * object that closes the file when disposed.
29
+ * A Node.js-specific async file sink driver.
30
+ * @since 1.0.0
28
31
  */
32
+ const nodeAsyncDriver = {
33
+ ...nodeDriver,
34
+ async writeMany(fd, chunks) {
35
+ if (chunks.length === 0) return;
36
+ if (chunks.length === 1) {
37
+ await (0, node_util.promisify)(node_fs.default.write)(fd, chunks[0]);
38
+ return;
39
+ }
40
+ await (0, node_util.promisify)(node_fs.default.writev)(fd, chunks);
41
+ },
42
+ flush: (0, node_util.promisify)(node_fs.default.fsync),
43
+ close: (0, node_util.promisify)(node_fs.default.close)
44
+ };
29
45
  function getFileSink(path, options = {}) {
46
+ if (options.nonBlocking) return require_filesink_base.getBaseFileSink(path, {
47
+ ...options,
48
+ ...nodeAsyncDriver
49
+ });
30
50
  return require_filesink_base.getBaseFileSink(path, {
31
51
  ...options,
32
52
  ...nodeDriver
33
53
  });
34
54
  }
35
- /**
36
- * Get a rotating file sink.
37
- *
38
- * This sink writes log records to a file, and rotates the file when it reaches
39
- * the `maxSize`. The rotated files are named with the original file name
40
- * followed by a dot and a number, starting from 1. The number is incremented
41
- * for each rotation, and the maximum number of files to keep is `maxFiles`.
42
- *
43
- * Note that this function is unavailable in the browser.
44
- *
45
- * @param path A path to the file to write to.
46
- * @param options The options for the sink and the file driver.
47
- * @returns A sink that writes to the file. The sink is also a disposable
48
- * object that closes the file when disposed.
49
- */
50
55
  function getRotatingFileSink(path, options = {}) {
56
+ if (options.nonBlocking) return require_filesink_base.getBaseRotatingFileSink(path, {
57
+ ...options,
58
+ ...nodeAsyncDriver
59
+ });
51
60
  return require_filesink_base.getBaseRotatingFileSink(path, {
52
61
  ...options,
53
62
  ...nodeDriver
@@ -57,4 +66,5 @@ function getRotatingFileSink(path, options = {}) {
57
66
  //#endregion
58
67
  exports.getFileSink = getFileSink;
59
68
  exports.getRotatingFileSink = getRotatingFileSink;
69
+ exports.nodeAsyncDriver = nodeAsyncDriver;
60
70
  exports.nodeDriver = nodeDriver;
@@ -1,4 +1,4 @@
1
- import { FileSinkOptions, RotatingFileSinkDriver, RotatingFileSinkOptions } from "./filesink.base.cjs";
1
+ import { AsyncRotatingFileSinkDriver, FileSinkOptions, RotatingFileSinkDriver, RotatingFileSinkOptions } from "./filesink.base.cjs";
2
2
  import { Sink } from "@logtape/logtape";
3
3
 
4
4
  //#region filesink.node.d.ts
@@ -7,6 +7,11 @@ import { Sink } from "@logtape/logtape";
7
7
  * A Node.js-specific file sink driver.
8
8
  */
9
9
  declare const nodeDriver: RotatingFileSinkDriver<number | void>;
10
+ /**
11
+ * A Node.js-specific async file sink driver.
12
+ * @since 1.0.0
13
+ */
14
+ declare const nodeAsyncDriver: AsyncRotatingFileSinkDriver<number | void>;
10
15
  /**
11
16
  * Get a file sink.
12
17
  *
@@ -15,9 +20,13 @@ declare const nodeDriver: RotatingFileSinkDriver<number | void>;
15
20
  * @param path A path to the file to write to.
16
21
  * @param options The options for the sink.
17
22
  * @returns A sink that writes to the file. The sink is also a disposable
18
- * object that closes the file when disposed.
23
+ * object that closes the file when disposed. If `nonBlocking` is enabled,
24
+ * returns a sink that also implements {@link AsyncDisposable}.
19
25
  */
20
26
  declare function getFileSink(path: string, options?: FileSinkOptions): Sink & Disposable;
27
+ declare function getFileSink(path: string, options: FileSinkOptions & {
28
+ nonBlocking: true;
29
+ }): Sink & AsyncDisposable;
21
30
  /**
22
31
  * Get a rotating file sink.
23
32
  *
@@ -31,10 +40,14 @@ declare function getFileSink(path: string, options?: FileSinkOptions): Sink & Di
31
40
  * @param path A path to the file to write to.
32
41
  * @param options The options for the sink and the file driver.
33
42
  * @returns A sink that writes to the file. The sink is also a disposable
34
- * object that closes the file when disposed.
43
+ * object that closes the file when disposed. If `nonBlocking` is enabled,
44
+ * returns a sink that also implements {@link AsyncDisposable}.
35
45
  */
36
46
  declare function getRotatingFileSink(path: string, options?: RotatingFileSinkOptions): Sink & Disposable;
47
+ declare function getRotatingFileSink(path: string, options: RotatingFileSinkOptions & {
48
+ nonBlocking: true;
49
+ }): Sink & AsyncDisposable;
37
50
  //# sourceMappingURL=filesink.node.d.ts.map
38
51
  //#endregion
39
- export { getFileSink, getRotatingFileSink, nodeDriver };
52
+ export { getFileSink, getRotatingFileSink, nodeAsyncDriver, nodeDriver };
40
53
  //# sourceMappingURL=filesink.node.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filesink.node.d.cts","names":[],"sources":["../filesink.node.ts"],"sourcesContent":[],"mappings":";;;;;;;AAaA;AAqBgB,cArBH,UAqBc,EArBF,sBAqBE,CAAA,MAAA,GAAA,IAAA,CAAA;;;;;AAGP;AAmBpB;;;;;AAGoB,iBAzBJ,WAAA,CAyBI,IAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAvBT,eAuBS,CAAA,EAtBjB,IAsBiB,GAtBV,UAsBU;;;;;;;;;;;;;;;;iBAHJ,mBAAA,yBAEL,0BACR,OAAO"}
1
+ {"version":3,"file":"filesink.node.d.cts","names":[],"sources":["../filesink.node.ts"],"sourcesContent":[],"mappings":";;;;;;;AAeA;AAwBa,cAxBA,UAqCZ,EArCwB,sBAwBK,CAAA,MAA2B,GAAA,IAAA,CAAA;AA0BzD;;;;AAGU,cA7BG,eA6BH,EA7BoB,2BA6BpB,CAAA,MAAA,GAAA,IAAA,CAAA;AAAU;AACpB;;;;;AAGyB;AA2BzB;;;;AAGU,iBArCM,WAAA,CAqCN,IAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAnCE,eAmCF,CAAA,EAlCP,IAkCO,GAlCA,UAkCA;AAAU,iBAjCJ,WAAA,CAiCI,IAAA,EAAA,MAAA,EAAA,OAAA,EA/BT,eA+BS,GAAA;EACJ,WAAA,EAAA,IAAA;CAAmB,CAAA,EA/BhC,IA+BgC,GA/BzB,eA+ByB;;;;AAGV;;;;;;;;;;;;;iBAPT,mBAAA,yBAEJ,0BACT,OAAO;iBACM,mBAAA,wBAEL;;IACR,OAAO"}
@@ -1,4 +1,4 @@
1
- import { FileSinkOptions, RotatingFileSinkDriver, RotatingFileSinkOptions } from "./filesink.base.js";
1
+ import { AsyncRotatingFileSinkDriver, FileSinkOptions, RotatingFileSinkDriver, RotatingFileSinkOptions } from "./filesink.base.js";
2
2
  import { Sink } from "@logtape/logtape";
3
3
 
4
4
  //#region filesink.node.d.ts
@@ -7,6 +7,11 @@ import { Sink } from "@logtape/logtape";
7
7
  * A Node.js-specific file sink driver.
8
8
  */
9
9
  declare const nodeDriver: RotatingFileSinkDriver<number | void>;
10
+ /**
11
+ * A Node.js-specific async file sink driver.
12
+ * @since 1.0.0
13
+ */
14
+ declare const nodeAsyncDriver: AsyncRotatingFileSinkDriver<number | void>;
10
15
  /**
11
16
  * Get a file sink.
12
17
  *
@@ -15,9 +20,13 @@ declare const nodeDriver: RotatingFileSinkDriver<number | void>;
15
20
  * @param path A path to the file to write to.
16
21
  * @param options The options for the sink.
17
22
  * @returns A sink that writes to the file. The sink is also a disposable
18
- * object that closes the file when disposed.
23
+ * object that closes the file when disposed. If `nonBlocking` is enabled,
24
+ * returns a sink that also implements {@link AsyncDisposable}.
19
25
  */
20
26
  declare function getFileSink(path: string, options?: FileSinkOptions): Sink & Disposable;
27
+ declare function getFileSink(path: string, options: FileSinkOptions & {
28
+ nonBlocking: true;
29
+ }): Sink & AsyncDisposable;
21
30
  /**
22
31
  * Get a rotating file sink.
23
32
  *
@@ -31,10 +40,14 @@ declare function getFileSink(path: string, options?: FileSinkOptions): Sink & Di
31
40
  * @param path A path to the file to write to.
32
41
  * @param options The options for the sink and the file driver.
33
42
  * @returns A sink that writes to the file. The sink is also a disposable
34
- * object that closes the file when disposed.
43
+ * object that closes the file when disposed. If `nonBlocking` is enabled,
44
+ * returns a sink that also implements {@link AsyncDisposable}.
35
45
  */
36
46
  declare function getRotatingFileSink(path: string, options?: RotatingFileSinkOptions): Sink & Disposable;
47
+ declare function getRotatingFileSink(path: string, options: RotatingFileSinkOptions & {
48
+ nonBlocking: true;
49
+ }): Sink & AsyncDisposable;
37
50
  //# sourceMappingURL=filesink.node.d.ts.map
38
51
  //#endregion
39
- export { getFileSink, getRotatingFileSink, nodeDriver };
52
+ export { getFileSink, getRotatingFileSink, nodeAsyncDriver, nodeDriver };
40
53
  //# sourceMappingURL=filesink.node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filesink.node.d.ts","names":[],"sources":["../filesink.node.ts"],"sourcesContent":[],"mappings":";;;;;;;AAaA;AAqBgB,cArBH,UAqBc,EArBF,sBAqBE,CAAA,MAAA,GAAA,IAAA,CAAA;;;;;AAGP;AAmBpB;;;;;AAGoB,iBAzBJ,WAAA,CAyBI,IAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAvBT,eAuBS,CAAA,EAtBjB,IAsBiB,GAtBV,UAsBU;;;;;;;;;;;;;;;;iBAHJ,mBAAA,yBAEL,0BACR,OAAO"}
1
+ {"version":3,"file":"filesink.node.d.ts","names":[],"sources":["../filesink.node.ts"],"sourcesContent":[],"mappings":";;;;;;;AAeA;AAwBa,cAxBA,UAqCZ,EArCwB,sBAwBK,CAAA,MAA2B,GAAA,IAAA,CAAA;AA0BzD;;;;AAGU,cA7BG,eA6BH,EA7BoB,2BA6BpB,CAAA,MAAA,GAAA,IAAA,CAAA;AAAU;AACpB;;;;;AAGyB;AA2BzB;;;;AAGU,iBArCM,WAAA,CAqCN,IAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAnCE,eAmCF,CAAA,EAlCP,IAkCO,GAlCA,UAkCA;AAAU,iBAjCJ,WAAA,CAiCI,IAAA,EAAA,MAAA,EAAA,OAAA,EA/BT,eA+BS,GAAA;EACJ,WAAA,EAAA,IAAA;CAAmB,CAAA,EA/BhC,IA+BgC,GA/BzB,eA+ByB;;;;AAGV;;;;;;;;;;;;;iBAPT,mBAAA,yBAEJ,0BACT,OAAO;iBACM,mBAAA,wBAEL;;IACR,OAAO"}
@@ -1,5 +1,6 @@
1
1
  import { getBaseFileSink, getBaseRotatingFileSink } from "./filesink.base.js";
2
2
  import fs from "node:fs";
3
+ import { promisify } from "node:util";
3
4
 
4
5
  //#region filesink.node.ts
5
6
  /**
@@ -10,43 +11,51 @@ const nodeDriver = {
10
11
  return fs.openSync(path, "a");
11
12
  },
12
13
  writeSync: fs.writeSync,
14
+ writeManySync(fd, chunks) {
15
+ if (chunks.length === 0) return;
16
+ if (chunks.length === 1) {
17
+ fs.writeSync(fd, chunks[0]);
18
+ return;
19
+ }
20
+ fs.writevSync(fd, chunks);
21
+ },
13
22
  flushSync: fs.fsyncSync,
14
23
  closeSync: fs.closeSync,
15
24
  statSync: fs.statSync,
16
25
  renameSync: fs.renameSync
17
26
  };
18
27
  /**
19
- * Get a file sink.
20
- *
21
- * Note that this function is unavailable in the browser.
22
- *
23
- * @param path A path to the file to write to.
24
- * @param options The options for the sink.
25
- * @returns A sink that writes to the file. The sink is also a disposable
26
- * object that closes the file when disposed.
28
+ * A Node.js-specific async file sink driver.
29
+ * @since 1.0.0
27
30
  */
31
+ const nodeAsyncDriver = {
32
+ ...nodeDriver,
33
+ async writeMany(fd, chunks) {
34
+ if (chunks.length === 0) return;
35
+ if (chunks.length === 1) {
36
+ await promisify(fs.write)(fd, chunks[0]);
37
+ return;
38
+ }
39
+ await promisify(fs.writev)(fd, chunks);
40
+ },
41
+ flush: promisify(fs.fsync),
42
+ close: promisify(fs.close)
43
+ };
28
44
  function getFileSink(path, options = {}) {
45
+ if (options.nonBlocking) return getBaseFileSink(path, {
46
+ ...options,
47
+ ...nodeAsyncDriver
48
+ });
29
49
  return getBaseFileSink(path, {
30
50
  ...options,
31
51
  ...nodeDriver
32
52
  });
33
53
  }
34
- /**
35
- * Get a rotating file sink.
36
- *
37
- * This sink writes log records to a file, and rotates the file when it reaches
38
- * the `maxSize`. The rotated files are named with the original file name
39
- * followed by a dot and a number, starting from 1. The number is incremented
40
- * for each rotation, and the maximum number of files to keep is `maxFiles`.
41
- *
42
- * Note that this function is unavailable in the browser.
43
- *
44
- * @param path A path to the file to write to.
45
- * @param options The options for the sink and the file driver.
46
- * @returns A sink that writes to the file. The sink is also a disposable
47
- * object that closes the file when disposed.
48
- */
49
54
  function getRotatingFileSink(path, options = {}) {
55
+ if (options.nonBlocking) return getBaseRotatingFileSink(path, {
56
+ ...options,
57
+ ...nodeAsyncDriver
58
+ });
50
59
  return getBaseRotatingFileSink(path, {
51
60
  ...options,
52
61
  ...nodeDriver
@@ -54,5 +63,5 @@ function getRotatingFileSink(path, options = {}) {
54
63
  }
55
64
 
56
65
  //#endregion
57
- export { getFileSink, getRotatingFileSink, nodeDriver };
66
+ export { getFileSink, getRotatingFileSink, nodeAsyncDriver, nodeDriver };
58
67
  //# sourceMappingURL=filesink.node.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"filesink.node.js","names":["nodeDriver: RotatingFileSinkDriver<number | void>","path: string","options: FileSinkOptions","options: RotatingFileSinkOptions"],"sources":["../filesink.node.ts"],"sourcesContent":["import type { Sink } from \"@logtape/logtape\";\nimport fs from \"node:fs\";\nimport {\n type FileSinkOptions,\n getBaseFileSink,\n getBaseRotatingFileSink,\n type RotatingFileSinkDriver,\n type RotatingFileSinkOptions,\n} from \"./filesink.base.ts\";\n\n/**\n * A Node.js-specific file sink driver.\n */\nexport const nodeDriver: RotatingFileSinkDriver<number | void> = {\n openSync(path: string) {\n return fs.openSync(path, \"a\");\n },\n writeSync: fs.writeSync,\n flushSync: fs.fsyncSync,\n closeSync: fs.closeSync,\n statSync: fs.statSync,\n renameSync: fs.renameSync,\n};\n\n/**\n * Get a file sink.\n *\n * Note that this function is unavailable in the browser.\n *\n * @param path A path to the file to write to.\n * @param options The options for the sink.\n * @returns A sink that writes to the file. The sink is also a disposable\n * object that closes the file when disposed.\n */\nexport function getFileSink(\n path: string,\n options: FileSinkOptions = {},\n): Sink & Disposable {\n return getBaseFileSink(path, { ...options, ...nodeDriver });\n}\n\n/**\n * Get a rotating file sink.\n *\n * This sink writes log records to a file, and rotates the file when it reaches\n * the `maxSize`. The rotated files are named with the original file name\n * followed by a dot and a number, starting from 1. The number is incremented\n * for each rotation, and the maximum number of files to keep is `maxFiles`.\n *\n * Note that this function is unavailable in the browser.\n *\n * @param path A path to the file to write to.\n * @param options The options for the sink and the file driver.\n * @returns A sink that writes to the file. The sink is also a disposable\n * object that closes the file when disposed.\n */\nexport function getRotatingFileSink(\n path: string,\n options: RotatingFileSinkOptions = {},\n): Sink & Disposable {\n return getBaseRotatingFileSink(path, { ...options, ...nodeDriver });\n}\n\n// cSpell: ignore filesink\n"],"mappings":";;;;;;;AAaA,MAAaA,aAAoD;CAC/D,SAASC,MAAc;AACrB,SAAO,GAAG,SAAS,MAAM,IAAI;CAC9B;CACD,WAAW,GAAG;CACd,WAAW,GAAG;CACd,WAAW,GAAG;CACd,UAAU,GAAG;CACb,YAAY,GAAG;AAChB;;;;;;;;;;;AAYD,SAAgB,YACdA,MACAC,UAA2B,CAAE,GACV;AACnB,QAAO,gBAAgB,MAAM;EAAE,GAAG;EAAS,GAAG;CAAY,EAAC;AAC5D;;;;;;;;;;;;;;;;AAiBD,SAAgB,oBACdD,MACAE,UAAmC,CAAE,GAClB;AACnB,QAAO,wBAAwB,MAAM;EAAE,GAAG;EAAS,GAAG;CAAY,EAAC;AACpE"}
1
+ {"version":3,"file":"filesink.node.js","names":["nodeDriver: RotatingFileSinkDriver<number | void>","path: string","fd: number","chunks: Uint8Array[]","nodeAsyncDriver: AsyncRotatingFileSinkDriver<number | void>","options: FileSinkOptions","options: RotatingFileSinkOptions"],"sources":["../filesink.node.ts"],"sourcesContent":["import type { Sink } from \"@logtape/logtape\";\nimport fs from \"node:fs\";\nimport { promisify } from \"node:util\";\nimport {\n type AsyncRotatingFileSinkDriver,\n type FileSinkOptions,\n getBaseFileSink,\n getBaseRotatingFileSink,\n type RotatingFileSinkDriver,\n type RotatingFileSinkOptions,\n} from \"./filesink.base.ts\";\n\n/**\n * A Node.js-specific file sink driver.\n */\nexport const nodeDriver: RotatingFileSinkDriver<number | void> = {\n openSync(path: string) {\n return fs.openSync(path, \"a\");\n },\n writeSync: fs.writeSync,\n writeManySync(fd: number, chunks: Uint8Array[]): void {\n if (chunks.length === 0) return;\n if (chunks.length === 1) {\n fs.writeSync(fd, chunks[0]);\n return;\n }\n // Use writev for multiple chunks\n fs.writevSync(fd, chunks);\n },\n flushSync: fs.fsyncSync,\n closeSync: fs.closeSync,\n statSync: fs.statSync,\n renameSync: fs.renameSync,\n};\n\n/**\n * A Node.js-specific async file sink driver.\n * @since 1.0.0\n */\nexport const nodeAsyncDriver: AsyncRotatingFileSinkDriver<number | void> = {\n ...nodeDriver,\n async writeMany(fd: number, chunks: Uint8Array[]): Promise<void> {\n if (chunks.length === 0) return;\n if (chunks.length === 1) {\n await promisify(fs.write)(fd, chunks[0]);\n return;\n }\n // Use async writev for multiple chunks\n await promisify(fs.writev)(fd, chunks);\n },\n flush: promisify(fs.fsync),\n close: promisify(fs.close),\n};\n\n/**\n * Get a file sink.\n *\n * Note that this function is unavailable in the browser.\n *\n * @param path A path to the file to write to.\n * @param options The options for the sink.\n * @returns A sink that writes to the file. The sink is also a disposable\n * object that closes the file when disposed. If `nonBlocking` is enabled,\n * returns a sink that also implements {@link AsyncDisposable}.\n */\nexport function getFileSink(\n path: string,\n options?: FileSinkOptions,\n): Sink & Disposable;\nexport function getFileSink(\n path: string,\n options: FileSinkOptions & { nonBlocking: true },\n): Sink & AsyncDisposable;\nexport function getFileSink(\n path: string,\n options: FileSinkOptions = {},\n): Sink & (Disposable | AsyncDisposable) {\n if (options.nonBlocking) {\n return getBaseFileSink(path, { ...options, ...nodeAsyncDriver });\n }\n return getBaseFileSink(path, { ...options, ...nodeDriver });\n}\n\n/**\n * Get a rotating file sink.\n *\n * This sink writes log records to a file, and rotates the file when it reaches\n * the `maxSize`. The rotated files are named with the original file name\n * followed by a dot and a number, starting from 1. The number is incremented\n * for each rotation, and the maximum number of files to keep is `maxFiles`.\n *\n * Note that this function is unavailable in the browser.\n *\n * @param path A path to the file to write to.\n * @param options The options for the sink and the file driver.\n * @returns A sink that writes to the file. The sink is also a disposable\n * object that closes the file when disposed. If `nonBlocking` is enabled,\n * returns a sink that also implements {@link AsyncDisposable}.\n */\nexport function getRotatingFileSink(\n path: string,\n options?: RotatingFileSinkOptions,\n): Sink & Disposable;\nexport function getRotatingFileSink(\n path: string,\n options: RotatingFileSinkOptions & { nonBlocking: true },\n): Sink & AsyncDisposable;\nexport function getRotatingFileSink(\n path: string,\n options: RotatingFileSinkOptions = {},\n): Sink & (Disposable | AsyncDisposable) {\n if (options.nonBlocking) {\n return getBaseRotatingFileSink(path, { ...options, ...nodeAsyncDriver });\n }\n return getBaseRotatingFileSink(path, { ...options, ...nodeDriver });\n}\n\n// cSpell: ignore filesink\n"],"mappings":";;;;;;;;AAeA,MAAaA,aAAoD;CAC/D,SAASC,MAAc;AACrB,SAAO,GAAG,SAAS,MAAM,IAAI;CAC9B;CACD,WAAW,GAAG;CACd,cAAcC,IAAYC,QAA4B;AACpD,MAAI,OAAO,WAAW,EAAG;AACzB,MAAI,OAAO,WAAW,GAAG;AACvB,MAAG,UAAU,IAAI,OAAO,GAAG;AAC3B;EACD;AAED,KAAG,WAAW,IAAI,OAAO;CAC1B;CACD,WAAW,GAAG;CACd,WAAW,GAAG;CACd,UAAU,GAAG;CACb,YAAY,GAAG;AAChB;;;;;AAMD,MAAaC,kBAA8D;CACzE,GAAG;CACH,MAAM,UAAUF,IAAYC,QAAqC;AAC/D,MAAI,OAAO,WAAW,EAAG;AACzB,MAAI,OAAO,WAAW,GAAG;AACvB,SAAM,UAAU,GAAG,MAAM,CAAC,IAAI,OAAO,GAAG;AACxC;EACD;AAED,QAAM,UAAU,GAAG,OAAO,CAAC,IAAI,OAAO;CACvC;CACD,OAAO,UAAU,GAAG,MAAM;CAC1B,OAAO,UAAU,GAAG,MAAM;AAC3B;AAqBD,SAAgB,YACdF,MACAI,UAA2B,CAAE,GACU;AACvC,KAAI,QAAQ,YACV,QAAO,gBAAgB,MAAM;EAAE,GAAG;EAAS,GAAG;CAAiB,EAAC;AAElE,QAAO,gBAAgB,MAAM;EAAE,GAAG;EAAS,GAAG;CAAY,EAAC;AAC5D;AA0BD,SAAgB,oBACdJ,MACAK,UAAmC,CAAE,GACE;AACvC,KAAI,QAAQ,YACV,QAAO,wBAAwB,MAAM;EAAE,GAAG;EAAS,GAAG;CAAiB,EAAC;AAE1E,QAAO,wBAAwB,MAAM;EAAE,GAAG;EAAS,GAAG;CAAY,EAAC;AACpE"}
package/dist/mod.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_streamfilesink = require('./streamfilesink.cjs');
2
3
  const __filesink = require_rolldown_runtime.__toESM(require("#filesink"));
3
4
 
4
5
  Object.defineProperty(exports, 'getFileSink', {
@@ -12,4 +13,5 @@ Object.defineProperty(exports, 'getRotatingFileSink', {
12
13
  get: function () {
13
14
  return __filesink.getRotatingFileSink;
14
15
  }
15
- });
16
+ });
17
+ exports.getStreamFileSink = require_streamfilesink.getStreamFileSink;
package/dist/mod.d.cts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { FileSinkDriver, FileSinkOptions, RotatingFileSinkDriver, RotatingFileSinkOptions } from "./filesink.base.cjs";
2
+ import { StreamFileSinkOptions, getStreamFileSink } from "./streamfilesink.cjs";
2
3
  import { getFileSink, getRotatingFileSink } from "#filesink";
3
- export { FileSinkDriver, FileSinkOptions, RotatingFileSinkDriver, RotatingFileSinkOptions, getFileSink, getRotatingFileSink };
4
+ export { FileSinkDriver, FileSinkOptions, RotatingFileSinkDriver, RotatingFileSinkOptions, StreamFileSinkOptions, getFileSink, getRotatingFileSink, getStreamFileSink };
package/dist/mod.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { FileSinkDriver, FileSinkOptions, RotatingFileSinkDriver, RotatingFileSinkOptions } from "./filesink.base.js";
2
+ import { StreamFileSinkOptions, getStreamFileSink } from "./streamfilesink.js";
2
3
  import { getFileSink, getRotatingFileSink } from "#filesink";
3
- export { FileSinkDriver, FileSinkOptions, RotatingFileSinkDriver, RotatingFileSinkOptions, getFileSink, getRotatingFileSink };
4
+ export { FileSinkDriver, FileSinkOptions, RotatingFileSinkDriver, RotatingFileSinkOptions, StreamFileSinkOptions, getFileSink, getRotatingFileSink, getStreamFileSink };
package/dist/mod.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { getStreamFileSink } from "./streamfilesink.js";
1
2
  import { getFileSink, getRotatingFileSink } from "#filesink";
2
3
 
3
- export { getFileSink, getRotatingFileSink };
4
+ export { getFileSink, getRotatingFileSink, getStreamFileSink };
@@ -0,0 +1,84 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const __logtape_logtape = require_rolldown_runtime.__toESM(require("@logtape/logtape"));
3
+ const node_fs = require_rolldown_runtime.__toESM(require("node:fs"));
4
+ const node_stream = require_rolldown_runtime.__toESM(require("node:stream"));
5
+
6
+ //#region streamfilesink.ts
7
+ /**
8
+ * Create a high-performance stream-based file sink that writes log records to a file.
9
+ *
10
+ * This sink uses Node.js PassThrough streams piped to WriteStreams for optimal
11
+ * I/O performance. It leverages the Node.js stream infrastructure to provide
12
+ * automatic backpressure management, efficient buffering, and asynchronous writes
13
+ * without blocking the main thread.
14
+ *
15
+ * ## Performance Characteristics
16
+ *
17
+ * - **High Performance**: Optimized for high-volume logging scenarios
18
+ * - **Non-blocking**: Uses asynchronous I/O that doesn't block the main thread
19
+ * - **Memory Efficient**: Automatic backpressure prevents memory buildup
20
+ * - **Stream-based**: Leverages Node.js native stream optimizations
21
+ *
22
+ * ## When to Use
23
+ *
24
+ * Use this sink when you need:
25
+ * - High-performance file logging for production applications
26
+ * - Non-blocking I/O behavior for real-time applications
27
+ * - Automatic backpressure handling for high-volume scenarios
28
+ * - Simple file output without complex buffering configuration
29
+ *
30
+ * For more control over buffering behavior, consider using {@link getFileSink}
31
+ * instead, which provides options for buffer size, flush intervals, and
32
+ * non-blocking modes.
33
+ *
34
+ * ## Example
35
+ *
36
+ * ```typescript
37
+ * import { configure } from "@logtape/logtape";
38
+ * import { getStreamFileSink } from "@logtape/file";
39
+ *
40
+ * await configure({
41
+ * sinks: {
42
+ * file: getStreamFileSink("app.log", {
43
+ * highWaterMark: 32768 // 32KB buffer for high-volume logging
44
+ * })
45
+ * },
46
+ * loggers: [
47
+ * { category: ["myapp"], sinks: ["file"] }
48
+ * ]
49
+ * });
50
+ * ```
51
+ *
52
+ * @param path The path to the file to write logs to. The file will be created
53
+ * if it doesn't exist, or appended to if it does exist.
54
+ * @param options Configuration options for the stream-based sink.
55
+ * @returns A sink that writes formatted log records to the specified file.
56
+ * The returned sink implements `Disposable` for proper resource cleanup.
57
+ *
58
+ * @since 1.0.0
59
+ */
60
+ function getStreamFileSink(path, options = {}) {
61
+ const highWaterMark = options.highWaterMark ?? 16384;
62
+ const formatter = options.formatter ?? __logtape_logtape.defaultTextFormatter;
63
+ const passThrough = new node_stream.PassThrough({
64
+ highWaterMark,
65
+ objectMode: false
66
+ });
67
+ const writeStream = (0, node_fs.createWriteStream)(path, { flags: "a" });
68
+ passThrough.pipe(writeStream);
69
+ let disposed = false;
70
+ const sink = (record) => {
71
+ if (disposed) return;
72
+ passThrough.write(formatter(record));
73
+ };
74
+ sink[Symbol.dispose] = () => {
75
+ if (disposed) return;
76
+ disposed = true;
77
+ passThrough.end();
78
+ writeStream.end();
79
+ };
80
+ return sink;
81
+ }
82
+
83
+ //#endregion
84
+ exports.getStreamFileSink = getStreamFileSink;