mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-04 23:54:53 +00:00
Handle absence of Buffer on the web
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import { Platform } from 'react-native';
|
import { Platform } from 'react-native';
|
||||||
import { Buffer } from 'buffer';
|
|
||||||
|
|
||||||
export async function fetchText(uri?: string): Promise<string | null> {
|
export async function fetchText(uri?: string): Promise<string | null> {
|
||||||
if (!uri) {
|
if (!uri) {
|
||||||
@@ -20,6 +19,7 @@ const decodeBase64Image = (uri: string) => {
|
|||||||
const dataType = splitContent[0] as BufferEncoding;
|
const dataType = splitContent[0] as BufferEncoding;
|
||||||
const content = splitContent.slice(1).join(',');
|
const content = splitContent.slice(1).join(',');
|
||||||
|
|
||||||
|
if (typeof Buffer === "undefined") return window.atob(content)
|
||||||
return Buffer.from(content, dataType).toString('utf-8');
|
return Buffer.from(content, dataType).toString('utf-8');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user