UNPKG

@softkit/mail

Version:

The Mailgun Mail Module is a comprehensive solution for integrating Mailgun's email functionality into NestJS applications. It provides a seamless way to send emails using Mailgun with minimal setup and configuration.

45 lines 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toBase64 = void 0; const node_stream_1 = require("node:stream"); async function toBase64(input) { if (typeof input === 'string') { // if type is string we assume it's already base64 encoded return input; } else if (Buffer.isBuffer(input)) { return input.toString('base64'); } else if (input instanceof Uint8Array) { return Buffer.from(input).toString('base64'); } else if (input instanceof node_stream_1.Readable) { return streamToBase64(input); } else { throw new TypeError('Unsupported input type.'); } } exports.toBase64 = toBase64; async function streamToBase64(stream) { const chunks = []; return new Promise((resolve, reject) => { stream.on('data', (chunk) => { chunks.push(new Uint8Array(Buffer.from(chunk))); }); stream.on('end', () => { const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0); const concatenated = new Uint8Array(totalLength); let offset = 0; for (const chunk of chunks) { concatenated.set(chunk, offset); offset += chunk.length; } resolve(Buffer.from(concatenated).toString('base64')); }); stream.on('error', (err) => { reject(err); }); }); } //# sourceMappingURL=type-convertor.js.map