UNPKG

qsu

Version:

qsu is a utility library that contains useful and frequently used functions. Start with your preferred language and the modern development environment.

1 lines 433 B
import{createReadStream as n}from"fs";import{createInterface as o}from"node:readline";export async function tailFile(e,l=1){return l<=0?null:new Promise((r,t)=>{const i=n(e,{encoding:"utf-8"}),u=o({input:i,crlfDelay:1/0}),f=[];u.on("line",n=>{f.length===l&&f.shift(),f.push(n)}),u.on("close",()=>{0!==f.length?(""===f[f.length-1]&&f.pop(),0!==f.length?r(f.join("\n")):r(null)):r(null)}),u.on("error",n=>t(n)),i.on("error",n=>t(n))})}