@logtape/file 1.0.0-dev.236 → 1.0.0-dev.237

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.
@@ -1 +1 @@
1
- {"version":3,"file":"filesink.base.js","names":["path: string","options: FileSinkOptions & FileSinkDriver<TFile>","buffer: string","lastFlushTimestamp: number","sink: Sink & Disposable","record: LogRecord","options: RotatingFileSinkOptions & RotatingFileSinkDriver<TFile>","offset: number","bytes: Uint8Array"],"sources":["../filesink.base.ts"],"sourcesContent":["import {\n defaultTextFormatter,\n type LogRecord,\n type Sink,\n type StreamSinkOptions,\n} from \"@logtape/logtape\";\n\n/**\n * Options for the {@link getBaseFileSink} function.\n */\nexport type FileSinkOptions = StreamSinkOptions & {\n /**\n * If `true`, the file is not opened until the first write. Defaults to `false`.\n */\n lazy?: boolean;\n\n /**\n * The size of the buffer to use when writing to the file. If not specified,\n * a default buffer size will be used. If it is less or equal to 0,\n * the file will be written directly without buffering.\n * @default 8192\n * @since 0.12.0\n */\n bufferSize?: number;\n\n /**\n * The maximum time interval in milliseconds between flushes. If this time\n * passes since the last flush, the buffer will be flushed regardless of size.\n * This helps prevent log loss during unexpected process termination.\n * @default 5000\n * @since 0.12.0\n */\n flushInterval?: number;\n};\n\n/**\n * A platform-specific file sink driver.\n * @typeParam TFile The type of the file descriptor.\n */\nexport interface FileSinkDriver<TFile> {\n /**\n * Open a file for appending and return a file descriptor.\n * @param path A path to the file to open.\n */\n openSync(path: string): TFile;\n\n /**\n * Write a chunk of data to the file.\n * @param fd The file descriptor.\n * @param chunk The data to write.\n */\n writeSync(fd: TFile, chunk: Uint8Array): void;\n\n /**\n * Flush the file to ensure that all data is written to the disk.\n * @param fd The file descriptor.\n */\n flushSync(fd: TFile): void;\n\n /**\n * Close the file.\n * @param fd The file descriptor.\n */\n closeSync(fd: TFile): void;\n}\n\n/**\n * Get a platform-independent file sink.\n *\n * @typeParam TFile The type of the file descriptor.\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 getBaseFileSink<TFile>(\n path: string,\n options: FileSinkOptions & FileSinkDriver<TFile>,\n): Sink & Disposable {\n const formatter = options.formatter ?? defaultTextFormatter;\n const encoder = options.encoder ?? new TextEncoder();\n const bufferSize = options.bufferSize ?? 1024 * 8; // Default buffer size of 8192 chars\n const flushInterval = options.flushInterval ?? 5000; // Default flush interval of 5 seconds\n let fd = options.lazy ? null : options.openSync(path);\n let buffer: string = \"\";\n let lastFlushTimestamp: number = Date.now();\n\n function flushBuffer(): void {\n if (fd == null) return;\n if (buffer.length > 0) {\n options.writeSync(fd, encoder.encode(buffer));\n buffer = \"\";\n options.flushSync(fd);\n lastFlushTimestamp = Date.now();\n }\n }\n\n const sink: Sink & Disposable = (record: LogRecord) => {\n if (fd == null) fd = options.openSync(path);\n buffer += formatter(record);\n\n const shouldFlushBySize = buffer.length >= bufferSize;\n const shouldFlushByTime = flushInterval > 0 &&\n (record.timestamp - lastFlushTimestamp) >= flushInterval;\n\n if (shouldFlushBySize || shouldFlushByTime) {\n flushBuffer();\n }\n };\n sink[Symbol.dispose] = () => {\n if (fd !== null) {\n flushBuffer();\n options.closeSync(fd);\n }\n };\n return sink;\n}\n\n/**\n * Options for the {@link getBaseRotatingFileSink} function.\n */\nexport interface RotatingFileSinkOptions extends Omit<FileSinkOptions, \"lazy\"> {\n /**\n * The maximum bytes of the file before it is rotated. 1 MiB by default.\n */\n maxSize?: number;\n\n /**\n * The maximum number of files to keep. 5 by default.\n */\n maxFiles?: number;\n}\n\n/**\n * A platform-specific rotating file sink driver.\n */\nexport interface RotatingFileSinkDriver<TFile> extends FileSinkDriver<TFile> {\n /**\n * Get the size of the file.\n * @param path A path to the file.\n * @returns The `size` of the file in bytes, in an object.\n */\n statSync(path: string): { size: number };\n\n /**\n * Rename a file.\n * @param oldPath A path to the file to rename.\n * @param newPath A path to be renamed to.\n */\n renameSync(oldPath: string, newPath: string): void;\n}\n\n/**\n * Get a platform-independent 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 * @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 getBaseRotatingFileSink<TFile>(\n path: string,\n options: RotatingFileSinkOptions & RotatingFileSinkDriver<TFile>,\n): Sink & Disposable {\n const formatter = options.formatter ?? defaultTextFormatter;\n const encoder = options.encoder ?? new TextEncoder();\n const maxSize = options.maxSize ?? 1024 * 1024;\n const maxFiles = options.maxFiles ?? 5;\n const bufferSize = options.bufferSize ?? 1024 * 8; // Default buffer size of 8192 chars\n const flushInterval = options.flushInterval ?? 5000; // Default flush interval of 5 seconds\n let offset: number = 0;\n try {\n const stat = options.statSync(path);\n offset = stat.size;\n } catch {\n // Continue as the offset is already 0.\n }\n let fd = options.openSync(path);\n let lastFlushTimestamp: number = Date.now();\n\n function shouldRollover(bytes: Uint8Array): boolean {\n return offset + bytes.length > maxSize;\n }\n function performRollover(): void {\n options.closeSync(fd);\n for (let i = maxFiles - 1; i > 0; i--) {\n const oldPath = `${path}.${i}`;\n const newPath = `${path}.${i + 1}`;\n try {\n options.renameSync(oldPath, newPath);\n } catch (_) {\n // Continue if the file does not exist.\n }\n }\n options.renameSync(path, `${path}.1`);\n offset = 0;\n fd = options.openSync(path);\n }\n\n function flushBuffer(): void {\n if (buffer.length > 0) {\n const bytes = encoder.encode(buffer);\n buffer = \"\";\n if (shouldRollover(bytes)) performRollover();\n options.writeSync(fd, bytes);\n options.flushSync(fd);\n offset += bytes.length;\n lastFlushTimestamp = Date.now();\n }\n }\n\n let buffer: string = \"\";\n const sink: Sink & Disposable = (record: LogRecord) => {\n buffer += formatter(record);\n\n const shouldFlushBySize = buffer.length >= bufferSize;\n const shouldFlushByTime = flushInterval > 0 &&\n (record.timestamp - lastFlushTimestamp) >= flushInterval;\n\n if (shouldFlushBySize || shouldFlushByTime) {\n flushBuffer();\n }\n };\n sink[Symbol.dispose] = () => {\n flushBuffer();\n options.closeSync(fd);\n };\n return sink;\n}\n"],"mappings":";;;;;;;;;;;;AA2EA,SAAgB,gBACdA,MACAC,SACmB;CACnB,MAAM,YAAY,QAAQ,aAAa;CACvC,MAAM,UAAU,QAAQ,WAAW,IAAI;CACvC,MAAM,aAAa,QAAQ,cAAc,OAAO;CAChD,MAAM,gBAAgB,QAAQ,iBAAiB;CAC/C,IAAI,KAAK,QAAQ,OAAO,OAAO,QAAQ,SAAS,KAAK;CACrD,IAAIC,SAAiB;CACrB,IAAIC,qBAA6B,KAAK,KAAK;CAE3C,SAAS,cAAoB;AAC3B,MAAI,MAAM,KAAM;AAChB,MAAI,OAAO,SAAS,GAAG;AACrB,WAAQ,UAAU,IAAI,QAAQ,OAAO,OAAO,CAAC;AAC7C,YAAS;AACT,WAAQ,UAAU,GAAG;AACrB,wBAAqB,KAAK,KAAK;EAChC;CACF;CAED,MAAMC,OAA0B,CAACC,WAAsB;AACrD,MAAI,MAAM,KAAM,MAAK,QAAQ,SAAS,KAAK;AAC3C,YAAU,UAAU,OAAO;EAE3B,MAAM,oBAAoB,OAAO,UAAU;EAC3C,MAAM,oBAAoB,gBAAgB,KACvC,OAAO,YAAY,sBAAuB;AAE7C,MAAI,qBAAqB,kBACvB,cAAa;CAEhB;AACD,MAAK,OAAO,WAAW,MAAM;AAC3B,MAAI,OAAO,MAAM;AACf,gBAAa;AACb,WAAQ,UAAU,GAAG;EACtB;CACF;AACD,QAAO;AACR;;;;;;;;;;;;;;AAiDD,SAAgB,wBACdL,MACAM,SACmB;CACnB,MAAM,YAAY,QAAQ,aAAa;CACvC,MAAM,UAAU,QAAQ,WAAW,IAAI;CACvC,MAAM,UAAU,QAAQ,WAAW,OAAO;CAC1C,MAAM,WAAW,QAAQ,YAAY;CACrC,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esink.base.js","names":["path: string","options:\n & FileSinkOptions\n & (FileSinkDriver<TFile> | AsyncFileSinkDriver<TFile>)","buffer: string","lastFlushTimestamp: number","flushBuffer","sink: Sink & Disposable","record: LogRecord","activeFlush: Promise<void> | null","flushTimer: ReturnType<typeof setInterval> | null","nonBlockingSink: Sink & AsyncDisposable","options:\n & RotatingFileSinkOptions\n & (RotatingFileSinkDriver<TFile> | AsyncRotatingFileSinkDriver<TFile>)","offset: number","bytes: Uint8Array"],"sources":["../filesink.base.ts"],"sourcesContent":["import {\n defaultTextFormatter,\n type LogRecord,\n type Sink,\n type StreamSinkOptions,\n} from \"@logtape/logtape\";\n\n/**\n * Options for the {@link getBaseFileSink} function.\n */\nexport type FileSinkOptions = StreamSinkOptions & {\n /**\n * If `true`, the file is not opened until the first write. Defaults to `false`.\n */\n lazy?: boolean;\n\n /**\n * The size of the buffer to use when writing to the file. If not specified,\n * a default buffer size will be used. If it is less or equal to 0,\n * the file will be written directly without buffering.\n * @default 8192\n * @since 0.12.0\n */\n bufferSize?: number;\n\n /**\n * The maximum time interval in milliseconds between flushes. If this time\n * passes since the last flush, the buffer will be flushed regardless of size.\n * This helps prevent log loss during unexpected process termination.\n * @default 5000\n * @since 0.12.0\n */\n flushInterval?: number;\n\n /**\n * Enable non-blocking mode with background flushing.\n * When enabled, flush operations are performed asynchronously to prevent\n * blocking the main thread during file I/O operations.\n *\n * @default `false`\n * @since 1.0.0\n */\n nonBlocking?: boolean;\n};\n\n/**\n * A platform-specific file sink driver.\n * @typeParam TFile The type of the file descriptor.\n */\nexport interface FileSinkDriver<TFile> {\n /**\n * Open a file for appending and return a file descriptor.\n * @param path A path to the file to open.\n */\n openSync(path: string): TFile;\n\n /**\n * Write a chunk of data to the file.\n * @param fd The file descriptor.\n * @param chunk The data to write.\n */\n writeSync(fd: TFile, chunk: Uint8Array): void;\n\n /**\n * Flush the file to ensure that all data is written to the disk.\n * @param fd The file descriptor.\n */\n flushSync(fd: TFile): void;\n\n /**\n * Close the file.\n * @param fd The file descriptor.\n */\n closeSync(fd: TFile): void;\n}\n\n/**\n * A platform-specific async file sink driver.\n * @typeParam TFile The type of the file descriptor.\n * @since 1.0.0\n */\nexport interface AsyncFileSinkDriver<TFile> extends FileSinkDriver<TFile> {\n /**\n * Asynchronously flush the file to ensure that all data is written to the disk.\n * @param fd The file descriptor.\n */\n flush(fd: TFile): Promise<void>;\n\n /**\n * Asynchronously close the file.\n * @param fd The file descriptor.\n */\n close(fd: TFile): Promise<void>;\n}\n\n/**\n * Get a platform-independent file sink.\n *\n * @typeParam TFile The type of the file descriptor.\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 getBaseFileSink<TFile>(\n path: string,\n options: FileSinkOptions & FileSinkDriver<TFile>,\n): Sink & Disposable;\nexport function getBaseFileSink<TFile>(\n path: string,\n options: FileSinkOptions & AsyncFileSinkDriver<TFile>,\n): Sink & AsyncDisposable;\nexport function getBaseFileSink<TFile>(\n path: string,\n options:\n & FileSinkOptions\n & (FileSinkDriver<TFile> | AsyncFileSinkDriver<TFile>),\n): Sink & (Disposable | AsyncDisposable) {\n const formatter = options.formatter ?? defaultTextFormatter;\n const encoder = options.encoder ?? new TextEncoder();\n const bufferSize = options.bufferSize ?? 1024 * 8; // Default buffer size of 8192 chars\n const flushInterval = options.flushInterval ?? 5000; // Default flush interval of 5 seconds\n let fd = options.lazy ? null : options.openSync(path);\n let buffer: string = \"\";\n let lastFlushTimestamp: number = Date.now();\n\n if (!options.nonBlocking) {\n // Blocking mode implementation\n // deno-lint-ignore no-inner-declarations\n function flushBuffer(): void {\n if (fd == null) return;\n if (buffer.length > 0) {\n options.writeSync(fd, encoder.encode(buffer));\n buffer = \"\";\n options.flushSync(fd);\n lastFlushTimestamp = Date.now();\n }\n }\n\n const sink: Sink & Disposable = (record: LogRecord) => {\n if (fd == null) fd = options.openSync(path);\n buffer += formatter(record);\n\n const shouldFlushBySize = buffer.length >= bufferSize;\n const shouldFlushByTime = flushInterval > 0 &&\n (record.timestamp - lastFlushTimestamp) >= flushInterval;\n\n if (shouldFlushBySize || shouldFlushByTime) {\n flushBuffer();\n }\n };\n sink[Symbol.dispose] = () => {\n if (fd !== null) {\n flushBuffer();\n options.closeSync(fd);\n }\n };\n return sink;\n }\n\n // Non-blocking mode implementation\n const asyncOptions = options as AsyncFileSinkDriver<TFile>;\n let disposed = false;\n let activeFlush: Promise<void> | null = null;\n let flushTimer: ReturnType<typeof setInterval> | null = null;\n\n async function flushBuffer(): Promise<void> {\n if (fd == null || buffer.length === 0) return;\n\n const data = buffer;\n buffer = \"\";\n try {\n asyncOptions.writeSync(fd, encoder.encode(data));\n await asyncOptions.flush(fd);\n lastFlushTimestamp = Date.now();\n } catch {\n // Silently ignore errors in non-blocking mode\n }\n }\n\n function scheduleFlush(): void {\n if (activeFlush || disposed) return;\n\n activeFlush = flushBuffer().finally(() => {\n activeFlush = null;\n });\n }\n\n function startFlushTimer(): void {\n if (flushTimer !== null || disposed) return;\n\n flushTimer = setInterval(() => {\n scheduleFlush();\n }, flushInterval);\n }\n\n const nonBlockingSink: Sink & AsyncDisposable = (record: LogRecord) => {\n if (disposed) return;\n if (fd == null) fd = asyncOptions.openSync(path);\n buffer += formatter(record);\n\n const shouldFlushBySize = buffer.length >= bufferSize;\n const shouldFlushByTime = flushInterval > 0 &&\n (record.timestamp - lastFlushTimestamp) >= flushInterval;\n\n if (shouldFlushBySize || shouldFlushByTime) {\n scheduleFlush();\n } else if (flushTimer === null && flushInterval > 0) {\n startFlushTimer();\n }\n };\n\n nonBlockingSink[Symbol.asyncDispose] = async () => {\n disposed = true;\n if (flushTimer !== null) {\n clearInterval(flushTimer);\n flushTimer = null;\n }\n await flushBuffer();\n if (fd !== null) {\n try {\n await asyncOptions.close(fd);\n } catch {\n // Writer might already be closed or errored\n }\n }\n };\n\n return nonBlockingSink;\n}\n\n/**\n * Options for the {@link getBaseRotatingFileSink} function.\n */\nexport interface RotatingFileSinkOptions extends Omit<FileSinkOptions, \"lazy\"> {\n /**\n * The maximum bytes of the file before it is rotated. 1 MiB by default.\n */\n maxSize?: number;\n\n /**\n * The maximum number of files to keep. 5 by default.\n */\n maxFiles?: number;\n}\n\n/**\n * A platform-specific rotating file sink driver.\n */\nexport interface RotatingFileSinkDriver<TFile> extends FileSinkDriver<TFile> {\n /**\n * Get the size of the file.\n * @param path A path to the file.\n * @returns The `size` of the file in bytes, in an object.\n */\n statSync(path: string): { size: number };\n\n /**\n * Rename a file.\n * @param oldPath A path to the file to rename.\n * @param newPath A path to be renamed to.\n */\n renameSync(oldPath: string, newPath: string): void;\n}\n\n/**\n * A platform-specific async rotating file sink driver.\n * @since 1.0.0\n */\nexport interface AsyncRotatingFileSinkDriver<TFile>\n extends AsyncFileSinkDriver<TFile> {\n /**\n * Get the size of the file.\n * @param path A path to the file.\n * @returns The `size` of the file in bytes, in an object.\n */\n statSync(path: string): { size: number };\n\n /**\n * Rename a file.\n * @param oldPath A path to the file to rename.\n * @param newPath A path to be renamed to.\n */\n renameSync(oldPath: string, newPath: string): void;\n}\n\n/**\n * Get a platform-independent 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 * @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 getBaseRotatingFileSink<TFile>(\n path: string,\n options: RotatingFileSinkOptions & RotatingFileSinkDriver<TFile>,\n): Sink & Disposable;\nexport function getBaseRotatingFileSink<TFile>(\n path: string,\n options: RotatingFileSinkOptions & AsyncRotatingFileSinkDriver<TFile>,\n): Sink & AsyncDisposable;\nexport function getBaseRotatingFileSink<TFile>(\n path: string,\n options:\n & RotatingFileSinkOptions\n & (RotatingFileSinkDriver<TFile> | AsyncRotatingFileSinkDriver<TFile>),\n): Sink & (Disposable | AsyncDisposable) {\n const formatter = options.formatter ?? defaultTextFormatter;\n const encoder = options.encoder ?? new TextEncoder();\n const maxSize = options.maxSize ?? 1024 * 1024;\n const maxFiles = options.maxFiles ?? 5;\n const bufferSize = options.bufferSize ?? 1024 * 8; // Default buffer size of 8192 chars\n const flushInterval = options.flushInterval ?? 5000; // Default flush interval of 5 seconds\n let offset: number = 0;\n try {\n const stat = options.statSync(path);\n offset = stat.size;\n } catch {\n // Continue as the offset is already 0.\n }\n let fd = options.openSync(path);\n let lastFlushTimestamp: number = Date.now();\n let buffer: string = \"\";\n\n function shouldRollover(bytes: Uint8Array): boolean {\n return offset + bytes.length > maxSize;\n }\n function performRollover(): void {\n options.closeSync(fd);\n for (let i = maxFiles - 1; i > 0; i--) {\n const oldPath = `${path}.${i}`;\n const newPath = `${path}.${i + 1}`;\n try {\n options.renameSync(oldPath, newPath);\n } catch (_) {\n // Continue if the file does not exist.\n }\n }\n options.renameSync(path, `${path}.1`);\n offset = 0;\n fd = options.openSync(path);\n }\n\n if (!options.nonBlocking) {\n // Blocking mode implementation\n // deno-lint-ignore no-inner-declarations\n function flushBuffer(): void {\n if (buffer.length > 0) {\n const bytes = encoder.encode(buffer);\n buffer = \"\";\n if (shouldRollover(bytes)) performRollover();\n options.writeSync(fd, bytes);\n options.flushSync(fd);\n offset += bytes.length;\n lastFlushTimestamp = Date.now();\n }\n }\n\n const sink: Sink & Disposable = (record: LogRecord) => {\n buffer += formatter(record);\n\n const shouldFlushBySize = buffer.length >= bufferSize;\n const shouldFlushByTime = flushInterval > 0 &&\n (record.timestamp - lastFlushTimestamp) >= flushInterval;\n\n if (shouldFlushBySize || shouldFlushByTime) {\n flushBuffer();\n }\n };\n sink[Symbol.dispose] = () => {\n flushBuffer();\n options.closeSync(fd);\n };\n return sink;\n }\n\n // Non-blocking mode implementation\n const asyncOptions = options as AsyncRotatingFileSinkDriver<TFile>;\n let disposed = false;\n let activeFlush: Promise<void> | null = null;\n let flushTimer: ReturnType<typeof setInterval> | null = null;\n\n async function flushBuffer(): Promise<void> {\n if (buffer.length === 0) return;\n\n const data = buffer;\n buffer = \"\";\n try {\n const bytes = encoder.encode(data);\n if (shouldRollover(bytes)) performRollover();\n asyncOptions.writeSync(fd, bytes);\n await asyncOptions.flush(fd);\n offset += bytes.length;\n lastFlushTimestamp = Date.now();\n } catch {\n // Silently ignore errors in non-blocking mode\n }\n }\n\n function scheduleFlush(): void {\n if (activeFlush || disposed) return;\n\n activeFlush = flushBuffer().finally(() => {\n activeFlush = null;\n });\n }\n\n function startFlushTimer(): void {\n if (flushTimer !== null || disposed) return;\n\n flushTimer = setInterval(() => {\n scheduleFlush();\n }, flushInterval);\n }\n\n const nonBlockingSink: Sink & AsyncDisposable = (record: LogRecord) => {\n if (disposed) return;\n buffer += formatter(record);\n\n const shouldFlushBySize = buffer.length >= bufferSize;\n const shouldFlushByTime = flushInterval > 0 &&\n (record.timestamp - lastFlushTimestamp) >= flushInterval;\n\n if (shouldFlushBySize || shouldFlushByTime) {\n scheduleFlush();\n } else if (flushTimer === null && flushInterval > 0) {\n startFlushTimer();\n }\n };\n\n nonBlockingSink[Symbol.asyncDispose] = async () => {\n disposed = true;\n if (flushTimer !== null) {\n clearInterval(flushTimer);\n flushTimer = null;\n }\n await flushBuffer();\n try {\n await asyncOptions.close(fd);\n } catch {\n // Writer might already be closed or errored\n }\n };\n\n return nonBlockingSink;\n}\n"],"mappings":";;;AAiHA,SAAgB,gBACdA,MACAC,SAGuC;CACvC,MAAM,YAAY,QAAQ,aAAa;CACvC,MAAM,UAAU,QAAQ,WAAW,IAAI;CACvC,MAAM,aAAa,QAAQ,cAAc,OAAO;CAChD,MAAM,gBAAgB,QAAQ,iBAAiB;CAC/C,IAAI,KAAK,QAAQ,OAAO,OAAO,QAAQ,SAAS,K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Ae;EAChB,GAAE,cAAc;CAClB;CAED,MAAMC,kBAA0C,CAACH,WAAsB;AACrE,MAAI,SAAU;AACd,YAAU,UAAU,OAAO;EAE3B,MAAM,oBAAoB,OAAO,UAAU;EAC3C,MAAM,oBAAoB,gBAAgB,KACvC,OAAO,YAAY,sBAAuB;AAE7C,MAAI,qBAAqB,kBACvB,gBAAe;WACN,eAAe,QAAQ,gBAAgB,EAChD,kBAAiB;CAEpB;AAED,iBAAgB,OAAO,gBAAgB,YAAY;AACjD,aAAW;AACX,MAAI,eAAe,MAAM;AACvB,iBAAc,WAAW;AACzB,gBAAa;EACd;AACD,QAAM,aAAa;AACnB,MAAI;AACF,SAAM,aAAa,MAAM,GAAG;EAC7B,QAAO,CAEP;CACF;AAED,QAAO;AACR"}
@@ -24,37 +24,33 @@ const denoDriver = {
24
24
  renameSync: globalThis?.Deno.renameSync
25
25
  };
