function toBase64(buffer) {
  if (isNode) {
    // Node.js environment
    return buffer.toString('base64');
  } else {
    // Browser environment
    return new Promise((resolve, reject) => {
      const blob = new Blob([buffer], { type: 'application/octet-stream' });
      const reader = new FileReader();
      reader.onloadend = () => {
        const base64String = /** @type {string } */ (reader.result).split(',')[1];
        resolve(base64String);
      };
      reader.onerror = reject;
      reader.readAsDataURL(blob);
    });
  }
}
@param {Buffer} buffer
@returns {string|Promise<string>}