base64转blob

node后端将文件buffer转成base64后发送给前端,前端解析后播放或下载,以下示例为mp3播放示例

    window.atob(res.data),
        n = bytes.length,
        u8arr = new Uint8Array(n);
        while (n--) {
          u8arr[n] = bytes.charCodeAt(n);
        }
        var audio = new Blob([u8arr], { type: "audio/mp3" });
        const url = URL.createObjectURL(audio);
        window.open(
            url,
            "在线播放",
            "height=250, width=500, top=0, left=0, toolbar=no, menubar=no, 
            scrollbars=no, resizable=no,location=n o, status=no"
         );