UNPKG

apitally

Version:

Simple API monitoring & analytics for REST APIs built with Express, Fastify, NestJS, AdonisJS, Hono, H3, Elysia, Hapi, and Koa.

79 lines 2.12 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { Buffer as Buffer2 } from "node:buffer"; import { randomUUID } from "node:crypto"; import { createWriteStream, readFile } from "node:fs"; import { unlink } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { createGzip } from "node:zlib"; const _TempGzipFile = class _TempGzipFile { uuid; filePath; gzip; writeStream; readyPromise; closedPromise; constructor() { this.uuid = randomUUID(); this.filePath = join(tmpdir(), `apitally-${this.uuid}.gz`); this.writeStream = createWriteStream(this.filePath); this.readyPromise = new Promise((resolve, reject) => { this.writeStream.once("ready", resolve); this.writeStream.once("error", reject); }); this.closedPromise = new Promise((resolve, reject) => { this.writeStream.once("close", resolve); this.writeStream.once("error", reject); }); this.gzip = createGzip(); this.gzip.pipe(this.writeStream); } get size() { return this.writeStream.bytesWritten; } async writeLine(data) { await this.readyPromise; return new Promise((resolve, reject) => { this.gzip.write(Buffer2.concat([ data, Buffer2.from("\n") ]), (error) => { if (error) { reject(error); } else { resolve(); } }); }); } async getContent() { return new Promise((resolve, reject) => { readFile(this.filePath, (error, data) => { if (error) { reject(error); } else { resolve(data); } }); }); } async close() { await new Promise((resolve) => { this.gzip.end(() => { resolve(); }); }); await this.closedPromise; } async delete() { await this.close(); await unlink(this.filePath); } }; __name(_TempGzipFile, "TempGzipFile"); let TempGzipFile = _TempGzipFile; export { TempGzipFile as default }; //# sourceMappingURL=tempGzipFile.js.map