Update for 2021 #3

Open
opened 2021-09-21 07:46:53 +00:00 by coolaj86 · 0 comments
Owner

There's some backwards compat stuff that can reasonably be
removed, as well as a few new tricks I've learned (like using the Uint8Array version of reduce to convert strings).

Here are some of the updated functions:

function base64ToBuffer(b64) {
  let binstr = atob(b64);
  let arr = binstr.split("").map(function (ch) {
    return ch.charCodeAt();
  });
  return Uint8Array.from(arr);
}

function bufferToBase64(buf) {
  var binstr = buf
    .reduce(function (arr, ch) {
      arr.push(String.fromCharCode(ch));
      return arr;
    }, [])
    .join("");
  return btoa(binstr);
}
There's some backwards compat stuff that can reasonably be removed, as well as a few new tricks I've learned (like using the Uint8Array version of `reduce` to convert strings). Here are some of the updated functions: ```js function base64ToBuffer(b64) { let binstr = atob(b64); let arr = binstr.split("").map(function (ch) { return ch.charCodeAt(); }); return Uint8Array.from(arr); } function bufferToBase64(buf) { var binstr = buf .reduce(function (arr, ch) { arr.push(String.fromCharCode(ch)); return arr; }, []) .join(""); return btoa(binstr); } ```
Sign in to join this conversation.
No Label
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: coolaj86/unibabel.js#3
No description provided.