Skip to content

Commit 6581613

Browse files
committed
Buffer does not exist in web
1 parent 7e49ac0 commit 6581613

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/components/OpenWithButton.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as css from './CopyButton.module.css';
88
const OpenWithButton = ({ text }) => {
99
return (
1010
<a
11-
href={`pde://sketch/base64/${Buffer.from(text).toString('base64')}`}
11+
href={`pde://sketch/base64/${stringToBase64(text)}`}
1212
type="button"
1313
className={classnames(css.root)}
1414
>
@@ -17,4 +17,11 @@ const OpenWithButton = ({ text }) => {
1717
)
1818
}
1919

20-
export default OpenWithButton;
20+
export default OpenWithButton;
21+
22+
function stringToBase64(str) {
23+
if (typeof Buffer !== 'undefined') {
24+
return Buffer.from(str).toString('base64');
25+
}
26+
return btoa(str);
27+
}

0 commit comments

Comments
 (0)