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 395 B
import{createReadStream as n}from"fs";import{createInterface as o}from"node:readline";export async function headFile(e,r=1){return r<=0?null:new Promise((l,t)=>{const i=n(e,{encoding:"utf-8"}),s=o({input:i,crlfDelay:1/0}),c=[];s.on("line",n=>{c.push(n),c.length>=r&&(s.close(),i.destroy())}),s.on("close",()=>{0===c.length?l(null):l(c.join("\n"))}),s.on("error",n=>t(n)),i.on("error",n=>t(n))})}