26
26
  /**
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.
27
+ * A Deno-specific async file sink driver.
28
+ * @since 1.0.0
35
29
  */
30
+ const denoAsyncDriver = {
31
+ ...denoDriver,
32
+ async flush(fd) {
33
+ await fd.sync();
34
+ },
35
+ close(fd) {
36
+ return Promise.resolve(fd.close());
37
+ }
38
+ };
36
39
  function getFileSink(path, options = {}) {
40
+ if (options.nonBlocking) return require_filesink_base.getBaseFileSink(path, {
41
+ ...options,
42
+ ...denoAsyncDriver
43
+ });
37
44
  return require_filesink_base.getBaseFileSink(path, {
38
45
  ...options,
39
46
  ...denoDriver
40
47
  });
41
48
  }
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
49
  function getRotatingFileSink(path, options = {}) {
50
+ if (options.nonBlocking) return require_filesink_base.getBaseRotatingFileSink(path, {
51
+ ...options,
52
+ ...denoAsyncDriver
53
+ });
58
54
  return require_filesink_base.getBaseRotatingFileSink(path, {
59
55
  ...options,
60
56
  ...denoDriver
@@ -62,6 +58,7 @@ function getRotatingFileSink(path, options = {}) {
62
58
  }
63
59
 
64
60
  //#endregion
61
+ exports.denoAsyncDriver = denoAsyncDriver;
65
62
  exports.denoDriver = denoDriver;
66
63
  exports.getFileSink = getFileSink;
67
64
  exports.getRotatingFileSink = getRotatingFileSink;
@@ -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.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.cts.map
@@ -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;AAeC,cAfY,UAeZ,EAfwB,sBAexB,CAf+C,IAAA,CAAK,MAepD,CAAA;;;AAf8C;AAqB/C;AAQC,cARY,eAQZ,EAR6B,2BAQ7B,CARyD,IAAA,CAAK,MAQ9D,CAAA;;;AARwD;AAqBzD;;;;;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;AAeC,cAfY,UAeZ,EAfwB,sBAexB,CAf+C,IAAA,CAAK,MAepD,CAAA;;;AAf8C;AAqB/C;AAQC,cARY,eAQZ,EAR6B,2BAQ7B,CARyD,IAAA,CAAK,MAQ9D,CAAA;;;AARwD;AAqBzD;;;;;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"}
@@ -24,37 +24,33 @@ const denoDriver = {
24
24
  renameSync: globalThis?.Deno.renameSync
25
25
  };
26
26
  /**
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.
27
+ * A Deno-specific async file sink driver.
28
+ * @since 1.0.0
35
29
  */
30
+ const denoAsyncDriver = {
31
+ ...denoDriver,
32
+ async flush(fd) {
33
+ await fd.sync();
34
+ },
35
+ close(fd) {
36
+ return Promise.resolve(fd.close());
37
+ }
38
+ };
36
39
  function getFileSink(path, options = {}) {
40
+ if (options.nonBlocking) return getBaseFileSink(path, {
41
+ ...options,
42
+ ...denoAsyncDriver
43
+ });
37
44
  return getBaseFileSink(path, {
38
45
  ...options,
39
46
  ...denoDriver
40
47
  });
41
48
  }
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
49
  function getRotatingFileSink(path, options = {}) {
50
+ if (options.nonBlocking) return getBaseRotatingFileSink(path, {
51
+ ...options,
52
+ ...denoAsyncDriver
53
+ });
58
54
  return getBaseRotatingFileSink(path, {
59
55
  ...options,
60
56
  ...denoDriver
@@ -62,5 +58,5 @@ function getRotatingFileSink(path, options = {}) {
62
58
  }
63
59
 
64
60
  //#endregion
65
- export { denoDriver, getFileSink, getRotatingFileSink };
61
+ export { denoAsyncDriver, denoDriver, getFileSink, getRotatingFileSink };
66
62
  //# 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","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 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 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,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,MAAM,IAAI;AACd,QAAM,GAAG,MAAM;CAChB;CACD,MAAM,IAAI;AACR,SAAO,QAAQ,QAAQ,GAAG,OAAO,CAAC;CACnC;AACF;AAqBD,SAAgB,YACdD,MACAE,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,oBACdF,MACAG,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
  /**
@@ -17,37 +18,29 @@ const nodeDriver = {
17
18
  renameSync: node_fs.default.renameSync
18
19
  };
19
20
  /**
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.
21
+ * A Node.js-specific async file sink driver.
22
+ * @since 1.0.0
28
23
  */
24
+ const nodeAsyncDriver = {
25
+ ...nodeDriver,
26
+ flush: (0, node_util.promisify)(node_fs.default.fsync),
27
+ close: (0, node_util.promisify)(node_fs.default.close)
28
+ };
29
29
  function getFileSink(path, options = {}) {
30
+ if (options.nonBlocking) return require_filesink_base.getBaseFileSink(path, {
31
+ ...options,
32
+ ...nodeAsyncDriver
33
+ });
30
34
  return require_filesink_base.getBaseFileSink(path, {
31
35
  ...options,
32
36
  ...nodeDriver
33
37
  });
34
38
  }
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
39
  function getRotatingFileSink(path, options = {}) {
40
+ if (options.nonBlocking) return require_filesink_base.getBaseRotatingFileSink(path, {
41
+ ...options,
42
+ ...nodeAsyncDriver
43
+ });
51
44
  return require_filesink_base.getBaseRotatingFileSink(path, {
52
45
  ...options,
53
46
  ...nodeDriver
@@ -57,4 +50,5 @@ function getRotatingFileSink(path, options = {}) {
57
50
  //#endregion
58
51
  exports.getFileSink = getFileSink;
59
52
  exports.getRotatingFileSink = getRotatingFileSink;
53
+ exports.nodeAsyncDriver = nodeAsyncDriver;
60
54
  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;AAea,cAfA,UAmBZ,EAnBwB,sBAeK,CAAA,MAA2B,GAAA,IAAA,CAAA;AAiBzD;;;;AAGU,cApBG,eAoBH,EApBoB,2BAoBpB,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;AAea,cAfA,UAmBZ,EAnBwB,sBAeK,CAAA,MAA2B,GAAA,IAAA,CAAA;AAiBzD;;;;AAGU,cApBG,eAoBH,EApBoB,2BAoBpB,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
  /**
@@ -16,37 +17,29 @@ const nodeDriver = {
16
17
  renameSync: fs.renameSync
17
18
  };
18
19
  /**
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.
20
+ * A Node.js-specific async file sink driver.
21
+ * @since 1.0.0
27
22
  */
23
+ const nodeAsyncDriver = {
24
+ ...nodeDriver,
25
+ flush: promisify(fs.fsync),
26
+ close: promisify(fs.close)
27
+ };
28
28
  function getFileSink(path, options = {}) {
29
+ if (options.nonBlocking) return getBaseFileSink(path, {
30
+ ...options,
31
+ ...nodeAsyncDriver
32
+ });
29
33
  return getBaseFileSink(path, {
30
34
  ...options,
31
35
  ...nodeDriver
32
36
  });
33
37
  }
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
38
  function getRotatingFileSink(path, options = {}) {
39
+ if (options.nonBlocking) return getBaseRotatingFileSink(path, {
40
+ ...options,
41
+ ...nodeAsyncDriver
42
+ });
50
43
  return getBaseRotatingFileSink(path, {
51
44
  ...options,
52
45
  ...nodeDriver
@@ -54,5 +47,5 @@ function getRotatingFileSink(path, options = {}) {
54
47
  }
55
48
 
56
49
  //#endregion
57
- export { getFileSink, getRotatingFileSink, nodeDriver };
50
+ export { getFileSink, getRotatingFileSink, nodeAsyncDriver, nodeDriver };
58
51
  //# 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","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 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 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,WAAW,GAAG;CACd,WAAW,GAAG;CACd,UAAU,GAAG;CACb,YAAY,GAAG;AAChB;;;;;AAMD,MAAaC,kBAA8D;CACzE,GAAG;CACH,OAAO,UAAU,GAAG,MAAM;CAC1B,OAAO,UAAU,GAAG,MAAM;AAC3B;AAqBD,SAAgB,YACdD,MACAE,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,oBACdF,MACAG,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"}