@logtape/file
Version:
File sink and rotating file sink for LogTape
70 lines (68 loc) • 1.53 kB
JavaScript
const require_filesink_base = require('./filesink.base.cjs');
//#region filesink.deno.ts
/**
* A Deno-specific file sink driver.
*/
const denoDriver = {
openSync(path) {
return Deno.openSync(path, {
create: true,
append: true
});
},
writeSync(fd, chunk) {
fd.writeSync(chunk);
},
writeManySync(fd, chunks) {
for (const chunk of chunks) fd.writeSync(chunk);
},
flushSync(fd) {
fd.syncSync();
},
closeSync(fd) {
fd.close();
},
statSync: globalThis?.Deno.statSync,
renameSync: globalThis?.Deno.renameSync
};
/**
* A Deno-specific async file sink driver.
* @since 1.0.0
*/
const denoAsyncDriver = {
...denoDriver,
async writeMany(fd, chunks) {
for (const chunk of chunks) await fd.write(chunk);
},
async flush(fd) {
await fd.sync();
},
close(fd) {
return Promise.resolve(fd.close());
}
};
function getFileSink(path, options = {}) {
if (options.nonBlocking) return require_filesink_base.getBaseFileSink(path, {
...options,
...denoAsyncDriver
});
return require_filesink_base.getBaseFileSink(path, {
...options,
...denoDriver
});
}
function getRotatingFileSink(path, options = {}) {
if (options.nonBlocking) return require_filesink_base.getBaseRotatingFileSink(path, {
...options,
...denoAsyncDriver
});
return require_filesink_base.getBaseRotatingFileSink(path, {
...options,
...denoDriver
});
}
//#endregion
exports.denoAsyncDriver = denoAsyncDriver;
exports.denoDriver = denoDriver;
exports.getFileSink = getFileSink;
exports.getRotatingFileSink = getRotatingFileSink;